Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load FastText model from gensim.
NLP
from gensim.models import FastText model = FastText.load('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file extension like .bin or .vec which are not gensim model files.
Trying to load a text vector file instead of the model.
✗ Incorrect
The FastText model is saved as a model file, typically with .model extension. Use that filename to load it.
2fill in blank
mediumComplete the code to get the vector for the word 'apple' using FastText model.
NLP
vector = model.wv.[1]('apple')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.wv.vector which does not exist.
Using model.wv.word_vec which is deprecated.
✗ Incorrect
The correct method to get a word vector in gensim FastText is get_vector().
3fill in blank
hardFix the error in the code to train a FastText model on sentences.
NLP
from gensim.models import FastText sentences = [['hello', 'world'], ['fasttext', 'embedding']] model = FastText(sentences=[1], vector_size=50, window=3, min_count=1, epochs=10)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sentence' instead of 'sentences' causes a TypeError.
Passing data with wrong parameter name.
✗ Incorrect
The parameter name for training data in FastText is 'sentences'.
4fill in blank
hardFill both blanks to create a FastText model and train it on data.
NLP
model = FastText([1], vector_size=100, window=5, min_count=2) model.[2](sentences, total_examples=len(sentences), epochs=5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' or 'fit_transform' which are not methods of gensim FastText.
Not passing the training data correctly.
✗ Incorrect
You pass the training data as 'sentences' and call the 'train' method to train the model.
5fill in blank
hardFill both blanks to create a dictionary of word vectors for words longer than 3 characters.
NLP
word_vectors = {word: model.wv.[1](word) for word in model.wv.index_to_key if len(word) [2] 3 and word.isalpha()}
filtered_vectors = {k: v for k, v in word_vectors.items() if v is not None and v.any()}
print(len(filtered_vectors)) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect comparison operators like '<' or '=='.
Using wrong method names to get vectors.
✗ Incorrect
Use get_vector to get vectors, filter words with length > 3.