Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
NLP - Topic Modeling
Why does this code raise an error?
coherence_model = CoherenceModel(topics=lda_model.print_topics(), texts=tokenized_texts, dictionary=dictionary, coherence='c_v')
score = coherence_model.get_coherence()
Atexts parameter is missing
Bprint_topics() returns strings, not list of word lists
Cdictionary parameter is invalid
Dcoherence type 'c_v' is unsupported
Step-by-Step Solution
Solution:
  1. Step 1: Understand print_topics() output

    print_topics() returns formatted strings, but CoherenceModel expects list of word lists for topics.
  2. Step 2: Check other parameters

    Texts and dictionary are provided correctly, 'c_v' is supported coherence type.
  3. Final Answer:

    print_topics() returns strings, not list of word lists -> Option B
  4. Quick Check:

    print_topics() output incompatible with CoherenceModel [OK]
Quick Trick: Use list of word lists for topics, not print_topics() strings [OK]
Common Mistakes:
MISTAKES
  • Passing string topics instead of word lists
  • Missing texts parameter
  • Misunderstanding coherence type support

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes