Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN014 · Training method

Label smoothing

Replaces hard classification targets with a mixture of the target label and a reference distribution.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.cnn, learn.dann, learn.deep_ensemble, learn.ft_transformer, learn.gnn, learn.neural_cde, learn.set_model, learn.tabm, learn.tabnet, learn.torch_mlp. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Replaces hard classification targets with a mixture of the target label and a reference distribution.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

The network is unchanged; only the cross-entropy target distribution changes.

Assumptions

Choose the smoothing distribution and ignored-label handling explicitly. Uniform smoothing may be inappropriate when classes have structured relations or highly skewed prevalence.

Formula / computational definition

qc=(1−ϵ)1{c=y}+ϵ/C,L=−∑cqclog⁡pc.q_c=(1-\epsilon)\mathbf1\{c=y\}+\epsilon/C,\qquad L=-\sum_c q_c\log p_c.

Parameters and notation

Learned: network weights. Hyperparameters: epsilon, reference distribution, class count, masking. Some implementations distribute smoothing mass over non-target classes instead, giving a different formula.

Fitting, fine-tuning, and adaptation

Tune epsilon on validation accuracy and calibration; for language models exclude ignored/padding tokens correctly. Changing targets can affect distillation and confidence interpretation.

How to use and calibrate

Inspect confidence distributions and validation log loss. Example: reduce overly sharp class predictions during image or speech classification.

Example application

reduce overly sharp class predictions during image or speech classification.

Interpretation / pitfalls

Watch out

Label smoothing is not a calibrated uncertainty model. It can suppress informative probability differences; applying it indiscriminately to noisy labels does not solve label corruption.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
C=3; eps=.1; y=1; q=np.full(C,eps/C); q[y]+=1-eps; p=np.array([.1,.8,.1])
print(q,-np.sum(q*np.log(p)))
R

Component demo, not a trained model — numerical mechanism demonstration.

C <- 3; eps <- .1; y <- 2; q <- rep(eps/C,C); q[y] <- q[y]+1-eps; p <- c(.1,.8,.1)
print(q); print(-sum(q*log(p)))

Sources

From the CodeSplash reference, entry TRN014.