0
0
NLPml~10 mins

Pre-trained embedding usage 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 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'
Aglove.6B.100d.txt
BGoogleNews-vectors-negative300.bin
Cfasttext.vec
Drandom_vectors.txt
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.
2fill in blank
medium

Complete 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'
Aapple
Bfruit
Cbanana
Dorange
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different word than 'apple'.
Not using quotes around the word.
3fill in blank
hard

Fix 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'
Avocab
Bembedding_model
Ckey_to_index
Dcomputer
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the wrong variable or attribute.
Not using quotes around the word.
4fill in blank
hard

Fill 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'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using the word variable instead of its length.
5fill in blank
hard

Fill 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'
Acossim
Cq
Dcosine
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong function name for cosine similarity.
Not filtering words starting with 'q'.