Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Word2Vec model from gensim.
NLP
from gensim.models import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'word2vec' which is not the class name.
Misspelling the class name like 'WordVec' or 'WordToVec'.
✗ Incorrect
The correct class name to import is Word2Vec with capital W and V.
2fill in blank
mediumComplete the code to initialize a Word2Vec model with vector size 100.
NLP
model = Word2Vec(sentences, vector_size=[1], window=5, min_count=1, workers=4)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using vector size too small or too large without reason.
Confusing vector_size with window size.
✗ Incorrect
The vector size parameter controls the size of word vectors. Here, 100 is a common choice.
3fill in blank
hardFix the error in the code to train the Word2Vec model on sentences.
NLP
model.[1](sentences) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' which is common in scikit-learn but not in gensim.
Using 'fit_transform' which is not a Word2Vec method.
✗ Incorrect
The correct method to train a Word2Vec model is train.
4fill in blank
hardFill both blanks to create a dictionary of word vectors for words with frequency above 2.
NLP
word_vectors = {word: model.wv.[1](word) for word in model.wv.index_to_key if model.wv.get_vecattr(word, '[2]') > 2} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'vector' instead of 'get_vector' to get word vectors.
Using 'frequency' instead of 'count' for word frequency attribute.
✗ Incorrect
get_vector retrieves the vector for a word, and count is the attribute for word frequency.
5fill in blank
hardFill all three blanks to save the trained model and then load it back.
NLP
model.[1]('word2vec.model') loaded_model = Word2Vec.[2]('word2vec.model') vector = loaded_model.wv.[3]('example')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' instead of 'save' or 'load'.
Using 'vector' instead of 'get_vector' to get word vectors.
✗ Incorrect
Use save to save the model, load to load it, and get_vector to get a word's vector.