使用g2p_en包时遇dataclass_transform()参数错误求助
解决g2p_en运行报错
dataclass_transform() got an unexpected keyword argument 'field_specifiers'的方法 这个错误是由于依赖库版本不兼容导致的:typing_extensions库的新版本修改了dataclass_transform函数的参数,而g2p_en依赖的其他库仍在使用旧参数调用方式。
修复步骤:
- 卸载当前的
typing_extensions:
!pip uninstall -y typing_extensions
- 安装兼容的旧版本(4.10.0版本与旧依赖参数匹配):
!pip install typing_extensions==4.10.0
- 重新运行示例代码:
from g2p_en import G2p texts = ["I have $250 in my pocket.", # number -> spell-out "popular pets, e.g. cats and dogs", # e.g. -> for example "I refuse to collect the refuse around here.", # homograph "I'm an activationist."] # newly coined word g2p = G2p() for text in texts: out = g2p(text) print(out)
补充方案(若上述步骤无效):
同时锁定transformers的版本到4.x系列(如4.30.2),避免新版本引发的参数冲突:
!pip install transformers==4.30.2
内容的提问来源于stack exchange,提问作者Turing101
相关产品推荐
相关产品推荐

