首页 > 解决方案 > 加载了 gensim 的 Fasttext 模型不会继续使用新句子进行训练

问题描述

我正在尝试加载从https://fasttext.cc/docs/en/crawl-vectors.html下载的西班牙语 fasttext .bin 模型,并继续使用我感兴趣的特定领域的新句子对其进行训练。

系统:Anaconda、Jupyter Notebook、Python 3.6、升级后的 Gensim

我的代码(玩具示例):

from gensim.models.fasttext import load_facebook_model
import os
os.chdir('path/to/directory')
model = load_facebook_model('cc.es.300.bin')

'enmadrarse' in model.wv.vocab
>>> False
old_vector = np.copy(model.wv['enmadrarse'])

new_sentences = [['complexidad', 'cataratas', 'enmadrarse'],
['enmadrarse', 'cataratas', 'increibles'], 
['unidad','enmadrarse','complexa']]

model.build_vocab(new_sentences, update = True)
model.train(new_sentences, total_examples = len(new_sentences), epochs=model.epochs)

new_vector = np.copy(model.wv['enmadrarse'])
np.allclose(old_vector, new_vector, atol=1e-4)
>>> True

'enmadrarse' in model.wv.vocab
>>> False (still)

单词的旧向量和新向量是相等的,它仍然不在词汇表中,所以模型什么也没学到。我究竟做错了什么?

标签: pythongensimfasttextresuming-training

解决方案


推荐阅读