Skip to content

fix: normalize SASEvaluator cross encoder scores based on the model - #13244

Merged
sjrl merged 2 commits into
deepset-ai:mainfrom
yuv009:fix/sas-evaluator-cross-encoder-logits
Oct 15, 2026
Merged

sjrl merged 2 commits into
deepset-ai:mainfrom
yuv009:fix/sas-evaluator-cross-encoder-logits

Conversation

@yuv009

@yuv009 yuv009 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

For Cross Encoders, SASEvaluator only applied a sigmoid when a score in the batch was above 1. Models like cross-encoder/ms-marco-MiniLM-L-6-v2 return 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_fn is Identity, 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?

  • Added a unit test with a mocked Cross Encoder that scores the same pair alone and in a batch with a correct answer, for an Identity and a Sigmoid model. The Identity case fails without the fix.
  • Ran the existing integration tests with the tiny bi encoder and cross encoder models, and the expected scores didn't change.
  • Ran all evaluator unit tests, plus fmt-check and types on the changed files.
  • Checked with the real cross-encoder/ms-marco-MiniLM-L-6-v2 model: 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_fn instead of the abs(similarity_scores) > 1 idea from #6877, because that would still depend on the batch when all logits are between -1 and 1.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

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
yuv009 requested a review from a team as a code owner October 13, 2026 14:24
@yuv009
yuv009 requested review from julian-risch and removed request for a team October 13, 2026 14:24
@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@yuv009 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/evaluators
  sas_evaluator.py
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@AryanRG

AryanRG commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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.

@yuv009

yuv009 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for testing this independently @AryanRG, and for keeping the multi-label case separate in #13251. Agreed that it's out of scope here, so this PR stays focused on the batch normalization. If #13251 merges first, I'll add num_labels = 1 to the test mock here.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Oct 15, 2026

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrl
sjrl merged commit 5ebd96a into deepset-ai:main Oct 15, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SASEvaluator returns negative scores when no cross encoder score in the batch is above 1

3 participants