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

Add optional use_effective_order parameter to BLEU score #1862

Merged

Conversation

JonasElburgUVA
Copy link
Contributor

The original BLEU score fails for answers shorter than four tokens because the number of 4-grams is zero. Adding the use_effective_order parameter allows users to obtain scores by considering only n-grams up to the number of tokens in the answer when ( N < 4 ). This feature is already implemented in sacreBLEU, so we only need to add the parameter to the BLEU object in ragas. The default is set to False to maintain previous behavior.

Original BLEU fails at answers shorter than four tokens, since the amount of 4-grams is zero. Adding the use effective order parameter allows the user to still obtain scores considering only n-grams up to the amount of tokens in the answer when N<4.
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 21, 2025
@shahules786 shahules786 self-assigned this Jan 21, 2025
@shahules786 shahules786 self-requested a review January 21, 2025 19:00
@shahules786
Copy link
Member

Hey @JonasElburgUVA thanks for taking notice. There was a slight mistake in your implementation so I have changed, you may use it like

from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import BleuScore

sample = SingleTurnSample(
    response="The Eiffel Tower is located in India.",
    reference="The Eiffel Tower is located in Paris."
)

scorer = BleuScore(kwargs={"use_effective_order":True})
await scorer.single_turn_ascore(sample)```

@shahules786 shahules786 merged commit 4bae2b0 into explodinggradients:main Jan 21, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants