Richard Zowalla created OPENNLP-1977:
----------------------------------------
Summary: SentenceVectorsDL returns the [CLS] hidden state instead
of the pooled sentence embedding
Key: OPENNLP-1977
URL: https://issues.apache.org/jira/browse/OPENNLP-1977
Project: OpenNLP
Issue Type: Bug
Reporter: Richard Zowalla
Fix For: 3.0.0
{{SentenceVectorsDL.getVectors}} returns {{v\[0\]\[0\]}}, the raw last hidden
state of the first \(\[CLS\]\) token. The class targets sentence\-transformers
models converted to ONNX, and {{SentenceVectorsDLEval}} uses
all\-MiniLM\-L6\-v2, whose {{1\_Pooling/config.json}} sets
{{pooling\_mode\_mean\_tokens: true}} and {{pooling\_mode\_cls\_token: false}},
followed by a Normalize module. So the returned vector is not the embedding the
model was trained to produce, and similarity scores differ from
sentence\-transformers.
Suggested fix: read the pooling mode and normalization from the model's
sentence\-transformers metadata \({{1\_Pooling/config.json}},
{{modules.json}}\) when present, otherwise require it as an option; mean
pooling must exclude padding positions. Since the 3.0.0 release note already
states that vectors change, the default should be settled before 3.0.0.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)