Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is label smoothing in machine learning?
Label smoothing is a technique that softens the target labels by assigning a small probability to all classes instead of a hard 0 or 1. This helps the model avoid becoming too confident and improves generalization.
Click to reveal answer
beginner
Why do we use label smoothing during training?
We use label smoothing to prevent the model from becoming overconfident on training data. It reduces overfitting and helps the model perform better on new, unseen data.
Click to reveal answer
intermediate
How does label smoothing change the target labels?
Instead of using 1 for the correct class and 0 for others, label smoothing assigns a value like 0.9 to the correct class and distributes 0.1 among the other classes evenly.
Click to reveal answer
intermediate
Show a simple PyTorch code snippet to apply label smoothing with CrossEntropyLoss.
You can use PyTorch's built-in label smoothing by setting the 'label_smoothing' parameter in CrossEntropyLoss, like this:<br><pre>import torch
loss_fn = torch.nn.CrossEntropyLoss(label_smoothing=0.1)</pre>
Click to reveal answer
advanced
What effect does label smoothing have on model confidence and calibration?
Label smoothing reduces the model's confidence in its predictions, which often leads to better calibrated probabilities and less overconfident wrong predictions.
Click to reveal answer
What does label smoothing do to the target labels?
AAssigns a small positive value to all classes instead of hard 0 or 1
BIncreases the learning rate during training
CRemoves noisy data from the dataset
DChanges the model architecture
✗ Incorrect
Label smoothing assigns a small positive value to all classes, softening the target labels.
Which PyTorch loss function parameter enables label smoothing?
Asmooth_factor
Blabel_smoothing
Csmooth_labels
Dsmoothing_rate
✗ Incorrect
The 'label_smoothing' parameter in CrossEntropyLoss enables label smoothing.
What is a common benefit of using label smoothing?
ALarger model size
BFaster training speed
CBetter model calibration and less overfitting
DMore complex model architecture
✗ Incorrect
Label smoothing helps the model generalize better by reducing overfitting and improving calibration.
If label smoothing is set to 0.1, what label value might the correct class get?
A0.0
B1.0
C0.1
D0.9
✗ Incorrect
With 0.1 smoothing, the correct class label is reduced from 1.0 to 0.9.
Label smoothing is mainly used to:
APrevent the model from becoming too confident
BMake the model more confident
CIncrease the number of classes
DMake labels harder for the model
✗ Incorrect
Label smoothing prevents the model from becoming too confident by softening the labels.
Explain what label smoothing is and why it helps improve model training.
Think about how changing the target labels affects model confidence.
You got /4 concepts.
Describe how to implement label smoothing in PyTorch using CrossEntropyLoss.
Check PyTorch documentation for CrossEntropyLoss parameters.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of label smoothing in PyTorch?
easy
A. To increase the learning rate automatically
B. To make the model less confident and improve generalization
C. To add noise to the input data
D. To reduce the size of the training dataset
Solution
Step 1: Understand label smoothing concept
Label smoothing softens the target labels, making the model less confident about the exact class.
Step 2: Connect to model behavior
This helps the model generalize better by not being too sure, reducing overfitting.
Final Answer:
To make the model less confident and improve generalization -> Option B
Quick Check:
Label smoothing = less confident model [OK]
Hint: Label smoothing reduces confidence to improve generalization [OK]
Common Mistakes:
Thinking it changes learning rate
Confusing with data augmentation
Assuming it reduces dataset size
2. Which of the following is the correct way to apply label smoothing in PyTorch's CrossEntropyLoss?
easy
A. loss_fn = torch.nn.CrossEntropyLoss(label_smoothing=0.1)
B. loss_fn = torch.nn.CrossEntropyLoss(smooth_labels=0.1)
C. loss_fn = torch.nn.CrossEntropyLoss(smoothing=0.1)
D. loss_fn = torch.nn.CrossEntropyLoss(label_smooth=0.1)
D. CrossEntropyLoss does not support label smoothing
Solution
Step 1: Check target tensor shape
CrossEntropyLoss expects target as 1D tensor of class indices, but target is 2D here.
Step 2: Confirm label smoothing usage
Label smoothing parameter is correctly used as float; logits shape is correct as batch size 1 with 3 classes.
Final Answer:
Target tensor shape should be 1D, not 2D -> Option A
Quick Check:
Target shape must be 1D for CrossEntropyLoss [OK]
Hint: Target tensor must be 1D class indices [OK]
Common Mistakes:
Passing target as 2D tensor
Using integer for label_smoothing
Misunderstanding CrossEntropyLoss support
5. You want to train a classification model with 5 classes using label smoothing of 0.1. Which of the following target label vectors correctly applies label smoothing manually for class 2 (index 1)?
hard
A. [0.2, 0.2, 0.2, 0.2, 0.2]
B. [0, 1, 0, 0, 0]
C. [0.025, 0.9, 0.025, 0.025, 0.025]
D. [0.1, 0.1, 0.1, 0.1, 0.6]
Solution
Step 1: Recall label smoothing formula
With smoothing ε=0.1 and K=5 classes, true class gets 1 - ε = 0.9, each of the other K-1=4 classes gets ε / (K-1) = 0.1 / 4 = 0.025.
Step 2: Construct target for true class index 1
The vector is [0.025, 0.9, 0.025, 0.025, 0.025].
Final Answer:
[0.025, 0.9, 0.025, 0.025, 0.025] -> Option C
Quick Check:
Smoothed target sums to 1 with 0.1 smoothing [OK]
Hint: Distribute smoothing evenly, reduce true class by smoothing [OK]