0
0
Prompt Engineering / GenAIml~10 mins

Hugging Face fine-tuning 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 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'
Ascikit-learn
Bpytorch-lightning
Cbert-base-uncased
Dtensorflow
Attempts:
3 left
💡 Hint
Common Mistakes
Using framework names like 'tensorflow' instead of model names.
Confusing model names with unrelated libraries.
2fill in blank
medium

Complete 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'
Agpt2
Broberta-base
Cdistilbert-base-uncased
Dbert-base-uncased
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tokenizer from a different model family.
Using a tokenizer that does not match the model.
3fill in blank
hard

Fix 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'
Aoptimizer.step()
Bloss.step()
Cmodel.step()
Dloss.backward()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling loss.backward() twice.
Calling step() on loss or model instead of optimizer.
4fill in blank
hard

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

Fill 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'
Aword.upper()
Bcount
Cword
Dcount.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using count.upper() which is invalid for integers.
Swapping keys and values in the dictionary comprehension.