krickert commented on code in PR #1462:
URL: https://github.com/apache/opennlp/pull/1462#discussion_r4243895812


##########
opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/vectors/TinyVectorModels.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License 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.
+ */
+package opennlp.dl.vectors;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+import java.util.Objects;
+
+import ai.onnxruntime.OrtEnvironment;
+import ai.onnxruntime.OrtException;
+import ai.onnxruntime.OrtProvider;
+
+import opennlp.dl.InferenceOptions;
+
+import static org.junit.jupiter.api.Assumptions.abort;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+/**
+ * Test fixtures for the bundled tiny ONNX models. {@code tiny-vectors.onnx} 
(see
+ * {@code gen_tiny_vectors_model.py}) computes {@code output[b][t] = 
float(input_ids[b][t]) * W}
+ * with {@code W = [0.5, -1, 2]}; {@code tiny-pooled.onnx} (see {@code 
gen_tiny_pooled_model.py})
+ * adds a {@code sentence_embedding} output holding the sum of the ids times 
{@code W}.
+ */
+public final class TinyVectorModels {
+
+  /** The model with a token output only. */
+  public static final String TINY_VECTORS = "tiny-vectors.onnx";
+
+  /** The model with an additional {@code sentence_embedding} output. */
+  public static final String TINY_POOLED = "tiny-pooled.onnx";
+
+  private static final String VECTORS_RESOURCES = "/opennlp/dl/vectors/";
+
+  private TinyVectorModels() {
+  }
+
+  /**
+   * Copies a classpath resource into a directory. The resource is copied 
rather than resolved in
+   * place, because inside the {@code opennlp-dl} test-jar, as used by {@code 
opennlp-dl-gpu}, it
+   * is not a file.
+   *
+   * @param dir The directory to copy into.
+   * @param resource The absolute classpath name of the resource.
+   * @param name The file name of the copy.
+   * @return The copied file.
+   * @throws IOException Thrown if the resource cannot be copied.
+   */
+  public static File copy(final Path dir, final String resource, final String 
name)

Review Comment:
   Done. One copy helper in the new `opennlp.dl.OnnxTestSupport`, and 
`LoadVocabTest` uses it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to