krickert commented on code in PR #1072:
URL: https://github.com/apache/opennlp/pull/1072#discussion_r3403719995
##########
opennlp-eval-tests/src/test/java/opennlp/dl/vectors/SentenceVectorsDLEval.java:
##########
@@ -38,10 +38,10 @@ public void generateVectorsTest() throws Exception {
final float[] vectors = sv.getVectors(sentence);
- Assertions.assertEquals(vectors[0], 0.39994872, 0.00001);
- Assertions.assertEquals(vectors[1], -0.055101186, 0.00001);
- Assertions.assertEquals(vectors[2], 0.2817594, 0.00001);
- Assertions.assertEquals(vectors.length, 384);
+ Assertions.assertEquals(0.044745024, vectors[0], 0.00001);
Review Comment:
Done, added a comment block above the assertions documenting where the
values come from.
The pinned values are the first three components of
`last_hidden_state[0][0]` (the `[CLS]` position) produced by the ONNX export of
[sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
for the input `[CLS] george washington was president [SEP]` with the corrected
encoding (`attention_mask=1`, `token_type_ids=0`).
They are reproducible independently of OpenNLP with the HuggingFace
reference implementation (Python packages `tokenizers` and `onnxruntime`):
```python
tok = BertWordPieceTokenizer("vocab.txt", lowercase=True)
enc = tok.encode("george washington was president", add_special_tokens=True)
ids = np.array([enc.ids], dtype=np.int64)
out = ort.InferenceSession("model.onnx").run(None, {
"input_ids": ids,
"attention_mask": np.ones_like(ids),
"token_type_ids": np.zeros_like(ids)})[0]
out[0][0][:3] # -> [0.04474502, 0.20219636, 0.41306049]
```
I re-ran this against the eval model before pinning the comment; the three
values match exactly.
--
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]