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

Fix perplexity computation in perplexity.md #34387

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

Framartin
Copy link
Contributor

What does this PR do?

This pull request fixes an issue in the code of the Perplexity of fixed-length models documentation. The current implementation computes the arithmetic mean of the negative log-likelihood (NLL) per sequence chunk without accounting for the varying number of tokens in each chunk. This can lead to an inaccurate average NLL per token, as tokens in smaller chunks (like the last one) have a higher weight in the final perplexity calculation. The PR computes the arithmetic mean of NLL per token. The perplexity error is small in the provided example (16.4541 vs. 16.4443), but I guess that it can be larger for shorter sequences.

Before submitting

Who can review?

@stevhliu @ArthurZucker

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks

@ArthurZucker ArthurZucker merged commit 626c610 into huggingface:main Oct 29, 2024
9 checks passed
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
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.

3 participants