2017-06-07 7 views
1

デコードエラーを取得するプログラムを実行できません。実際には、私はgensimを使用してDoc2vecライブラリを試していますが、私はこのエラーが表示されますか? コード: -'utf-8' codec error while doc2vec

def to_array(self): 
    self.sentences = [] 
    for source, prefix in self.sources.items(): 
     with utils.smart_open(source) as fin: 
      for item_no, line in enumerate(fin): 
       self.sentences.append(LabeledSentence(
        utils.to_unicode(line).split(), [prefix + '_%s' % 
item_no])) 
    return self.sentences 

sentences = LabeledLineSentence(sources) 
model = Doc2Vec(min_count=1, window=10, size=100, dm_mean=0, sample=1e-5, 
negative=5, workers=12) 
model.build_vocab(sentences.to_array()) 

のエラー: - それは、UTF-8を望んでいるときに、このアナコンダのgensimプログラムはバイトを取得しているよう

File "<ipython-input-88-eab20df20acc>", line 75, in <module> 
model.build_vocab(sentences.to_array()) 

File "<ipython-input-88-eab20df20acc>", line 58, in to_array 
utils.to_unicode(line).split(), [prefix + '_%s' % item_no])) 

File "C:\Users\summert\AppData\Local\Continuum\Anaconda3\lib\site- 
packages\gensim\utils.py", line 235, in any2unicode 
return unicode(text, encoding, errors=errors) 

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 21: 
invalid continuation byt 

答えて

1

に見えます。 は、それが望むタイプに給餌されていません。

to_unicodeはどこにありますか?どこから 'utils'をインポートしたのですか?私はこれが普通のPython 3だとは思わない。thisを見てください。

Python 3を使用しているとすれば、おそらくそこには何も必要ありません。

(LabeledSentence(line.encode('utf-8').split()... 
:それは試して動作しない場合

だけ

(LabeledSentence(utils.to_unicode(line).split()... 

(LabeledSentence(line.split()... 

と交換

関連する問題