Bird
0
0

Given the following Python code snippet using gensim LDA, what will print(ldamodel.num_topics) output?

medium📝 Predict Output Q4 of 15
NLP - Topic Modeling
Given the following Python code snippet using gensim LDA, what will print(ldamodel.num_topics) output?
from gensim import corpora, models
texts = [['apple', 'banana', 'apple'], ['banana', 'orange'], ['apple', 'orange', 'banana']]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
ldamodel = models.LdaModel(corpus, num_topics=2, id2word=dictionary, passes=10)
print(ldamodel.num_topics)
A2
B3
C10
DLength of texts list
Step-by-Step Solution
Solution:
  1. Step 1: Understand LdaModel parameters

    The parameter num_topics=2 sets the number of topics in the model.
  2. Step 2: Check the attribute

    ldamodel.num_topics returns the number of topics set during initialization.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    num_topics attribute = 2 [OK]
Quick Trick: num_topics attribute matches initialization parameter [OK]
Common Mistakes:
MISTAKES
  • Confusing num_topics with number of passes
  • Assuming num_topics equals number of documents
  • Thinking num_topics is length of texts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes