Repository navigation
fix: normalize SASEvaluator cross encoder scores based on the model - #13244
Conversation
SASEvaluator only applied a sigmoid to cross encoder scores when a score in the batch was above 1. For models that return raw logits, the same answer got a different score depending on the rest of the batch, and batches of only wrong answers returned negative scores. The sigmoid is now applied when the model's activation function is Identity.
|
@yuv009 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
|
I independently checked head 6606607 with tiny local models through the real CrossEncoder load/predict path, offline. The one-label Identity control confirms the normalization fix (main -0.5, this head 0.3775). The default Sigmoid control stays at 0.3775 on both heads. I have not duplicated the fix. I found a separate unsupported-model case on both that head and current main: a three-label cross encoder returns nested individual_scores, despite SASEvaluator declaring list[float]. With fixed logits [2, -1, 0], sigmoid is applied to each class separately, giving [[0.8807970, 0.2689414, 0.5]], and the overall score is 0.5499128, averaging those class columns. A three-label NLI configuration is a real CrossEncoder shape; no model weights were downloaded for this reproduction. This is not a blocker for this PR: the same output occurs on main. The narrow local candidate is to reject a cross encoder with num_labels != 1 in run, before predict, with a clear ValueError. It preserves this PR's normalization, bi-encoders, warm_up and empty-input behavior. Selecting a similarity label would need a defined API and is outside that candidate. Does rejection of unsupported multi-label models fit the intended SAS contract, or would you prefer a defined label-selection design? I am keeping this separate from the batch-normalization fix. If the guard is accepted later, the batch-invariance test's CrossEncoder mock needs num_labels = 1; whichever PR merges second would make that fixture adjustment. |
Related Issues
Proposed Changes:
For Cross Encoders,
SASEvaluatoronly applied a sigmoid when a score in the batch was above 1. Models likecross-encoder/ms-marco-MiniLM-L-6-v2return raw logits, and wrong answers have negative logits, so a batch with no good answer skipped the sigmoid and returned the raw logits. The same pair got a different score depending on the rest of the batch.Now the sigmoid is applied when the Cross Encoder's
activation_fnisIdentity, which means it returns raw logits. This depends only on the model, so a pair gets the same score in every batch. Models that already normalize their scores aren't affected.How did you test it?
Identityand aSigmoidmodel. TheIdentitycase fails without the fix.fmt-checkandtypeson the changed files.cross-encoder/ms-marco-MiniLM-L-6-v2model: a batch with only wrong answers went from -10.08 to 0.0, and "Lyon" vs "Paris" now scores the same in every batch.Notes for the reviewer
I went with the model's
activation_fninstead of theabs(similarity_scores) > 1idea from #6877, because that would still depend on the batch when all logits are between -1 and 1.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.