0
0
Prompt Engineering / GenAIml~10 mins

Embedding generation 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 generate an embedding vector from text using a model.

Prompt Engineering / GenAI
embedding = model.[1](text)
Drag options to blanks, or click blank then click option'
Afit
Btrain
Cpredict
Dencode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' or 'fit' instead of 'encode' to get embeddings.
Using 'predict' which is for classification or regression outputs.
2fill in blank
medium

Complete the code to normalize the embedding vector to unit length.

Prompt Engineering / GenAI
normalized_embedding = embedding / [1](embedding)
Drag options to blanks, or click blank then click option'
Asum
Blen
Cnp.linalg.norm
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum or max which do not compute vector length.
Using len which returns number of elements, not magnitude.
3fill in blank
hard

Fix the error in the code to generate embeddings for a list of texts.

Prompt Engineering / GenAI
embeddings = [model.[1](text) for text in texts]
Drag options to blanks, or click blank then click option'
Aencode
Btrain
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' or 'fit' which are for model training, not embedding generation.
Using 'predict' which is for output predictions, not embeddings.
4fill in blank
hard

Fill both blanks to create a dictionary of text to embedding length for texts longer than 5 characters.

Prompt Engineering / GenAI
embedding_lengths = {text: len(model.[1](text)) for text in texts if len(text) [2] 5}
Drag options to blanks, or click blank then click option'
Aencode
B>
C<
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predict' instead of 'encode' for embeddings.
Using '<' instead of '>' which filters shorter texts.
5fill in blank
hard

Fill all three blanks to compute cosine similarity between two normalized embeddings.

Prompt Engineering / GenAI
cos_sim = np.dot([1], [2]) / (np.linalg.norm([3]) * np.linalg.norm([2]))
Drag options to blanks, or click blank then click option'
Aembedding1
Bembedding2
Dembedding3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different vector like embedding3 which is undefined.
Mixing up the order of embeddings in dot product or norms.