【发布时间】:2017-06-22 23:06:43
【问题描述】:
我使用 gensim 包训练了一个 word2vec 模型并使用以下名称保存它。
model_name = "300features_1minwords_10context"
model.save(model_name)
我得到了这些日志消息信息。在模型得到训练和保存时。
INFO : not storing attribute syn0norm
INFO : not storing attribute cum_table
然后,我尝试使用这个加载模型,
from gensim.models import Word2Vec
model = Word2Vec.load("300features_1minwords_10context")
我收到以下错误。
2017-06-22 21:27:14,975 : INFO : loading Word2Vec object from 300features_1minwords_10context
2017-06-22 21:27:15,496 : INFO : loading wv recursively from 300features_1minwords_10context.wv.* with mmap=None
2017-06-22 21:27:15,497 : INFO : setting ignored attribute syn0norm to None
2017-06-22 21:27:15,498 : INFO : setting ignored attribute cum_table to None
2017-06-22 21:27:15,499 : INFO : loaded 300features_1minwords_10context
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-9d90db0f07c0> in <module>()
1 from gensim.models import Word2Vec
2 model = Word2Vec.load("300features_1minwords_10context")
----> 3 model.syn0.shape
AttributeError: 'Word2Vec' object has no attribute 'syn0'
另外,在文件“300features_1minwords_10context”中,显示
"300features_1minwords_10context" is not UTF-8 encoded
Saving disabled.
Open console for more details
为了修复上述属性错误,我也尝试了谷歌论坛的以下内容,
import gensim
model = gensim.models.KeyedVectors.load_word2vec_format("300features_1minwords_10context")
model.syn0.shape
这导致另一个错误是
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
该模型使用 UTF-8 编码的句子进行训练。我不确定为什么会抛出这个错误?
更多信息:
df = pd.read_csv('UNSPSCdataset.csv',encoding='mac_roman',low_memory=False)
features = ['MaterialDescription']
temp_features = df[features]
temp_features.to_csv('materialDescription', encoding='UTF-8')
X = pd.read_csv('materialDescription',encoding='UTF-8')
在这里,我必须使用“mac_roman”编码才能使用 pandas 数据框访问它。由于在训练模型时数据帧中的文本必须采用 UTF-8 格式,因此我通过使用 UTF-8 对其进行编码,将该特定特征保存在单独的 csv 文件中,之后,我访问了该特定列。
任何帮助都是可观的
【问题讨论】:
标签: python-3.x utf-8 nlp gensim word2vec