What if your model could learn to be confident but still humble enough to avoid big mistakes?
Why Label smoothing in PyTorch? - Purpose & Use Cases
Imagine you are teaching a child to recognize animals. You always say, "This is a cat," and never mention it might look a bit like a fox or a dog. The child learns to be 100% sure about cats, but struggles when the animal looks slightly different.
When training a model without label smoothing, it tries to be absolutely sure about the correct answer. This can make the model too confident and less flexible, causing it to make big mistakes on new or slightly different data. It's like being stubborn and refusing to consider other possibilities.
Label smoothing gently tells the model, "Be confident, but not too confident." Instead of saying the correct answer is 100% right, it says it's mostly right but leaves a little room for uncertainty. This helps the model learn better and avoid overconfidence, making it smarter and more adaptable.
target = torch.tensor([1, 0, 0], dtype=torch.float) # one-hot encoding
target = torch.tensor([0.9, 0.05, 0.05], dtype=torch.float) # label smoothing applied
Label smoothing enables models to generalize better and avoid overfitting by preventing them from becoming too confident in their predictions.
In image recognition, label smoothing helps a model correctly identify animals even if the photo is blurry or the animal is partially hidden, by not forcing the model to be 100% sure about one label.
Label smoothing reduces overconfidence in model predictions.
It improves model flexibility and generalization.
It helps models perform better on new, unseen data.