когда я обучал свою модель doc2vec, я проходил через набор данных несколько раз и каждый раз перетасовывал обзоры обучения, чтобы повысить точность. Затем python предоставил мне объект AttributeError: 'numpy.ndarray' не имеет атрибута 'words'. Далее следует мой код на Python:
def labelizeReviews(reviews, label_type):
labelized = []
for index, review in enumerate(reviews):
label = ' %s_%s ' % (label_type, index)
labelized.append(LabeledSentence(review, [label]))
return labelized
x_train = labelizeReviews(x_train, 'TRAIN') # input x_train is a list of word lists, each word list is a list of tokens of all words in one document
x_train=np.array(x_train)
model_dm = gensim.models.Doc2Vec(alpha=0.025, min_alpha=0.0001, iter=10, min_count=5, window=10, size=size, sample=1e-3,
negative=5, workers=3)
for epoch in range(10):
perm = np.random.permutation(x_train.shape[0])
model_dm.train(x_train[perm], total_examples=model_dbow.corpus_count, epochs=model_dbow.iter)
а затем следующее мое сообщение об ошибке:
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Users\123\Anaconda2\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Users\123\Anaconda2\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Users\123\Anaconda2\lib\site-packages\gensim-2.1.0-py2.7-win-amd64.egg\gensim\models\word2vec.py", line 857, in job_producer
sentence_length = self._raw_word_count([sentence])
File "C:\Users\123\Anaconda2\lib\site-packages\gensim-2.1.0-py2.7-win-amd64.egg\gensim\models\doc2vec.py", line 729, in _raw_word_count
return sum(len(sentence.words) for sentence in job)
File "C:\Users\123\Anaconda2\lib\site-packages\gensim-2.1.0-py2.7-win-amd64.egg\gensim\models\doc2vec.py", line 729, in <genexpr>
return sum(len(sentence.words) for sentence in job)
AttributeError: 'numpy.ndarray' object has no attribute 'words'
кто-нибудь знает, как решить эту проблему? Большое спасибо!!!