TypeError: Fraction.__new__() got an unexpected keyword argument '_normalize'

506 阅读1分钟

报错信息

  File "/home/xxx/miniconda3/envs/torch/lib/python3.12/site-packages/nltk/translate/bleu_score.py", line 368, in modified_precision
    return Fraction(numerator, denominator, _normalize=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Fraction.__new__() got an unexpected keyword argument '_normalize'

原因

Fraction object creation fails with extra kwargs in bleu_score.py · Issue #3232 · nltk/nltk (github.com)

总之就是nltk包在python3.12导致的报错

解决方法

由于nltk包在pypi上从2023年2月就不再更新,所以只能用github上的代码

  1. 可以从github安装nltk(未试过,应该可行)
  2. 或者直接按照Merge pull request #3207 from k4black/python-3-12 · nltk/nltk@28eeb3e (github.com)这个commitnltk/translate/bleu_score.py文件进行修改

哪里会出现这个问题

github.com/hiyouga/LLa… 测试模型时会用到bleu