Bird
0
0

What is wrong with this code snippet for training Word2Vec?

medium📝 Debug Q14 of 15
NLP - Word Embeddings
What is wrong with this code snippet for training Word2Vec?
from gensim.models import Word2Vec
sentences = [['cat', 'dog'], ['mouse', 'rat']]
model = Word2Vec(sentences, size=50, window=3, min_count=1)
model.train(sentences, total_examples=2, epochs=10)
Amin_count must be greater than 1
B'train' method is missing required arguments
CSentences should be a flat list, not list of lists
DThe parameter 'size' is deprecated; use 'vector_size' instead
Step-by-Step Solution
Solution:
  1. Step 1: Check Word2Vec parameters

    Recent Gensim versions use 'vector_size' instead of 'size' for vector dimension.
  2. Step 2: Verify other code parts

    'train' method usage and sentences format are correct; min_count=1 is valid.
  3. Final Answer:

    The parameter 'size' is deprecated; use 'vector_size' instead -> Option D
  4. Quick Check:

    Use 'vector_size' not 'size' [OK]
Quick Trick: Use 'vector_size' for dimensions in Gensim 4+ [OK]
Common Mistakes:
MISTAKES
  • Using old 'size' parameter causes warnings or errors
  • Thinking sentences must be flat list
  • Believing min_count must be >1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes