Repository: deepjavalibrary/djl
Pull request #3393 (2024-08-06 17:52:19)

[examples] Moves nlp examples into nlp folder
## Description ##

Brief description of what this PR is about

- If this change is a backward incompatible change, why must this change be made?
- Interesting edge cases to note here



Patch:
diff --git a/docs/tensorflow/how_to_import_tensorflow_models_in_DJL.md b/docs/tensorflow/how_to_import_tensorflow_models_in_DJL.md
index 428b46990..c57fd055c 100644
--- a/docs/tensorflow/how_to_import_tensorflow_models_in_DJL.md
+++ b/docs/tensorflow/how_to_import_tensorflow_models_in_DJL.md
@@ -50,7 +50,7 @@ Note that you need to click the download model button to find the actual Google
 Please refer to these two examples:
 
 1. [Object Detection with TensorFlow](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/cv/ObjectDetection.java) for loading from TensorFlow Hub url.
-2. [BERT Classification](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/BertClassification.java) for loading from local downloaded model.
+2. [BERT Classification](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/nlp/BertClassification.java) for loading from local downloaded model.
 
 ## How to import TensorFlow models that use [TensorFlow Extensions](https://www.tensorflow.org/resources/libraries-extensions)
 
@@ -68,7 +68,7 @@ This is a text encoder from tensorflow hub that uses ops from the TensorFlow Tex
 - You need to download the library files for the extension so that we can load them for use. [Here](https://github.com/tensorflow/text#install-using-pip) are instructions for downloading TensorFlow text. We'll use version `2.7.0` in this example.
 - After the library files are downloaded, you are ready to load them for use in DJL. You do this by using
 TensorFlow Java `TensorFlow.loadLibrary(...)` API before loading the model in DJL. 
-- We can update the existing [UniversalSentenceEncoder](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/UniversalSentenceEncoder.java) example to use the Multilingual model:
+- We can update the existing [UniversalSentenceEncoder](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoder.java) example to use the Multilingual model:
 
 ```java
 // Build Criteria for Multilingual Universal Sentence Encoder from TensorFlow Hub
diff --git a/examples/docs/BERT_question_and_answer.md b/examples/docs/BERT_question_and_answer.md
index 9c65bb317..a66ca2084 100644
--- a/examples/docs/BERT_question_and_answer.md
+++ b/examples/docs/BERT_question_and_answer.md
@@ -2,7 +2,7 @@
 
 In this example, you learn how to use the BERT QA model trained by GluonNLP (Apache MXNet) and PyTorch. 
 You can provide the model with a question and a paragraph containing an answer. The model is then able to find the best answer from the answer paragraph.
-You can find the source code in [BertQaInference.java](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/BertQaInference.java).
+You can find the source code in [BertQaInference.java](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/nlp/BertQaInference.java).
 
 Note that Apache MXNet BERT model has a limitation where the max size of the tokens including the question and the paragraph is 384.  
 
@@ -33,5 +33,5 @@ Follow [setup](../../docs/development/setup.md) to configure your development en
 
 ```sh
 cd examples
-./gradlew run -Dmain=ai.djl.examples.inference.BertQaInference
+./gradlew run -Dmain=ai.djl.examples.inference.nlp.BertQaInference
 ```
diff --git a/examples/docs/sentiment_analysis.md b/examples/docs/sentiment_analysis.md
index c83e2f4c1..c18c5cc87 100644
--- a/examples/docs/sentiment_analysis.md
+++ b/examples/docs/sentiment_analysis.md
@@ -2,7 +2,7 @@
 
 In this example, you learn how to use the DistilBERT model trained by HuggingFace using PyTorch. 
 You can provide the model with a question and a paragraph containing an answer. The model is then able to find the best answer from the answer paragraph.
-You can find the source code in [SentimentAnalysis.java](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/SentimentAnalysis.java).
+You can find the source code in [SentimentAnalysis.java](https://github.com/deepjavalibrary/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/nlp/SentimentAnalysis.java).
 
 Example:
 
@@ -29,5 +29,5 @@ Follow [setup](../../docs/development/setup.md) to configure your development en
 
 ```sh
 cd examples
-./gradlew run -Dmain=ai.djl.examples.inference.SentimentAnalysis
+./gradlew run -Dmain=ai.djl.examples.inference.nlp.SentimentAnalysis
 ```
diff --git a/examples/src/main/java/ai/djl/examples/inference/BertClassification.java b/examples/src/main/java/ai/djl/examples/inference/nlp/BertClassification.java
similarity index 99%
rename from examples/src/main/java/ai/djl/examples/inference/BertClassification.java
rename to examples/src/main/java/ai/djl/examples/inference/nlp/BertClassification.java
index dcea78b25..fd5788123 100644
--- a/examples/src/main/java/ai/djl/examples/inference/BertClassification.java
+++ b/examples/src/main/java/ai/djl/examples/inference/nlp/BertClassification.java
@@ -10,7 +10,7 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
 import ai.djl.MalformedModelException;
 import ai.djl.ModelException;
diff --git a/examples/src/main/java/ai/djl/examples/inference/BertQaInference.java b/examples/src/main/java/ai/djl/examples/inference/nlp/BertQaInference.java
similarity index 89%
rename from examples/src/main/java/ai/djl/examples/inference/BertQaInference.java
rename to examples/src/main/java/ai/djl/examples/inference/nlp/BertQaInference.java
index 9538b7c00..6f75ec728 100644
--- a/examples/src/main/java/ai/djl/examples/inference/BertQaInference.java
+++ b/examples/src/main/java/ai/djl/examples/inference/nlp/BertQaInference.java
@@ -11,11 +11,10 @@
  * and limitations under the License.
  */
 
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
-import ai.djl.Application;
-import ai.djl.Device;
 import ai.djl.ModelException;
+import ai.djl.huggingface.translator.QuestionAnsweringTranslatorFactory;
 import ai.djl.inference.Predictor;
 import ai.djl.modality.nlp.qa.QAInput;
 import ai.djl.repository.zoo.Criteria;
@@ -65,11 +64,11 @@ public final class BertQaInference {
 
         Criteria<QAInput, String> criteria =
                 Criteria.builder()
-                        .optApplication(Application.NLP.QUESTION_ANSWER)
                         .setTypes(QAInput.class, String.class)
-                        .optFilter("backbone", "bert")
+                        .optModelUrls(
+                                "djl://ai.djl.huggingface.pytorch/deepset/minilm-uncased-squad2")
                         .optEngine("PyTorch")
-                        .optDevice(Device.cpu())
+                        .optTranslatorFactory(new QuestionAnsweringTranslatorFactory())
                         .optProgress(new ProgressBar())
                         .build();
 
diff --git a/examples/src/main/java/ai/djl/examples/inference/SentimentAnalysis.java b/examples/src/main/java/ai/djl/examples/inference/nlp/SentimentAnalysis.java
similarity index 95%
rename from examples/src/main/java/ai/djl/examples/inference/SentimentAnalysis.java
rename to examples/src/main/java/ai/djl/examples/inference/nlp/SentimentAnalysis.java
index 40045f21a..29671fb5d 100644
--- a/examples/src/main/java/ai/djl/examples/inference/SentimentAnalysis.java
+++ b/examples/src/main/java/ai/djl/examples/inference/nlp/SentimentAnalysis.java
@@ -11,9 +11,8 @@
  * and limitations under the License.
  */
 
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
-import ai.djl.Application;
 import ai.djl.Device;
 import ai.djl.MalformedModelException;
 import ai.djl.ModelException;
@@ -58,8 +57,8 @@ public final class SentimentAnalysis {
 
         Criteria<String, Classifications> criteria =
                 Criteria.builder()
-                        .optApplication(Application.NLP.SENTIMENT_ANALYSIS)
                         .setTypes(String.class, Classifications.class)
+                        .optModelUrls("djl://ai.djl.pytorch/distilbert")
                         .optEngine("PyTorch")
                         // This model was traced on CPU and can only run on CPU
                         .optDevice(Device.cpu())
diff --git a/examples/src/main/java/ai/djl/examples/inference/UniversalSentenceEncoder.java b/examples/src/main/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoder.java
similarity index 99%
rename from examples/src/main/java/ai/djl/examples/inference/UniversalSentenceEncoder.java
rename to examples/src/main/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoder.java
index 4cc299f42..ac6c1619e 100644
--- a/examples/src/main/java/ai/djl/examples/inference/UniversalSentenceEncoder.java
+++ b/examples/src/main/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoder.java
@@ -10,7 +10,7 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
 import ai.djl.Application;
 import ai.djl.MalformedModelException;


Test patch:
diff --git a/examples/src/test/java/ai/djl/examples/inference/ActionRecognitionTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/ActionRecognitionTest.java
similarity index 92%
rename from examples/src/test/java/ai/djl/examples/inference/ActionRecognitionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/ActionRecognitionTest.java
index 63b9bbc2b..cc7253e6b 100644
--- a/examples/src/test/java/ai/djl/examples/inference/ActionRecognitionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/ActionRecognitionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.ActionRecognition;
 import ai.djl.modality.Classifications;
 import ai.djl.translate.TranslateException;
 
diff --git a/examples/src/test/java/ai/djl/examples/inference/BigGANTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/BigGANTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/BigGANTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/BigGANTest.java
index 8158db050..80aebc619 100644
--- a/examples/src/test/java/ai/djl/examples/inference/BigGANTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/BigGANTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.BigGAN;
 import ai.djl.modality.cv.Image;
 import ai.djl.testing.TestRequirements;
 import ai.djl.translate.TranslateException;
diff --git a/examples/src/test/java/ai/djl/examples/inference/InstanceSegmentationTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/InstanceSegmentationTest.java
similarity index 93%
rename from examples/src/test/java/ai/djl/examples/inference/InstanceSegmentationTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/InstanceSegmentationTest.java
index e04f0f99b..193d2fdf2 100644
--- a/examples/src/test/java/ai/djl/examples/inference/InstanceSegmentationTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/InstanceSegmentationTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.InstanceSegmentation;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.translate.TranslateException;
diff --git a/examples/src/test/java/ai/djl/examples/inference/MaskDetectionTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/MaskDetectionTest.java
similarity index 95%
rename from examples/src/test/java/ai/djl/examples/inference/MaskDetectionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/MaskDetectionTest.java
index 02ef7f6f8..42da8844e 100644
--- a/examples/src/test/java/ai/djl/examples/inference/MaskDetectionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/MaskDetectionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.MaskDetection;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/ObjectDetectionTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionTest.java
similarity index 95%
rename from examples/src/test/java/ai/djl/examples/inference/ObjectDetectionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionTest.java
index 076fda3f9..e83c4881d 100644
--- a/examples/src/test/java/ai/djl/examples/inference/ObjectDetectionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.ObjectDetection;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/ObjectDetectionWithTensorflowSavedModelTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionWithTensorflowSavedModelTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/ObjectDetectionWithTensorflowSavedModelTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionWithTensorflowSavedModelTest.java
index cb8448113..91704905d 100644
--- a/examples/src/test/java/ai/djl/examples/inference/ObjectDetectionWithTensorflowSavedModelTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/ObjectDetectionWithTensorflowSavedModelTest.java
@@ -11,10 +11,9 @@
  * and limitations under the License.
  */
 
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.ObjectDetectionWithTensorflowSavedModel;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/PoseEstimationTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/PoseEstimationTest.java
similarity index 92%
rename from examples/src/test/java/ai/djl/examples/inference/PoseEstimationTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/PoseEstimationTest.java
index 398c71ced..bade178b6 100644
--- a/examples/src/test/java/ai/djl/examples/inference/PoseEstimationTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/PoseEstimationTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.PoseEstimation;
 import ai.djl.modality.cv.output.Joints;
 import ai.djl.translate.TranslateException;
 
diff --git a/examples/src/test/java/ai/djl/examples/inference/StyleTransferTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/StyleTransferTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/StyleTransferTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/StyleTransferTest.java
index 645a88b57..c5159b298 100644
--- a/examples/src/test/java/ai/djl/examples/inference/StyleTransferTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/StyleTransferTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.StyleTransfer;
 import ai.djl.modality.cv.Image;
 import ai.djl.modality.cv.ImageFactory;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/Yolov8DetectionTest.java b/examples/src/test/java/ai/djl/examples/inference/cv/Yolov8DetectionTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/Yolov8DetectionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/cv/Yolov8DetectionTest.java
index de46c8967..f34c0a025 100644
--- a/examples/src/test/java/ai/djl/examples/inference/Yolov8DetectionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/Yolov8DetectionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.cv;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.cv.Yolov8Detection;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/cv/package-info.java b/examples/src/test/java/ai/djl/examples/inference/cv/package-info.java
new file mode 100644
index 000000000..c47d4738a
--- /dev/null
+++ b/examples/src/test/java/ai/djl/examples/inference/cv/package-info.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
+ * with the License. A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0/
+ *
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ */
+
+/** Contains tests for the inference examples. */
+package ai.djl.examples.inference.cv;
diff --git a/examples/src/test/java/ai/djl/examples/inference/FeatureComparisonTest.java b/examples/src/test/java/ai/djl/examples/inference/face/FeatureComparisonTest.java
similarity index 91%
rename from examples/src/test/java/ai/djl/examples/inference/FeatureComparisonTest.java
rename to examples/src/test/java/ai/djl/examples/inference/face/FeatureComparisonTest.java
index 7e355ecfa..245acdcfa 100644
--- a/examples/src/test/java/ai/djl/examples/inference/FeatureComparisonTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/face/FeatureComparisonTest.java
@@ -10,11 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.face;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.face.FeatureComparison;
-import ai.djl.examples.inference.face.FeatureExtraction;
 import ai.djl.modality.cv.Image;
 import ai.djl.modality.cv.ImageFactory;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/FeatureExtractionTest.java b/examples/src/test/java/ai/djl/examples/inference/face/FeatureExtractionTest.java
similarity index 93%
rename from examples/src/test/java/ai/djl/examples/inference/FeatureExtractionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/face/FeatureExtractionTest.java
index c5ac6bd11..af50b240a 100644
--- a/examples/src/test/java/ai/djl/examples/inference/FeatureExtractionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/face/FeatureExtractionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.face;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.face.FeatureExtraction;
 import ai.djl.modality.cv.Image;
 import ai.djl.modality.cv.ImageFactory;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/LightFaceDetectionTest.java b/examples/src/test/java/ai/djl/examples/inference/face/LightFaceDetectionTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/LightFaceDetectionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/face/LightFaceDetectionTest.java
index 360a76049..b3d28a36c 100644
--- a/examples/src/test/java/ai/djl/examples/inference/LightFaceDetectionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/face/LightFaceDetectionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.face;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.face.LightFaceDetection;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/RetinaFaceDetectionTest.java b/examples/src/test/java/ai/djl/examples/inference/face/RetinaFaceDetectionTest.java
similarity index 94%
rename from examples/src/test/java/ai/djl/examples/inference/RetinaFaceDetectionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/face/RetinaFaceDetectionTest.java
index 0060cd3e6..39e9737ce 100644
--- a/examples/src/test/java/ai/djl/examples/inference/RetinaFaceDetectionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/face/RetinaFaceDetectionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.face;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.face.RetinaFaceDetection;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.output.DetectedObjects;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/face/package-info.java b/examples/src/test/java/ai/djl/examples/inference/face/package-info.java
new file mode 100644
index 000000000..881e4fd93
--- /dev/null
+++ b/examples/src/test/java/ai/djl/examples/inference/face/package-info.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
+ * with the License. A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0/
+ *
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ */
+
+/** Contains tests for the inference examples. */
+package ai.djl.examples.inference.face;
diff --git a/examples/src/test/java/ai/djl/examples/inference/BertQaTest.java b/examples/src/test/java/ai/djl/examples/inference/nlp/BertQaTest.java
similarity index 96%
rename from examples/src/test/java/ai/djl/examples/inference/BertQaTest.java
rename to examples/src/test/java/ai/djl/examples/inference/nlp/BertQaTest.java
index 06194ac51..21a70ff67 100644
--- a/examples/src/test/java/ai/djl/examples/inference/BertQaTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/nlp/BertQaTest.java
@@ -10,7 +10,7 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
 import ai.djl.ModelException;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/SentimentAnalysisTest.java b/examples/src/test/java/ai/djl/examples/inference/nlp/SentimentAnalysisTest.java
similarity index 96%
rename from examples/src/test/java/ai/djl/examples/inference/SentimentAnalysisTest.java
rename to examples/src/test/java/ai/djl/examples/inference/nlp/SentimentAnalysisTest.java
index 4091c9152..c18b1f296 100644
--- a/examples/src/test/java/ai/djl/examples/inference/SentimentAnalysisTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/nlp/SentimentAnalysisTest.java
@@ -10,7 +10,7 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
 import ai.djl.ModelException;
 import ai.djl.modality.Classifications;
diff --git a/examples/src/test/java/ai/djl/examples/inference/UniversalSentenceEncoderTest.java b/examples/src/test/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoderTest.java
similarity index 97%
rename from examples/src/test/java/ai/djl/examples/inference/UniversalSentenceEncoderTest.java
rename to examples/src/test/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoderTest.java
index a85564fb6..fb9551be1 100644
--- a/examples/src/test/java/ai/djl/examples/inference/UniversalSentenceEncoderTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/nlp/UniversalSentenceEncoderTest.java
@@ -10,7 +10,7 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.nlp;
 
 import ai.djl.ModelException;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/SuperResolutionTest.java b/examples/src/test/java/ai/djl/examples/inference/sr/SuperResolutionTest.java
similarity index 95%
rename from examples/src/test/java/ai/djl/examples/inference/SuperResolutionTest.java
rename to examples/src/test/java/ai/djl/examples/inference/sr/SuperResolutionTest.java
index e40c2e6ad..4895c8d74 100644
--- a/examples/src/test/java/ai/djl/examples/inference/SuperResolutionTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/sr/SuperResolutionTest.java
@@ -10,10 +10,9 @@
  * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  * and limitations under the License.
  */
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.sr;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.sr.SuperResolution;
 import ai.djl.modality.cv.Image;
 import ai.djl.modality.cv.ImageFactory;
 import ai.djl.testing.TestRequirements;
diff --git a/examples/src/test/java/ai/djl/examples/inference/sr/package-info.java b/examples/src/test/java/ai/djl/examples/inference/sr/package-info.java
new file mode 100644
index 000000000..60033daa2
--- /dev/null
+++ b/examples/src/test/java/ai/djl/examples/inference/sr/package-info.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
+ * with the License. A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0/
+ *
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ */
+
+/** Contains tests for the inference examples. */
+package ai.djl.examples.inference.sr;
diff --git a/examples/src/test/java/ai/djl/examples/inference/TimeSeriesTest.java b/examples/src/test/java/ai/djl/examples/inference/timeseries/TimeSeriesTest.java
similarity index 92%
rename from examples/src/test/java/ai/djl/examples/inference/TimeSeriesTest.java
rename to examples/src/test/java/ai/djl/examples/inference/timeseries/TimeSeriesTest.java
index 614a43560..ee6fce700 100644
--- a/examples/src/test/java/ai/djl/examples/inference/TimeSeriesTest.java
+++ b/examples/src/test/java/ai/djl/examples/inference/timeseries/TimeSeriesTest.java
@@ -11,11 +11,9 @@
  * and limitations under the License.
  */
 
-package ai.djl.examples.inference;
+package ai.djl.examples.inference.timeseries;
 
 import ai.djl.ModelException;
-import ai.djl.examples.inference.timeseries.AirPassengersDeepAR;
-import ai.djl.examples.inference.timeseries.M5ForecastingDeepAR;
 import ai.djl.testing.TestRequirements;
 import ai.djl.translate.TranslateException;
 
diff --git a/examples/src/test/java/ai/djl/examples/inference/timeseries/package-info.java b/examples/src/test/java/ai/djl/examples/inference/timeseries/package-info.java
new file mode 100644
index 000000000..8d8fd25e2
--- /dev/null
+++ b/examples/src/test/java/ai/djl/examples/inference/timeseries/package-info.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
+ * with the License. A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0/
+ *
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ */
+
+/** Contains tests for the inference examples. */
+package ai.djl.examples.inference.timeseries;