【发布时间】:2018-09-07 23:29:15
【问题描述】:
我想将X_train_word2vec 向量作为输入传递给Gensim Word2Vec 模型。
向量类型为numpy.ndarray,例如:
X_train_word2vec[9] = array([ 19, 7, 1, 20120, 2, 1, 856, 233, 671,
1, 1208, 6016, 2, 32, 0, 0, 0, 0, ....)]
当我运行这段代码时:
model_word2vec = models.Word2Vec(X_train_word2vec, size=150, window=9)
model_word2vec.train(X_train_word2vec,total_examples=X_train_word2vec.shape[0], epochs=10)
我收到此错误:
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U11') dtype('<U11') dtype('<U11')
我已阅读 this 的帖子,其中问题是由于输入数组中的数据类型不同,但在我的情况下,我拥有相同类型的所有数据:int。
更新:
model_Word2Vec之前的代码:
tokenizer = Tokenizer()
tokenizer.fit_on_texts(X)
sequence = tokenizer.texts_to_sequences(X)
seq_max_len = 50
X_seq = pad_sequences(sequenza, maxlen=seq_max_len,padding='post',truncating='post',dtype=int)
X_train_word2vec, X_test_word2vec, y_train_word2vec, y_test_word2vec = train_test_split(X_seq, y_cat, test_size=0.2, random_state=123)
【问题讨论】:
-
请显示完整的回溯。该错误表明您的代码中有 unicode 字符串。