0
0
NLPml~10 mins

Choosing number of topics in NLP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the library needed for topic modeling.

NLP
from sklearn.decomposition import [1]
Drag options to blanks, or click blank then click option'
APCA
BKMeans
CNMF
DTSNE
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing PCA or KMeans which are not used for topic modeling here.
2fill in blank
medium

Complete the code to create an NMF model with a specified number of topics.

NLP
model = NMF(n_components=[1], random_state=42)
Drag options to blanks, or click blank then click option'
A5
B0.5
C'five'
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a float or string instead of an integer for number of topics.
3fill in blank
hard

Fix the error in the code to fit the NMF model on the document-term matrix X.

NLP
W = model.[1](X)
Drag options to blanks, or click blank then click option'
Afit_predict
Bfit_transform
Ctransform
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform without fitting first causes an error.
4fill in blank
hard

Fill both blanks to compute reconstruction error and print it.

NLP
error = model.[1]
print('Reconstruction error:', model.[2])
Drag options to blanks, or click blank then click option'
Areconstruction_err_
Breconstruction_error_
Creconstruction_err
Dreconstruction_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like reconstruction_error or missing underscore.
5fill in blank
hard

Fill all three blanks to create a dictionary of topic words with their weights for the first topic.

NLP
topic_words = {word: model.components_[0, [1]] for [2], word in enumerate(vectorizer.get_feature_names_out()) if [3] < 10}
Drag options to blanks, or click blank then click option'
Ai
Bidx
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using wrong variable names for indices.