【问题标题】:how can I train my model using python gensim如何使用 python gensim 训练我的模型
【发布时间】:2021-10-26 23:27:18
【问题描述】:

我正在尝试训练我的模型,当我编写这些代码时:

for epoch in range(max_epochs):
    model.train(tagged_data,
                total_examples=model.corpus_count,
                epochs=model.iter)

我得到的错误如下

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-6ecb8a2d0ac7> in <module>

      2     model.train(tagged_data,

      3                 total_examples=model.corpus_count,

----> 4                 epochs=model.iter)


AttributeError: 'Doc2Vec' object has no attribute 'iter'

【问题讨论】:

    标签: python nltk gensim doc2vec


    【解决方案1】:

    您可能复制了一些过时的示例代码。例如:

    • 最新版本的 Gensim 在 Doc2Vec 模型上没有 .iter 属性
    • 在您自己的 epochs 循环中多次调用 train() 几乎总是一个坏主意 - 特别是作为初学者只是想让事情正常进行

    所以:不要复制您要复制的任何来源。它不仅过时,而且暗示了一些从来都不是好主意的东西(train() 循环调用)。

    相反,将您的工作建立在更好的示例上,例如 Gensim 文档中的介绍教程:

    https://radimrehurek.com/gensim/auto_examples/tutorials/run_doc2vec_lee.html

    【讨论】:

      【解决方案2】:

      要解决此问题,请将 model.iter 更改为 model.epochs。例如:

      for epoch in range(max_epochs):
          model.train(tagged_data,
                  total_examples=model.corpus_count,
                  epochs=model.epochs)
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多