A Natural Language Processing (NLP) Java application that detects names, organizations, and locations in a text by running Hugging Face's Roberta NER model using ONNX Runtime and the Deep Java Library.
Open the project folder in a Java IDE (recommended: IntelliJ IDEA Community) with Gradle support and build the project.
- Java Development Kit (JDK) version 17
- Gradle version 8.9
These files are required to run the project:
- ONNX model
tokenizer.jsonfile
To convert the Hugging Face NER model to ONNX, open this Google Colaboratory Notebook, run the code as shown in the image below, and follow all the steps.
(The code for this purpose is also saved in the Jupyter notebook file convert Huggingface model to ONNX.ipynb. You can run the code using Jupyter Notebook.)
After running one of the above codes, your ONNX model will be saved in the onnx/ folder.
The tokenizer file tokenizer.json was taken from this Hugging Face repository. Download the tokenizer.json from this link.
Some times, the tokenizer.json file is created in onnx conversion process, In that case you can find it in onnx/ folder.
Move Files
Copy the files created from the above steps into the raw-files directory as shown in the image below.
Build the project using the button shown below.
Open the Main.java file and click the play button as shown in the red box in the image below.
You can build and run the project using the included Gradle wrapper. The Gradle wrapper (gradlew) allows you to build and run the project without installing Gradle system-wide.
- Build the application:
./gradlew build- Run the application:
./gradlew runThe run task will execute the Main class defined in the project.
If you want to install Gradle system-wide instead of using the wrapper, here are two common options. Using the Gradle wrapper is recommended for consistent builds.
- Install via SDKMAN (recommended):
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install gradle
gradle -v- Install on Debian/Ubuntu (may not be latest):
sudo apt update
sudo apt install gradle
gradle -vAfter installing Gradle, you can run gradle build and gradle run instead of using ./gradlew.



