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

attempting to let meteor handle multiple references per prediction #164

Merged
merged 12 commits into from
Jul 6, 2022

Conversation

sashavor
Copy link
Contributor

I'm not sure I'm doing the word_tokenize() correctly in line 27 -- @lvwerra can you please help?

@sashavor sashavor requested a review from lvwerra June 28, 2022 15:56
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 28, 2022

The documentation is not available anymore as the PR was closed or merged.

metrics/meteor/meteor.py Outdated Show resolved Hide resolved
Co-authored-by: Leandro von Werra <lvwerra@users.noreply.github.com>
@sashavor
Copy link
Contributor Author

Thank you @lvwerra !
One thing I can't seem to replicate is the example from NLTK:

    >>> reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that', 'ensures', 'that', 'the', 'military', 'will', 'forever', 'heed', 'Party', 'commands']
    >>> reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which', 'guarantees', 'the', 'military', 'forces', 'always', 'being', 'under', 'the', 'command', 'of', 'the', 'Party']
    >>> reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the', 'army', 'always', 'to', 'heed', 'the', 'directions', 'of', 'the', 'party']

    >>> round(meteor_score([reference1, reference2, reference3], hypothesis1),4)
    0.7398

When I do:

hypothesis1=  ['It is a guide to action which ensures that the military always obeys the commands of the party']
>>> references = [['It is a guide to action that ensures that the military will forever heed Party commands', 'It is the guiding principle which guarantees the military forces always being under the command of the Party', 'It is the practical guide for the army always to heed the directions of the party']]
>>> results = meteor.compute(predictions=hypothesis1, references=references)
>>> results
{'meteor': 0.6944444444444445}

The alpha, beta and gamma are all the same as NLTK.

Do you have any ideas? do you think it's the tokenizer?...

@lvwerra
Copy link
Member

lvwerra commented Jun 29, 2022

If you execute the first NLTK example yourself you get the same results? Or are they also different?

@sashavor
Copy link
Contributor Author

Nope 😕

>>> hypothesis1 = ['It is a guide to action which ensures that the military always obeys the commands of the party']
>>> reference1 = ['It is a guide to action that ensures that the military will forever heed Party commands']
>>> results = meteor.compute(predictions=hypothesis1, references=reference1)
>>> results
{'meteor': 0.6944444444444445}

Whereas the result given by NLTK is 0.7398

This is weird, right? since we're using it under the hood?

@lvwerra
Copy link
Member

lvwerra commented Jun 29, 2022

I just checked the NLTK example. It seems to be an issue with the version on their side: They switched from sentences to word tokens between 3.6 and 3.7 which is where the change must have happened:

with nltk==3.6.0 (note we need to join the examples):

hypothesis1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which', 'ensures', 'that', 'the', 'military', 'always', 'obeys', 'the', 'commands', 'of', 'the', 'party']

reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that', 'ensures', 'that', 'the', 'military', 'will', 'forever', 'heed', 'Party', 'commands']
reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which', 'guarantees', 'the', 'military', 'forces', 'always', 'being', 'under', 'the', 'command', 'of', 'the', 'Party']
reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the', 'army', 'always', 'to', 'heed', 'the', 'directions', 'of', 'the', 'party']

round(meteor_score([" ".join(reference1), " ".join(reference2), " ".join(reference3)], " ".join(hypothesis1)),4)

>>> 0.7298

in nltk==3.7.0:

hypothesis1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which', 'ensures', 'that', 'the', 'military', 'always', 'obeys', 'the', 'commands', 'of', 'the', 'party']

reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that', 'ensures', 'that', 'the', 'military', 'will', 'forever', 'heed', 'Party', 'commands']
reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which', 'guarantees', 'the', 'military', 'forces', 'always', 'being', 'under', 'the', 'command', 'of', 'the', 'Party']
reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the', 'army', 'always', 'to', 'heed', 'the', 'directions', 'of', 'the', 'party']

round(meteor_score([reference1, reference2, reference3], hypothesis1),4)

>>> 0.6944

So I would not worry about it in this PR but maybe open an issue on NLTK.

@sashavor sashavor marked this pull request as ready for review June 30, 2022 19:35
@sashavor
Copy link
Contributor Author

Ok great! I'll open a PR with NLTK then 😄

Copy link
Member

@lvwerra lvwerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this! A few minor comments. In addition, I think we should also document this in the README, right?

metrics/meteor/meteor.py Show resolved Hide resolved
metrics/meteor/meteor.py Outdated Show resolved Hide resolved
meteor_score.single_meteor_score(ref, pred, alpha=alpha, beta=beta, gamma=gamma)
for ref, pred in zip(references, predictions)
]
if any(isinstance(el, list) for el in references):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above. maybe you can also just check at the beginning once:

multiple_refs = isinstance(references[0], list)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change (I think) -- is this what you had in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated the README!

@sashavor sashavor requested a review from lvwerra July 4, 2022 17:14
Sasha Luccioni and others added 6 commits July 4, 2022 14:07
adding comment about NLTK version
Co-authored-by: Leandro von Werra <lvwerra@users.noreply.github.com>
checking first element
Updating README to reflect changes
Copy link
Member

@lvwerra lvwerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment about reusing multiple_refs. LGTM 🚀

metrics/meteor/meteor.py Outdated Show resolved Hide resolved
metrics/meteor/meteor.py Outdated Show resolved Hide resolved
metrics/meteor/meteor.py Outdated Show resolved Hide resolved
Sasha Luccioni and others added 3 commits July 6, 2022 12:02
Co-authored-by: Leandro von Werra <lvwerra@users.noreply.github.com>
Co-authored-by: Leandro von Werra <lvwerra@users.noreply.github.com>
Co-authored-by: Leandro von Werra <lvwerra@users.noreply.github.com>
@sashavor sashavor merged commit f62ad7c into main Jul 6, 2022
@sashavor sashavor deleted the meteor-modification branch July 6, 2022 16:13
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 this pull request may close these issues.

None yet

3 participants