You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BERTScore: OverflowError with transformers>=5 due to undefined model_max_length #739
When using evaluate.load("bertscore") with transformers>=5.0 and models that don't define model_max_length (e.g., microsoft/deberta-xlarge-mnli), the computation fails with:
OverflowError: int too big to convert
The error occurs at transformers/tokenization_utils_tokenizers.py in self._tokenizer.enable_truncation(**target), where the Rust tokenizers backend receives an integer (~10^30) that exceeds its maximum value.
Root Cause
Models like DeBERTa don't define model_max_length in their tokenizer config. Transformers assigns VERY_LARGE_INTEGER (~10^30) as default. In transformers>=5, this value is passed to the Rust tokenizers backend via enable_truncation(), which overflows.
Suggested Fixes:
Pass through max_length parameter: The underlying bert_score.score() function supports a max_length parameter, but evaluate's BERTScore wrapper (BERTScore._compute()) does not accept or forward it. Adding support for this parameter would allow users to work around the issue.
Cap model_max_length internally: Before calling the tokenizer, check if model_max_length exceeds a reasonable threshold and cap it (e.g., to the model's actual supported max length).
After reading the code, I see that evaluate's _compute() doesn't load the tokenizer directly - it passes model_type to bert_score.BERTScorer which handles tokenization internally.
It looks like, the change has to be done on underlying bert_score library!
Ran into the same OverflowError with DeBERTa-style tokenizers on transformers 5. This forwards max_length and clamps the placeholder model_max_length before bert-score tokenizes.
As noted above, the fix belongs in bert-score, which hasn't had a release since 2023 (Tiiiger/bert_score#205, unmerged PR #206). Until it has one: fitzyracing-bert-score 0.3.14 on PyPI is a drop-in fork of bert-score 0.3.13 with only this fix. The import name is still bert_score, so evaluate.load("bertscore") picks it up with no code changes. When the tokenizer reports the 1e30 placeholder, it encodes without truncation, as the slow tokenizers did, so scores match bert-score on transformers 4. Your microsoft/deberta-xlarge-mnli example works on transformers 5 with it:
Activity
meivelan commentedon Apr 25, 2026
Hi, I'd like to work on this. I'm planning to implement both suggested fixes
meivelan commentedon May 1, 2026
After reading the code, I see that evaluate's _compute() doesn't load the tokenizer directly - it passes model_type to bert_score.BERTScorer which handles tokenization internally.
It looks like, the change has to be done on underlying bert_score library!
What do you think?
ShamikOfficial commentedon Sep 2, 2026
Hi! Opening a PR for this.
Ran into the same
OverflowErrorwith DeBERTa-style tokenizers on transformers 5. This forwardsmax_lengthand clamps the placeholdermodel_max_lengthbefore bert-score tokenizes.#self-assign
fitzyracing1 commentedon Oct 9, 2026
As noted above, the fix belongs in bert-score, which hasn't had a release since 2023 (Tiiiger/bert_score#205, unmerged PR #206). Until it has one:
fitzyracing-bert-score0.3.14 on PyPI is a drop-in fork of bert-score 0.3.13 with only this fix. The import name is stillbert_score, soevaluate.load("bertscore")picks it up with no code changes. When the tokenizer reports the 1e30 placeholder, it encodes without truncation, as the slow tokenizers did, so scores match bert-score on transformers 4. Yourmicrosoft/deberta-xlarge-mnliexample works on transformers 5 with it:Details: https://github.com/fitzyracing1/bert_score