python-Levenshtein AttributeError: module 'Levenshtein' has no attribute 'distance'

今天咋运行程序的时候,出现了下面的错误:

[1/1000][15050/15056]   Loss = 85.33192443847656
[1/1000][15051/15056]   Loss = 85.493408203125
[1/1000][15052/15056]   Loss = 78.12874603271484
[1/1000][15053/15056]   Loss = 86.8485107421875
[1/1000][15054/15056]   Loss = 81.8629150390625
[1/1000][15055/15056]   Loss = 136.6531219482422
decoding
0it [00:01, ?it/s]
Traceback (most recent call last):
  File "train.py", line 117, in <module>
    train(model)
  File "train.py", line 70, in train
    cer = eval(model, dev_dataloader)
  File "train.py", line 103, in eval
    cer += decoder.cer(trans, ref) / float(len(ref))
  File "/home/eric/Documents/SpeechRecognition_MASR/decoder.py", line 58, in cer
    return Lev.distance(s1, s2)
AttributeError: module 'Levenshtein' has no attribute 'distance'

然后发现自己已经装了Levenshtein。

解决方法

pip install python-Levenshtein==0.11.2

我原来的版本是0.12,降了一下版本,然后就不报错了。

测试代码为:

import Levenshtein as lev
lev.distance('Levenshtein', 'Lenvinsten')

如果正常输出为4的话,说明是正常的。

参考文献

[1].How to import and use python Levenshtein extension on OSX?. https://stackoverflow.com/questions/28172261/how-to-import-and-use-python-levenshtein-extension-on-osx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值