python - 将 gensim KeyedVector 转换为模型的过程是什么?
问题描述
我想加载一个 gensim 预训练模型并继续训练它。
这个例子失败了......我尝试了许多变体和 gensim API,但我试图做的似乎不可能。
import gensim, logging, os
from gensim.models import KeyedVectors
from gensim.models import Word2Vec
import gensim.downloader as api
wv = api.load('word2vec-google-news-300')
# this fails - TypeError: 'int' object is not iterable
model = Word2Vec(wv)
class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
for fname in os.listdir(self.dirname):
for line in open(os.path.join(self.dirname, fname)):
yield line.split()
sentences = MySentences('all-tokenized-sentences.txt')
# Training the model with list of sentences (with 4 CPU cores)
model.train(sentences, workers=4)
解决方案
推荐阅读
- html - 我从服务器下载了一个项目,但图像没有以正确的路径显示
- elasticsearch - ElasticSearch:错误的相关顺序
- c# - 为什么成员变量不遵循递归返回规则?
- javascript - 当您不知道触发了哪些事件时,如何在更改输入字段的值后触发单击/更改事件
- wso2 - 带传感器的逻辑模式
- python - 3D 卷积自动编码器与输入层不匹配输出层
- c# - 使用 FileHelpers nuget 包读取条形码
- debezium - 如何在rest api中添加/删除Pulsar中的连接器?
- selenium - 使用 Selenium 使用部分 id 遍历值
- php - 如何将多个数组转换为单个数组