pysrilm icon indicating copy to clipboard operation
pysrilm copied to clipboard

TypeError: expected bytes, str found when load model

Open ttpro1995 opened this issue 8 years ago • 3 comments

I generate model with srilm

ngram-count -text VNESEcorpus.txt -order 3 -unk -lm vnese.lm

When I load with pysrilm, it need bytes, not str

>>> path = "/home/cpu11453local/workspace/SRILM_model/vnese.lm"
>>> lm = LM(path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "srilm.pyx", line 110, in srilm.LM.__cinit__
    fp = new_File(path, "r")
TypeError: expected bytes, str found

ttpro1995 avatar Nov 20 '17 09:11 ttpro1995

Yes, the examples in the README are python 2.

njsmith avatar Nov 21 '17 02:11 njsmith

Is there a way to make this to work for python3?

kushalarora avatar Aug 15 '18 00:08 kushalarora

I fixed this issue by doing path.encode(). This issue exists because of handling of strings in python2 and 3. By default, in python3 the str is a unicode. The encode handles this and you can use the code with python3.

kushalarora avatar Aug 20 '18 23:08 kushalarora