nlp_base icon indicating copy to clipboard operation
nlp_base copied to clipboard

AttributeError: 'float' object has no attribute 'decode'

Open slobLX opened this issue 5 years ago • 2 comments

So sorry to bother you again...

when I use "train()"

the error occur: Building prefix dict from the default dictionary ... Loading model from cache /tmp/jieba.cache Loading model cost 0.173 seconds. Prefix dict has been built succesfully.

Traceback (most recent call last): File "", line 1, in File "interrogative/api.py", line 17, in train model.train() File "interrogative/model.py", line 76, in train self.initialize_model() File "interrogative/model.py", line 31, in initialize_model train, label = self.corpus.generator() File "interrogative/corpus.py", line 62, in generator corpus = cls.read_corpus_from_file(corpus_path) File "interrogative/corpus.py", line 34, in perform_word_segment tokenizer = jieba.Tokenizer() File "/home1/liuxin/anaconda3/envs/py27/lib/python2.7/site-packages/pandas/core/series.py", line 3591, in apply mapped = lib.map_infer(values, f, convert=convert_dtype) File "pandas/_libs/lib.pyx", line 2217, in pandas._libs.lib.map_infer File "interrogative/corpus.py", line 34, in tokenizer = jieba.Tokenizer() File "/home1/liuxin/.local/lib/python2.7/site-packages/jieba/init.py", line 282, in cut sentence = strdecode(sentence) File "/home1/liuxin/.local/lib/python2.7/site-packages/jieba/_compat.py", line 37, in strdecode sentence = sentence.decode('utf-8') AttributeError: 'float' object has no attribute 'decode'

slobLX avatar Apr 26 '19 12:04 slobLX

you can just move decode('utf-8') directly. Beacuse in python 3, it was unicode str.

xyzindeed avatar Jun 27 '19 18:06 xyzindeed

我用的是:demjson.encode(text, encoding='utf-8')

fengchangmin666 avatar Jul 19 '19 07:07 fengchangmin666