这篇将是我运行Word2vec的时候一些问题汇总:
- ImportError: cannot import name ‘logsumexp‘ from ‘scipy.misc‘
解决:将ldamodel.py文件中的from scipy.misc import logsumexp
改为from scipy.special import logsumexp
- TypeError: init() got an unexpected keyword argument ‘vector_size’
原因是使用的gensim版本为4.0.0,在这个版本中Word2Vec的参数size变成了vector_size
解决:model=Word2Vec(vector_size=vocab_dim,min_count=n_exposures,window=window_size,workers=cpu_count,epochs=n_iterations)
改为
model=Word2Vec(size=vocab_dim,min_count=n_exposures,window=window_size,workers=cpu_count,epochs=n_iterations)`
3.AttributeError: ‘KeyedVectors’ object has no attribute ‘vocab’
解决:keys方法已经更新,以前的无法使用,将代码改为model.wv.vocab.keys()
- model_config = json.loads(model_config.decode(‘utf-8’))
AttributeError: ‘str’ object has no attribute ‘decode’
解决:pip install tensorflow h5py==2.10.0
5.ValueError: Classification metrics can’t handle a mix of multilabel-indicator and multiclass targets
解决:
y_pred=model.predict(X_test)
后面加上
for i in range(len(y_pred)):
max_value=max(y_pred[i])
for j in range(len(y_pred[i])):
if max_value==y_pred[i][j]:
y_pred[i][j]=1
else:
y_pred[i][j]=0
print(classification_report(Y_test, y_pred))
或者
y_pred=model.predict(X_test)
y_pred = np.rint(y_pred)
print(classification_report(Y_test, y_pred))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)