Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pretrained model from Hugging Face.
Prompt Engineering / GenAI
from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using framework names like 'tensorflow' instead of model names.
Confusing model names with unrelated libraries.
✗ Incorrect
The correct model name to load a pretrained BERT model is 'bert-base-uncased'.
2fill in blank
mediumComplete the code to prepare the tokenizer for the model.
Prompt Engineering / GenAI
from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tokenizer from a different model family.
Using a tokenizer that does not match the model.
✗ Incorrect
The tokenizer must match the model, so 'bert-base-uncased' is correct here.
3fill in blank
hardFix the error in the training loop by completing the missing optimizer step.
Prompt Engineering / GenAI
for batch in train_dataloader: outputs = model(**batch) loss = outputs.loss loss.backward() [1] optimizer.zero_grad()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling loss.backward() twice.
Calling step() on loss or model instead of optimizer.
✗ Incorrect
After backward(), optimizer.step() updates the model weights.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
Prompt Engineering / GenAI
{word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using '<' instead of '>' in the condition.
✗ Incorrect
We want the length as value and filter words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a filtered dictionary with uppercase keys, values as counts, and only include counts greater than 1.
Prompt Engineering / GenAI
filtered_counts = { [1]: [2] for [3], count in counts.items() if count > 1 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using count.upper() which is invalid for integers.
Swapping keys and values in the dictionary comprehension.
✗ Incorrect
Keys are uppercase words, values are counts, and iteration uses word and count.