0
0
Prompt Engineering / GenAIml~10 mins

Text embedding models in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a text embedding using a simple model.

Prompt Engineering / GenAI
embedding = model.[1](text)
Drag options to blanks, or click blank then click option'
Atransform
Bembed
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predict' instead of 'transform' causes errors because embeddings are not predictions.
Using 'fit' tries to train the model, not create embeddings.
2fill in blank
medium

Complete the code to normalize the embedding vector.

Prompt Engineering / GenAI
normalized_embedding = embedding / [1](embedding)
Drag options to blanks, or click blank then click option'
Anp.linalg.norm
Blen
Csum
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' adds all elements but does not give vector length.
Using 'len' returns number of elements, not vector magnitude.
3fill in blank
hard

Fix the error in the code to compute cosine similarity between two embeddings.

Prompt Engineering / GenAI
similarity = np.dot(embedding1, embedding2) / ([1](embedding1) * np.linalg.norm(embedding2))
Drag options to blanks, or click blank then click option'
Amax
Bsum
Clen
Dnp.linalg.norm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' or 'len' causes incorrect similarity calculation.
Forgetting to normalize both vectors leads to wrong results.
4fill in blank
hard

Fill both blanks to create a dictionary of word embeddings for words longer than 3 letters.

Prompt Engineering / GenAI
word_embeddings = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Amodel.transform(word)
Bmodel.fit(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' instead of 'transform' tries to train the model on single words.
Using '<' filters words shorter than 3 letters, which is incorrect here.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of embeddings where embedding norm is greater than 0.5.

Prompt Engineering / GenAI
filtered_embeddings = {word: emb for word, emb in embeddings.items() if [1](emb) [2] 0.5 and len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Anp.linalg.norm
B>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' changes the filter logic incorrectly.
Not using norm function causes errors in filtering.