python - Word2vec 模型尺寸很小,无法识别单词

标签 python python-3.x word2vec gensim word-embedding

我使用 gensim 包在 6.4 GB 文本数据 上训练了我的 word2vec 模型,该数据使用以下代码片段进行了预处理:

def read_input(input_file):
  with open(input_file, "r") as inp:
    inp_str = inp.read()

  inp_str = inp_str.strip('\n')
  inp_str = re.sub(r'\n', ' ', inp_str)
  lowercase = inp_str.lower()
  punc = lowercase.translate(str.maketrans('', '', string.punctuation))

  return (punc.translate(str.maketrans('','','1234567890')))

def read_(input_file):
  return( gensim.utils.simple_preprocess(input_file, deacc=True, min_len=3))          

doc = read_input('../train1.txt')
documents = read_(doc)
logging.info ("Done reading data file")

但每次我训练模型时,它的大小都是 147 Kb,这似乎不对,当我尝试从训练模型生成向量时,它说:

KeyError: "word 'type' not in vocabulary"

以下是我用来训练 word2vec 模型的代码:

old_model = Word2Vec.load('../word2vec_model')
old_model.train(documents, total_examples=old_model.corpus_count, epochs=7)

old_model.save('../word2vec_model1')

logging.info ("Saved the new word2vec model")

请帮我解决这个问题。

最佳答案

尺寸偏小,可能是因为您在设置模型的参数时,您可能为min_count参数使用了较大的值。 尝试减少 min_count 中的值并重新训练模型

关于python - Word2vec 模型尺寸很小,无法识别单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51222901/

相关文章:

python - 为什么 gensim doc2vec 中的单词或文档向量之间几乎所有余弦相似度都是正的?

python - 如何在 Python 中生成 Word2vec 向量?

python - 如何关闭python asyncio传输?

python - 如何找到子字符串并在 QTextEdit 中突出显示它?

python - 在 Python 3.5 64 位上通过 pip 安装 OpenCV

python - 如何调用 pypdfocr 函数以在 python 脚本中使用它们?

python - 带有语句的猴子补丁 python

python - 为什么无法从数组对象中获取 Py_buffer?

python - 递归斐波那契 yield

python - 如何在python中获取gensim中单词的最近文档