0
0
Prompt Engineering / GenAIml~10 mins

Why LLMs understand and generate text in Prompt Engineering / GenAI - Test Your Understanding

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 language model using the transformers library.

Prompt Engineering / GenAI
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained('[1]')
Drag options to blanks, or click blank then click option'
Atensorflow
Bgpt2
Csklearn
Dpytorch-lightning
Attempts:
3 left
💡 Hint
Common Mistakes
Using library names instead of model names.
Confusing framework names with model identifiers.
2fill in blank
medium

Complete the code to tokenize input text for the language model.

Prompt Engineering / GenAI
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('gpt2')
inputs = tokenizer('[1]', return_tensors='pt')
Drag options to blanks, or click blank then click option'
AHello, how are you?
Bmodel
Ctokenizer
Dtransformers
Attempts:
3 left
💡 Hint
Common Mistakes
Passing model or tokenizer objects instead of text.
Passing library names as input text.
3fill in blank
hard

Fix the error in the code to generate text from the model output.

Prompt Engineering / GenAI
outputs = model.generate(inputs['input_ids'], max_length=[1])
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Drag options to blanks, or click blank then click option'
A'max_length'
B5
C50
Dinput_ids
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer.
Using too small a number limiting output length.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.

Prompt Engineering / GenAI
{word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of length.
Using wrong comparison operator like <= instead of >.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words with length greater than 4.

Prompt Engineering / GenAI
{ [1]: [2] for word in words if len(word) [3] 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using original word as key instead of uppercase.
Using wrong comparison operator or value.