0
0
NLPml~10 mins

Word similarity and analogies 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 load a pre-trained word embedding model using gensim.

NLP
from gensim.models import KeyedVectors
model = KeyedVectors.load_word2vec_format('[1]', binary=True)
Drag options to blanks, or click blank then click option'
Aword2vec.txt
Bfasttext.vec
Cglove.6B.100d.txt
DGoogleNews-vectors-negative300.bin
Attempts:
3 left
💡 Hint
Common Mistakes
Using a text file instead of a binary file for Word2Vec.
Confusing GloVe or FastText files with Word2Vec binary format.
2fill in blank
medium

Complete the code to find the top 3 words most similar to 'king' using the model.

NLP
similar_words = model.most_similar('[1]', topn=3)
Drag options to blanks, or click blank then click option'
Aking
Bqueen
Cman
Droyal
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a similar word like 'queen' instead of the target word 'king'.
Passing a concept or unrelated word.
3fill in blank
hard

Fix the error in the analogy code to find the word that fits: 'man' is to 'king' as 'woman' is to ____.

NLP
result = model.most_similar(positive=['king', '[1]'], negative=['man'], topn=1)
Drag options to blanks, or click blank then click option'
Awoman
Blady
Cqueen
Dprince
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'queen' in positive instead of 'woman'.
Confusing positive and negative lists.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their similarity scores to 'computer', filtering only words with similarity greater than 0.7.

NLP
similarity_dict = {word: [1] for word, score in model.most_similar('[2]', topn=10) if score > 0.7}
Drag options to blanks, or click blank then click option'
Ascore
Bword
C'computer'
D'laptop'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'score' as dictionary value.
Using 'laptop' instead of 'computer' as target word.
5fill in blank
hard

Fill all three blanks to create a list of words from the model's vocabulary that have length greater than 5 and contain the letter 'a'.

NLP
filtered_words = [[1] for [2] in model.index_to_key if [3]]
Drag options to blanks, or click blank then click option'
Aword
C'a' in word and len(word) > 5
Dlen(word) > 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using only length condition without checking for 'a'.