Skip to content

Commit

Permalink
build: upgrade gradle, dependencies and java
Browse files Browse the repository at this point in the history
Upgraded Gradle to version 8.9
updated dependencies
upgraded Java from version 11 to 17
  • Loading branch information
Ahwar committed Jul 20, 2024
1 parent 3a26e6b commit 36aa0c9
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 133 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

# python
venv
12 changes: 6 additions & 6 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 103 additions & 98 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
# 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](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english) using [ONNX runtime](https://onnxruntime.ai/docs/get-started/with-java.html) and [Deep Java Library](https://djl.ai/)
# Run HuggingFace NER (NLP) Model on Java using ONNX Runtime and DJL

A Natural Language Processing (NLP) Java application that detects `names`, `organizations`, and `locations` in a text by running Hugging Face's [Roberta NER model](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english) using [ONNX Runtime](https://onnxruntime.ai/docs/get-started/with-java.html) and the [Deep Java Library](https://djl.ai/).

## Installation

Open the project folder in a Java IDE (recommended: IntelliJ IDEA Community) with Gradle support and build the project.

## 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 17
2. Gradle version 8.9

### Requirements:
1. Java Development Kit JDK version: 11
2. Gradle version 7+
### Download Files

### Download files
These files are required to run the project:

These files are required to run the project

1. ONNX model
1. ONNX model
2. `tokenizer.json` file

### Convert the ONNX model
### Convert the ONNX Model

To convert HuggingFace NER model to ONNX Open this [Google Colaboratory Notebook](https://colab.research.google.com/drive/1kZx9XOnExVfPoAGHhHRUrdQnioiLloBW#revisionId=0BwKss6yztf4KS0NKaWRiQjc0RGRvQkd6ZFp3OUFhR1lTclBNPQ) run the code as image shown below and follow all the steps
To convert the Hugging Face NER model to ONNX, open this [Google Colaboratory Notebook](https://colab.research.google.com/drive/1kZx9XOnExVfPoAGHhHRUrdQnioiLloBW#revisionId=0BwKss6yztf4KS0NKaWRiQjc0RGRvQkd6ZFp3OUFhR1lTclBNPQ), run the code as shown in the image below, and follow all the steps.

![run colab code cell](images/run-colab.jpeg)
![run colab code cell](images/run-colab.jpeg)

(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](https://jupyter.org/install).)

After running one of the above codes, your ONNX model will be saved in the `onnx/` folder.

(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](https://jupyter.org/install))
### Download tokenizer.json

after running the one of above codes your onnx model will be saved in `onnx/` folder.
The tokenizer file `tokenizer.json` was taken from this [Hugging Face repository](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english). Download the `tokenizer.json` from this [link](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/raw/main/tokenizer.json).

### Download tokenizer.json
Tokenzer file `tokenizer.json` was taken from this [huggingface repo](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english)
Download the `tokenizer.json` from the [link](https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/raw/main/tokenizer.json)
**Move Files**

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

![raw-files path](images/model-location.png)

## Building the Project

## Building project
Build the project using This button
Build the project using the button shown below.

![how to build project](images/building-project.jpg)

## 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](images/run-code.jpg)
Open the `Main.java` file and click the play button as shown in the red box in the image below.

![how to run project](images/run-code.jpg)
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
plugins {
id 'java'
id 'application'
}

application {
mainClass.set('dev.ahwar.Main')
}

group 'dev.ahwar'
Expand All @@ -11,8 +16,8 @@ repositories {

dependencies {
implementation 'com.microsoft.onnxruntime:onnxruntime:1.13.1'
implementation "ai.djl.huggingface:tokenizers:0.19.0"
implementation 'org.slf4j:slf4j-api:2.0.3'
implementation "ai.djl.huggingface:tokenizers:0.29.0"
implementation 'org.slf4j:slf4j-api:2.0.13'
}

test {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified gradlew
100644 → 100755
Empty file.

0 comments on commit 36aa0c9

Please sign in to comment.