This error occurs when using the train() function of the Word2Vec model from the gensim library without specifying either total_examples or total_words parameters.

To fix this error, you need to provide either total_examples or total_words parameter to the train() function. These parameters are used for learning-rate and progress calculations during training.

If you have just built the vocabulary using the same corpus, you can use the count cached in the model as the value for total_examples. You can set total_examples=model.corpus_count to resolve the error.

Here's an example:

from gensim.models import Word2Vec

# Create a Word2Vec model
model = Word2Vec()

# Build the vocabulary
model.build_vocab(corpus)

# Train the model
model.train(corpus, total_examples=model.corpus_count, epochs=model.epochs)

Make sure to replace corpus with your actual corpus of text data.

Gensim Word2Vec: 解决'ValueError: You must specify either total_examples or total_words' 错误

原文地址: https://www.cveoy.top/t/topic/jqy3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录