0
0
Prompt Engineering / GenAIml~20 mins

Hugging Face fine-tuning in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hugging Face Fine-Tuning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Model Choice
intermediate
2:00remaining
Choosing the right model for fine-tuning

You want to fine-tune a Hugging Face transformer model for a text classification task with limited labeled data. Which model is best suited to start with?

AA pretrained BERT model with a classification head
BA pretrained word2vec embedding model without a transformer
CA convolutional neural network trained on images
DA large GPT-style causal language model pretrained on general text
Attempts:
2 left
💡 Hint

Think about models designed for classification tasks and pretrained on language data.

Predict Output
intermediate
2:00remaining
Output of training metrics during fine-tuning

Consider this snippet for fine-tuning a Hugging Face model using Trainer API:

from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(output_dir='./results', num_train_epochs=1, per_device_train_batch_size=2)
trainer = Trainer(model=model, args=training_args, train_dataset=train_dataset)
train_result = trainer.train()
print(train_result.metrics)

What is the expected type and content of train_result.metrics after training?

AA list of loss values for each training step
BA string summarizing the training progress
CA dictionary containing keys like 'train_loss' and 'train_runtime' with float values
DAn integer representing the total number of training steps
Attempts:
2 left
💡 Hint

Think about what the Trainer API returns after training completes.

Hyperparameter
advanced
2:00remaining
Choosing learning rate for fine-tuning

You are fine-tuning a pretrained transformer model on a small dataset. Which learning rate is most appropriate to avoid overfitting and unstable training?

A1.0 (extremely high learning rate)
B5e-5 (a small learning rate commonly used for fine-tuning)
C0.1 (very high learning rate)
D1e-1 (which equals 0.1, very high)
Attempts:
2 left
💡 Hint

Fine-tuning usually requires smaller learning rates than training from scratch.

🔧 Debug
advanced
2:00remaining
Debugging a mismatch error during fine-tuning

You try to fine-tune a Hugging Face model but get this error:

RuntimeError: The size of tensor a (10) must match the size of tensor b (5) at non-singleton dimension 1

What is the most likely cause?

AThe model's output layer size does not match the number of classes in your dataset
BThe batch size is too large for your GPU memory
CThe learning rate is set too high causing unstable gradients
DThe tokenizer vocabulary size is smaller than the model's embedding size
Attempts:
2 left
💡 Hint

Think about tensor size mismatches related to classification output dimensions.

🧠 Conceptual
expert
3:00remaining
Understanding parameter freezing in fine-tuning

When fine-tuning a large pretrained transformer, freezing some layers can help training. Which statement best explains why freezing layers is useful?

AFreezing layers increases the model's capacity to learn new features faster
BFreezing layers automatically increases the learning rate for unfrozen layers
CFreezing layers allows the model to randomly reset weights during training
DFreezing layers reduces the number of trainable parameters, lowering memory use and preventing overfitting on small datasets
Attempts:
2 left
💡 Hint

Consider the effect of freezing on training stability and resource use.