0
0
NLPml~10 mins

Visualizing embeddings (t-SNE) 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 t-SNE class from sklearn.manifold.

NLP
from sklearn.manifold import [1]
Drag options to blanks, or click blank then click option'
ATSNE
BtSNE
Ct_SNE
DTsne
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters like 'tSNE' or 'Tsne' causes import errors.
Adding underscores like 't_SNE' is incorrect.
2fill in blank
medium

Complete the code to create a t-SNE object with 2 components for visualization.

NLP
tsne = TSNE(n_components=[1], random_state=42)
Drag options to blanks, or click blank then click option'
A3
B5
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting n_components to 3 or more makes visualization harder.
Using 1 component loses too much information.
3fill in blank
hard

Fix the error in the code to fit and transform the embeddings using t-SNE.

NLP
embeddings_2d = tsne.[1](embeddings)
Drag options to blanks, or click blank then click option'
Afit
Bfit_predict
Cfit_transform
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using only fit does not return transformed data.
Using transform without fitting causes errors.
4fill in blank
hard

Fill both blanks to create a scatter plot of the 2D embeddings with labels.

NLP
plt.scatter(embeddings_2d[:, [1]], embeddings_2d[:, [2]], c=labels, cmap='viridis')
plt.title('t-SNE visualization')
plt.show()
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using indices 2 or 3 causes index errors.
Swapping x and y axes can confuse interpretation.
5fill in blank
hard

Fill the blanks to create a dictionary of word embeddings filtered by length and visualize with t-SNE.

NLP
filtered_embeddings = {word: embedding for word, embedding in all_embeddings.items() if len(word) [1] 5}
tsne = TSNE(n_components=[2], random_state=42)
embeddings_2d = tsne.fit_transform(list(filtered_embeddings.values()))
Drag options to blanks, or click blank then click option'
A<
B>
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using > 5 filters out short words instead of keeping them.
Setting n_components to 3 makes visualization 3D, which is harder to plot.