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

Answer Relevance doesnt need context #1177

Closed
mohamad-tohidi opened this issue Aug 8, 2024 · 5 comments · Fixed by #1409
Closed

Answer Relevance doesnt need context #1177

mohamad-tohidi opened this issue Aug 8, 2024 · 5 comments · Fixed by #1409
Assignees
Labels
bug Something isn't working

Comments

@mohamad-tohidi
Copy link

[ ] I have checked the documentation and related resources and couldn't resolve my bug.

Describe the bug
the answer relevance metric, does not need context as input, it doesnt use it anywhere
so why is it when i try to run it without contexts list it gives me error?

even in the documentation you mentioned that it needs contexts, but you did not used it anywhere

@mohamad-tohidi mohamad-tohidi added the bug Something isn't working label Aug 8, 2024
Copy link

dosubot bot commented Aug 8, 2024

@mohamad-tohidi Hello there! I'm Dosu, a bot here to assist you with bug fixes, questions, and becoming a contributor. I'm here to help while you wait for a human maintainer.

The AnswerRelevance metric does indeed require a contexts list because it uses the contexts to extract relevant sentences necessary to answer the question. The contexts are joined into a single string and then tokenized into sentences for further processing. Without providing a contexts list, the metric cannot perform its intended function, leading to an error.

To resolve the error, ensure that you provide a contexts list when running the metric. The contexts list should be included in the row dictionary with the key "contexts". Here is an example of how to structure the row dictionary:

row = {
    "question": "What is the capital of France?",
    "contexts": ["Paris is the capital of France.", "It is known for its cafe culture and landmarks like the Eiffel Tower."]
}

This will allow the AnswerRelevancy class to properly process the contexts and compute the score [1][2].

The exact error message you receive when the contexts list is not provided is a KeyError, triggered by the following code:

question, contexts = row["question"], row["contexts"]

If row["contexts"] is not provided, it will raise a KeyError [3].

To continue talking to Dosu, mention @dosu.

@knpunk
Copy link

knpunk commented Aug 9, 2024

@dosu I'd like to add to this that, nowhere in the prompt it's instructing to go through the contexts. It's just taking care of non-committals and for contexts it's just few shot prompting. Maybe due to this I've noticed it's giving better scores for some of the wrong answers as compared to the correct ones. I'm no expert to say this but I think the prompt needs a little more fine tuning.

Cheers and thanks!

@gustavocidornelas
Copy link

Looking at the prompt, I also feel like the contexts shouldn't be required for answer relevance.

I understand the motivation for adding it in, exposed by @shahules786 on issue #440, but for many other cases, the context is not critical.

@jjmachan, if that's ok, I could prepare a PR that makes the context optional: if it's provided, fine, maintain the current behavior; otherwise, generate the questions based on the answer alone. What do you think?

@jjmachan
Copy link
Member

@gustavocidornelas your help would be highly appreciated - thanks a lot for offering! @shahules786 what do you think should be the next step?

@shahules786
Copy link
Member

You're right. From the past experience, it seems to me that adding contexts just to fit edge cases in the relevancy metric is not very useful. Just raised a PR to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants