Repository: deepjavalibrary/djl
Pull request #3276 (2024-06-25 22:52:09)

Refactored Identifiers
Identifier name changes

This pull request suggests minor alterations in identifier names for improved clarity and understandability.



Patch:
diff --git a/api/src/main/java/ai/djl/Application.java b/api/src/main/java/ai/djl/Application.java
index 6fce7f0fe..13ac1882b 100644
--- a/api/src/main/java/ai/djl/Application.java
+++ b/api/src/main/java/ai/djl/Application.java
@@ -82,25 +82,15 @@ public class Application {
             case "nlp/fill_mask":
             case "fill_mask":
                 return NLP.FILL_MASK;
-            case "nlp/machine_translation":
-            case "machine_translation":
-                return NLP.MACHINE_TRANSLATION;
-            case "nlp/multiple_choice":
-            case "multiple_choice":
-                return NLP.MULTIPLE_CHOICE;
             case "nlp/question_answer":
             case "question_answering":
                 return NLP.QUESTION_ANSWER;
-            case "nlp/sentiment_analysis":
-            case "sentiment_analysis":
-                return NLP.SENTIMENT_ANALYSIS;
             case "nlp/text_classification":
             case "text_classification":
                 return NLP.TEXT_CLASSIFICATION;
-            case "nlp/text_embedding":
-            case "text_embedding":
-            case "sentence_similarity":
-                return NLP.TEXT_EMBEDDING;
+            case "nlp/sentiment_analysis":
+            case "sentiment_analysis":
+                return NLP.SENTIMENT_ANALYSIS;
             case "nlp/token_classification":
             case "token_classification":
                 return NLP.TOKEN_CLASSIFICATION;
@@ -110,10 +100,26 @@ public class Application {
             case "nlp/text_generation":
             case "text_generation":
                 return NLP.TEXT_GENERATION;
+            case "nlp/machine_translation":
+            case "machine_translation":
+                return NLP.MACHINE_TRANSLATION;
+            case "nlp/multiple_choice":
+            case "multiple_choice":
+                return NLP.MULTIPLE_CHOICE;
+            case "nlp/text_embedding":
+            case "text_embedding":
+            case "sentence_similarity":
+                return NLP.TEXT_EMBEDDING;
             case "tabular":
                 return Tabular.ANY;
             case "tabular/linear_regression":
                 return Tabular.LINEAR_REGRESSION;
+            case "tabular/softmax_regression":
+                return Tabular.SOFTMAX_REGRESSION;
+            case "audio":
+                return Audio.ANY;
+            case "timeseries/forecasting":
+                return TimeSeries.FORECASTING;
             case "undefined":
             default:
                 return UNDEFINED;
diff --git a/extensions/timeseries/src/main/java/ai/djl/timeseries/timefeature/TimeOffset.java b/extensions/timeseries/src/main/java/ai/djl/timeseries/timefeature/TimeOffset.java
index 2fe0d2c65..d845050c2 100644
--- a/extensions/timeseries/src/main/java/ai/djl/timeseries/timefeature/TimeOffset.java
+++ b/extensions/timeseries/src/main/java/ai/djl/timeseries/timefeature/TimeOffset.java
@@ -22,27 +22,28 @@ public class TimeOffset {
     private static String oPattern = "(?<multiple>\\d*)(?<granularity>\\w+)";
 
     private String name;
-    private int n;
+    private int offsetValue;
 
     /**
      * Constructs a new {@code TimeOffset} instance.
      *
      * @param name offset granularity including "D", "M" etc
-     * @param n offset multiple
+     * @param offsetValue offset multiple
      */
-    public TimeOffset(String name, int n) {
+    public TimeOffset(String name, int offsetValue) {
         this.name = name;
-        this.n = n;
+        this.offsetValue = offsetValue;
     }
 
     /**
      * Return {@code TimeOffset} object from frequency string.
      *
-     * @param freqStr Frequency string of the form [multiple][granularity] such as "12H", "1D" etc.
+     * @param frequencyString Frequency string of the form [multiple][granularity] such as "12H",
+     *     "1D" etc.
      * @return a TimeOffset containing multiple and granularity
      */
-    public static TimeOffset toOffset(String freqStr) {
-        Matcher matcher = Pattern.compile(oPattern).matcher(freqStr);
+    public static TimeOffset toOffset(String frequencyString) {
+        Matcher matcher = Pattern.compile(oPattern).matcher(frequencyString);
         matcher.find();
         String name = matcher.group("granularity");
         if ("".equals(name)) {
@@ -73,7 +74,7 @@ public class TimeOffset {
      * @return the multiple of {@code TimeOffset}
      */
     public double getMultipleOfTimeOffset() {
-        return n;
+        return offsetValue;
     }
 
     /**
@@ -82,6 +83,6 @@ public class TimeOffset {
      * @return the formatted frequency string
      */
     public String toFreqStr() {
-        return n + name;
+        return offsetValue + name;
     }
 }


Test patch:
diff --git a/integration/src/main/java/ai/djl/integration/tests/training/EvaluatorTest.java b/integration/src/main/java/ai/djl/integration/tests/training/EvaluatorTest.java
index 4638cfd03..2e858a291 100644
--- a/integration/src/main/java/ai/djl/integration/tests/training/EvaluatorTest.java
+++ b/integration/src/main/java/ai/djl/integration/tests/training/EvaluatorTest.java
@@ -32,13 +32,13 @@ public class EvaluatorTest {
     public void testAccuracy() {
         try (NDManager manager = NDManager.newBaseManager(TestUtils.getEngine())) {
 
-            NDArray predictions =
+            NDArray predictionsArray =
                     manager.create(new float[] {0.3f, 0.7f, 0, 1, 0.4f, 0.6f}, new Shape(3, 2));
             NDArray labels = manager.create(new int[] {0, 1, 1}, new Shape(3));
 
             AbstractAccuracy acc = new Accuracy();
             acc.addAccumulator("");
-            acc.updateAccumulator("", new NDList(labels), new NDList(predictions));
+            acc.updateAccumulator("", new NDList(labels), new NDList(predictionsArray));
             float accuracy = acc.getAccumulator("");
             float expectedAccuracy = 2.f / 3;
             Assert.assertEquals(
@@ -50,7 +50,7 @@ public class EvaluatorTest {
 
             acc = new Accuracy();
             acc.addAccumulator("");
-            acc.updateAccumulator("", new NDList(labels), new NDList(predictions));
+            acc.updateAccumulator("", new NDList(labels), new NDList(predictionsArray));
             accuracy = acc.getAccumulator("");
             expectedAccuracy = 2.f / 3;
             Assert.assertEquals(
@@ -64,12 +64,12 @@ public class EvaluatorTest {
     public void testCoverage() {
         try (NDManager manager = NDManager.newBaseManager(TestUtils.getEngine())) {
 
-            NDArray predictions = manager.create(new float[] {0.3f, 0.7f, 0.0f}, new Shape(3));
+            NDArray predictionsArray = manager.create(new float[] {0.3f, 0.7f, 0.0f}, new Shape(3));
             NDArray labels = manager.create(new float[] {0.5f, 0.5f, 0.5f}, new Shape(3));
 
             Coverage coverage = new Coverage();
             coverage.addAccumulator("");
-            coverage.updateAccumulator("", new NDList(labels), new NDList(predictions));
+            coverage.updateAccumulator("", new NDList(labels), new NDList(predictionsArray));
             float accuracy = coverage.getAccumulator("");
             float expectedAccuracy = 1.f / 3;
             Assert.assertEquals(
@@ -82,7 +82,7 @@ public class EvaluatorTest {
     @Test
     public void testTopKAccuracy() {
         try (NDManager manager = NDManager.newBaseManager(TestUtils.getEngine())) {
-            NDArray predictions =
+            NDArray predictionsArray =
                     manager.create(
                             new float[] {
                                 0.1f, 0.2f, 0.3f, 0.4f, 0, 1, 0, 0, 0.3f, 0.5f, 0.1f, 0.1f
@@ -91,7 +91,7 @@ public class EvaluatorTest {
             NDArray labels = manager.create(new int[] {0, 1, 2}, new Shape(3));
             TopKAccuracy topKAccuracy = new TopKAccuracy(2);
             topKAccuracy.addAccumulator("");
-            topKAccuracy.updateAccumulator("", new NDList(labels), new NDList(predictions));
+            topKAccuracy.updateAccumulator("", new NDList(labels), new NDList(predictionsArray));
             float expectedAccuracy = 1.f / 3;
             float accuracy = topKAccuracy.getAccumulator("");
             Assert.assertEquals(
@@ -102,7 +102,7 @@ public class EvaluatorTest {
             labels = manager.create(new long[] {0, 1, 2}, new Shape(3));
             topKAccuracy = new TopKAccuracy(2);
             topKAccuracy.addAccumulator("");
-            topKAccuracy.updateAccumulator("", new NDList(labels), new NDList(predictions));
+            topKAccuracy.updateAccumulator("", new NDList(labels), new NDList(predictionsArray));
             expectedAccuracy = 1.f / 3;
             accuracy = topKAccuracy.getAccumulator("");
             Assert.assertEquals(