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

Seq2Seq Metrics QOL: Bleu, Rouge #107

Closed
sshleifer opened this issue Nov 3, 2020 · 5 comments
Closed

Seq2Seq Metrics QOL: Bleu, Rouge #107

sshleifer opened this issue Nov 3, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@sshleifer
Copy link

sshleifer commented Nov 3, 2020

Putting all my QOL issues here, idt I will have time to propose fixes, but I didn't want these to be lost, in case they are useful. I tried using rouge and bleu for the first time and wrote down everything I didn't immediately understand:

What I tried

Rouge experience:

rouge = load_metric('rouge')
rouge.add_batch(['hi im sam'], ['im daniel']) # fails
rouge.add_batch(predictions=['hi im sam'], references=['im daniel']) # works
rouge.compute() # huge messy output, but reasonable. Not worth integrating b/c don't want to rewrite all the postprocessing.

BLEU experience:

bleu = load_metric('bleu')
bleu.add_batch(predictions=['hi im sam'], references=['im daniel'])
bleu.add_batch(predictions=[['hi im sam']], references=[['im daniel']])

bleu.add_batch(predictions=[['hi im sam']], references=[['im daniel']])

All of these raise ValueError: Got a string but expected a list instead: 'im daniel'

Doc Typo

This says dataset=load_metric(...) which seems wrong, will cause NameError

image

cc @lhoestq, feel free to ignore.

@sshleifer sshleifer added the enhancement New feature or request label Nov 3, 2020
@lhoestq
Copy link
Member

lhoestq commented Nov 3, 2020

Hi ! Thanks for letting us know your experience :)
We should at least improve the error messages indeed

@mrm8488
Copy link

mrm8488 commented Nov 12, 2020

So what is the right way to add a batch to compute BLEU?

@antoinetaliercio
Copy link

prediction = [['Hey', 'how', 'are', 'you', '?']]
reference=[['Hey', 'how', 'are', 'you', '?']]
bleu.compute(predictions=prediction,references=reference)

also tried this kind of things lol
I definitely need help too

@lhoestq
Copy link
Member

lhoestq commented Jan 28, 2021

Hi !

As described in the documentation for bleu:

Args:
    predictions: list of translations to score.
        Each translation should be tokenized into a list of tokens.
    references: list of lists of references for each translation.
        Each reference should be tokenized into a list of tokens.

Therefore you can use this metric this way:

from datasets import load_metric

predictions = [
    ["hello", "there", "general", "kenobi"],                             # tokenized prediction of the first sample
    ["foo", "bar", "foobar"]                                             # tokenized prediction of the second sample
]
references = [
    [["hello", "there", "general", "kenobi"], ["hello", "there", "!"]],  # tokenized references for the first sample (2 references)
    [["foo", "bar", "foobar"]]                                           # tokenized references for the second sample (1 reference)
]

bleu = load_metric("bleu")
bleu.compute(predictions=predictions, references=references)
# Or you can also add batches before calling compute()
# bleu.add_batch(predictions=predictions, references=references)
# bleu.compute()

Hope this helps :)

@mariosasko mariosasko transferred this issue from huggingface/datasets Jun 2, 2022
@lvwerra
Copy link
Member

lvwerra commented Jun 3, 2022

This was addressed in #20 and #49.

@lvwerra lvwerra closed this as completed Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants