0
0
NLPml~20 mins

Custom QA model fine-tuning in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom QA Fine-Tuning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of fine-tuning a QA model

Why do we fine-tune a pre-trained question answering (QA) model on a custom dataset?

ATo convert the QA model into a text generation model
BTo reduce the model size so it runs faster on any device
CTo remove all pre-trained knowledge and start training from scratch
DTo adapt the model to the specific language and style of the custom dataset for better accuracy
Attempts:
2 left
💡 Hint

Think about why a model trained on general data might not perform well on your specific questions.

Predict Output
intermediate
2:00remaining
Output of fine-tuning training loop snippet

What will be the printed output after running this training loop snippet for 1 epoch?

NLP
for epoch in range(1):
    total_loss = 0
    for batch in [[{'input_ids': [1,2], 'labels': [1,2]}], [{'input_ids': [3,4], 'labels': [3,4]}]]:
        loss = sum(batch[0]['input_ids']) * 0.1
        total_loss += loss
    print(f"Epoch {epoch+1} loss: {total_loss:.2f}")
AEpoch 1 loss: 1.0\nEpoch 2 loss: 2.0
BEpoch 1 loss: 1.00
CEpoch 1 loss: 1.5
DEpoch 1 loss: 1.4
Attempts:
2 left
💡 Hint

Calculate the sum of input_ids for each batch and multiply by 0.1, then add them.

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

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

A0.00001 (1e-5)
B0.5
C1.0
D0.1
Attempts:
2 left
💡 Hint

Think about how large learning rates affect small datasets and model stability.

Metrics
advanced
2:00remaining
Evaluating fine-tuned QA model performance

Which metric best measures the quality of answers generated by a fine-tuned extractive QA model?

ABLEU score
BMean Squared Error (MSE)
CExact Match (EM) score
DPerplexity
Attempts:
2 left
💡 Hint

Consider metrics that compare predicted answer spans to ground truth answers exactly.

🔧 Debug
expert
2:00remaining
Debugging a fine-tuning script error

Given this snippet from a fine-tuning script, what error will it raise?

NLP
from transformers import AutoModelForQuestionAnswering
model = AutoModelForQuestionAnswering.from_pretrained('bert-base-uncased')
inputs = {'input_ids': [101, 2009, 2003, 1037, 2204, 2154, 102], 'attention_mask': [1,1,1,1,1,1,1]}
outputs = model(**inputs)
print(outputs.loss)
ANo error, prints loss value
BTypeError: forward() missing 1 required positional argument: 'start_positions'
CRuntimeError: CUDA out of memory
DAttributeError: 'QuestionAnsweringModelOutput' object has no attribute 'loss'
Attempts:
2 left
💡 Hint

Check what inputs the model expects during training vs inference.