Skip to content

An NLP Java Application that detects Names, organizations, and locations in a text by running Hugging face's Roberta NER model using ONNX runtime and Deep Java Library.

Notifications You must be signed in to change notification settings

Ahwar/NER-NLP-with-ONNX-Java

Repository files navigation

Run HuggingFace NER (NLP) Model on Java using ONNX Runtime and DJL

A NLP (Natural Language Processing) Java Application which detects Names, organizaions, and locations in a text by running Hugging face's Roberta NER model using ONNX runtime and Deep Java Library

Installation:

Open Project folder in Java IDE (Recommended: IntelliJ IDEA Community) with gradle support and Build the project

Requirements:

  1. Java Development Kit JDK version: 11
  2. Gradle version 7+

Download files

These files are required to run the project

  1. ONNX model
  2. tokenizer.json file

Convert the ONNX model

To convert HuggingFace NER model to ONNX Open this Google Colaboratory Notebook run the code as image shown below and follow all the steps

run colab code cell

(the code for above purpose is also saved in jupyter notebook in the file convert Huggingface model to ONNX.ipynb. you can run the code using Jupyter notebook)

after running the one of above codes your onnx model will be saved in onnx/ folder.

Download tokenizer.json

Tokenzer file tokenizer.json was taken from this huggingface repo
Download the tokenizer.json from the link

move files
Copy files created from above two stesp into raw-files directory as shown in the below image

raw-files path

Building project

Build the project using This button

how to build project

Run the Code

Open the Main.java file and click the play button as shown in the red box in the below image
how to run project