【问题标题】:Word2vec Model size is very small and it is not recognizing wordsWord2vec 模型非常小,无法识别单词
【发布时间】:2018-07-07 22:09:46
【问题描述】:

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

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

请帮我解决这个问题。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-19
      • 2021-02-25
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2022-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多