python - 加载了 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)
单词的旧向量和新向量是相等的,它仍然不在词汇表中,所以模型什么也没学到。我究竟做错了什么?
解决方案
推荐阅读
- json - 涉及 Mule 3.8.5 中 JSON 有效负载的 Dataweave 转换错误
- python - Python 执行 Java - 如何将命令行参数传递给 Java 主方法?
- neo4j - Neo4j 3.4 升级--数据库未启动
- html - Bootstrap,第一次数据切换点击不起作用或数据不显示
- python - 无法访问谷歌存储桶无效的字符串值:'noAcl:'。允许值:[full, noacl]
- python - 与团队一起开发时强制使用包管理系统
- mysql - 根据特定条件返回唯一行
- dns - 如何修复 Windows Server 2012 上的 DCDiag 连接测试
- python - 如何提取智能表中的所有值
- ios - 使用 Cognito 用户 ID 将数据存储到 DynamoDB