This is an automated email from the ASF dual-hosted git repository.

krickert pushed a commit to branch feat/GH-1392-embed-padding
in repository https://gitbox.apache.org/repos/asf/opennlp.git

commit 6557e4c4d10ae52a1d77e6c69b48539713c36487
Author: Kristian Rickert <[email protected]>
AuthorDate: Sat Oct 10 08:30:39 2026 -0400

    GH-1391: Shorten the embedAll Javadoc and compute the expected batch sizes
    
    The paragraph after {@inheritDoc} repeated the class Javadoc; it is one
    line now. The limit test listed 4096 and 904 as literals; it computes them
    from MAX_BATCH_TOKEN_POSITIONS.
---
 .../main/java/opennlp/dl/vectors/SentenceVectorsDL.java   |  6 ++----
 .../opennlp/dl/vectors/SentenceVectorsDLEmbedderTest.java | 15 +++++++++------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git 
a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/SentenceVectorsDL.java
 
b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/SentenceVectorsDL.java
index a5afc055f..290f1a74c 100644
--- 
a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/SentenceVectorsDL.java
+++ 
b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/SentenceVectorsDL.java
@@ -278,10 +278,8 @@ public class SentenceVectorsDL extends AbstractDL 
implements TextEmbedder {
   /**
    * {@inheritDoc}
    *
-   * <p>The inputs are tokenized up front, grouped by tokenized length, and 
each group runs
-   * through the session with shape {@code [rows, length]}, split so that no 
inference exceeds
-   * {@value #MAX_BATCH_TOKEN_POSITIONS} token positions. A batch never pads, 
so every row is
-   * computed from the tensors its single-input call would have used.</p>
+   * <p>The inputs are grouped by tokenized length, never padded, and each 
group runs in
+   * inferences of at most {@value #MAX_BATCH_TOKEN_POSITIONS} token 
positions.</p>
    */
   @Override
   public float[][] embedAll(final List<? extends CharSequence> texts) {
diff --git 
a/opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/vectors/SentenceVectorsDLEmbedderTest.java
 
b/opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/vectors/SentenceVectorsDLEmbedderTest.java
index f944ae208..5adab3fbf 100644
--- 
a/opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/vectors/SentenceVectorsDLEmbedderTest.java
+++ 
b/opennlp-core/opennlp-ml/opennlp-dl/src/test/java/opennlp/dl/vectors/SentenceVectorsDLEmbedderTest.java
@@ -254,17 +254,20 @@ class SentenceVectorsDLEmbedderTest {
    * Asserts that {@code embedAll} splits a large group of same-length inputs 
into inferences of
    * at most {@value SentenceVectorsDL#MAX_BATCH_TOKEN_POSITIONS} token 
positions, and that every
    * row still equals its single-input vector. "hello world" encodes to 4 
tokens, so one
-   * inference takes at most 4096 rows.
+   * inference takes at most a quarter of the cap in rows.
    */
   @Test
   void testEmbedAllCapsTokenPositionsPerInference(@TempDir final Path dir) 
throws Exception {
+    final int helloWorldTokens = 4;
+    final int rowsPerInference = SentenceVectorsDL.MAX_BATCH_TOKEN_POSITIONS / 
helloWorldTokens;
+    final int count = rowsPerInference + rowsPerInference / 4;
     try (SentenceVectorsDL vectors = meanVectors(dir, 
SentenceVectorsDL.DEFAULT_MAX_LENGTH)) {
-      final List<String> texts = Collections.nCopies(5000, "hello world");
-      final List<List<Integer>> batches =
-          SentenceVectorsDL.batches(Collections.nCopies(5000, 
tokens(4)).toArray(new Tokens[0]));
+      final List<String> texts = Collections.nCopies(count, "hello world");
+      final List<List<Integer>> batches = SentenceVectorsDL.batches(
+          Collections.nCopies(count, tokens(helloWorldTokens)).toArray(new 
Tokens[0]));
       assertEquals(2, batches.size());
-      assertEquals(4096, batches.get(0).size());
-      assertEquals(904, batches.get(1).size());
+      assertEquals(rowsPerInference, batches.get(0).size());
+      assertEquals(count - rowsPerInference, batches.get(1).size());
       final float[][] batch = vectors.embedAll(texts);
       assertEquals(texts.size(), batch.length);
       for (final float[] row : batch) {

Reply via email to