Как происходит преобразование gensim KeyedVector в модель? - PullRequest
0 голосов
/ 06 января 2020

Я хотел бы загрузить предварительно подготовленную модель gensim и продолжить ее обучение.

Этот пример не удался ... Я перепробовал много вариантов и API gensim, но то, что я пытаюсь сделать, не дает кажется возможным.

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)
...