Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pre-trained embedding model using gensim.
NLP
from gensim.models import KeyedVectors embedding_model = KeyedVectors.load_word2vec_format('[1]', binary=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a text file instead of a binary file for Word2Vec loading.
Confusing GloVe or FastText files with Word2Vec binary format.
✗ Incorrect
The GoogleNews-vectors-negative300.bin file is a common pre-trained Word2Vec binary format model used with gensim.
2fill in blank
mediumComplete the code to get the vector for the word 'apple' from the embedding model.
NLP
vector = embedding_model['[1]']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different word than 'apple'.
Not using quotes around the word.
✗ Incorrect
To get the vector for the word 'apple', you access the embedding model with the key 'apple'.
3fill in blank
hardFix the error in the code to check if the word 'computer' is in the embedding model vocabulary.
NLP
if '[1]' in embedding_model.key_to_index: print('Found') else: print('Not found')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the wrong variable or attribute.
Not using quotes around the word.
✗ Incorrect
To check if 'computer' is in the vocabulary, you check if the string 'computer' is in embedding_model.key_to_index.
4fill in blank
hardFill both blanks to create a dictionary of word vectors for words longer than 5 characters.
NLP
word_vectors = {word: embedding_model[word] for word in embedding_model.key_to_index if [1] [2] 5} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using the word variable instead of its length.
✗ Incorrect
We use len(word) to get the length of the word and check if it is greater than 5.
5fill in blank
hardFill all three blanks to create a list of cosine similarities between 'king' and other words starting with 'q'.
NLP
from gensim.matutils import [1] similarities = [[2](embedding_model['king'], embedding_model[word]) for word in embedding_model.key_to_index if word.startswith('[3]')]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong function name for cosine similarity.
Not filtering words starting with 'q'.
✗ Incorrect
The function cossim computes cosine similarity. We use it to compare 'king' with words starting with 'q'.