diff --git a/.gitignore b/.gitignore index 49c396f..16db85c 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,7 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +# python +venv \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 62269df..2149df3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4f2d8a6..a5514e6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,100 +1,105 @@ - - - - - - - - - - - - - - - - - - - - - - - - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "last_opened_file_path": "C:/Users/pakle/IdeaProjects/ONNX-Inference-Java", - "project.structure.last.edited": "Libraries", - "project.structure.proportion": "0.0", - "project.structure.side.proportion": "0.2", - "settings.editor.selected.configurable": "preferences.lookFeel" + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - 1668440365537 - - - 1668440503877 - - - 1668483041993 - - - - - - - - - +}]]> + + + + + + + + + + + + + 1668440365537 + + + 1668440503877 + + + 1668483041993 + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 5e3a545..49fe08d 100644 --- a/README.md +++ b/README.md @@ -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) \ No newline at end of file diff --git a/build.gradle b/build.gradle index cc71f76..fe044db 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,10 @@ plugins { id 'java' + id 'application' +} + +application { + mainClass.set('dev.ahwar.Main') } group 'dev.ahwar' @@ -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 { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..19cfad9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755