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

猜你喜欢

转载自blog.csdn.net/w5688414/article/details/105055784