Repository navigation
feat: Add Semantic Answer Similarity metric - #6877
Merged
Merged
Conversation
awinml
requested review from
dfokina and
silvanocerza
and removed request for
a team
January 31, 2024 13:00
Collaborator
Pull Request Test Coverage Report for Build 7758146880Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
silvanocerza
reviewed
Feb 2, 2024
Co-authored-by: Silvano Cerza <[email protected]>
silvanocerza
approved these changes
Feb 2, 2024
silvanocerza
left a comment
Contributor
There was a problem hiding this comment.
Great job as always. Thank you both. 🙏
|
|
||
| # All Cross Encoders do not return a set of logits scores that are normalized | ||
| # We normalize scores if they are larger than 1 | ||
| if (similarity_scores > 1).any(): |
There was a problem hiding this comment.
if (abs(similarity_scores) > 1).any(): ?
This was referenced Oct 13, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Fixes #6069
Proposed Changes:
Adds support for the Semantic Answer Similarity (SAS) metric to
EvaluationResult.calculate_metrics(...)The
_calculate_sasmethod of EvaluationResult had been updated to compute the SAS metric:Usage:
For evaluation of a pipeline:
How did you test it?
Unit tests have been added.
End-to-end tests with the following pipelines have been added:
Notes for the reviewer:
Certain cross encoders (like "ms-marco-MiniLM-L-6-v2") provide us with un-normalized similarity scores by simply outputting the logits. Since the mean of the normalized scores is what we use to calculate the final SAS score, it is necessary to normalize the logits by applying the sigmoid. For more information, please have a look at this issue.
In this implementation, we apply sigmoid to the logits returned by the cross encoder if they are greater than 1(un-normalized).
Alternatively, we could provide an optional
normalizeparameter. We decided against using this approach because it would produce SAS scores greater than 1, in the case that a cross-encoder model was passed withnormalize=False. This would make the results hard to interpret and compare.The tests in
test_eval_sas.pyhave been marked as integration tests, since they send need to send an API call to HuggingFace for fetching the SAS model config.This code was written collaboratively with @vrunm.