Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SASEvaluator returns score even when predicted_answers contains None #7842

Closed
mrm1001 opened this issue Jun 11, 2024 · 4 comments · Fixed by #7909
Closed

SASEvaluator returns score even when predicted_answers contains None #7842

mrm1001 opened this issue Jun 11, 2024 · 4 comments · Fixed by #7909

Comments

@mrm1001
Copy link

mrm1001 commented Jun 11, 2024

In a RAG pipeline, there are cases where the prompt instructs the LLM to return a placeholder answer if there is missing information in the context, such as "No answer". See an example in our evaluation repository.

In that case, it makes sense to replace the predicted answer in the RAG pipeline with None, instead of computing any metric on the placeholder answer. However, the SASEvaluator returns a score even if None is passed.

Example:

from haystack.components.evaluators import SASEvaluator

sas = SASEvaluator(model="sentence-transformers/all-mpnet-base-v2")
sas.warm_up()
sas.run(predicted_answers=[None, "Whatever"], ground_truth_answers=["Whatever", "Another whatever"])

the output is:

{'score': 0.46286168694496155,
 'individual_scores': [0.26153379678726196, 0.6641895771026611]}

Expected

{'score': 0.6641895771026611,
 'individual_scores': [None, 0.6641895771026611]}
@lbux
Copy link
Contributor

lbux commented Jun 11, 2024

In that case, it makes sense to replace the predicted answer in the RAG pipeline with None

This is something that I'm manually doing in my workflow, but I would like to see a component for. We have DocumentCleaner, so I think it would make sense to have an AnswerCleaner or a GeneratedAnswerCleaner which can take in a "stop word" parameter to scan the answer for a specific word/phrase.

The handling of 'None' might need to be applied to LLMEvaluator as well. I run a forked version and it accepts 'None' as a parameter and returns an answer. I will try running it on the main Haystack code to see what happens.

@lbux
Copy link
Contributor

lbux commented Jun 11, 2024

image

The same issue needs to be handled in LLMEvaluators.

@julian-risch
Copy link
Member

SASEvaluator expects List[str] for the input parameter predicted_answers. We can extend the input parameter validation here

raise ValueError("The number of predictions and labels must be the same.")
to catch cases where None is a value in the input list. In that case, we should raise a TypeError and let the user know that all values in the list are expected to be str.

@julian-risch julian-risch changed the title SASEvaluator returns score even when predicted answer is None SASEvaluator returns score even when predicted answer contains None Jun 20, 2024
@julian-risch julian-risch changed the title SASEvaluator returns score even when predicted answer contains None SASEvaluator returns score even when predicted_answers contains None Jun 20, 2024
@lbux
Copy link
Contributor

lbux commented Jun 21, 2024

I had a fix for LLM evaluator locally, but it looks like it was fixed as another PR #7818, so I made a PR request for my fix of SAS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants