TL;DR
Mixup is a training method that makes new examples by blending two real ones. It takes two inputs and their labels, mixes them with one random weight between 0 and 1, and trains the model to predict the mixed label from the mixed input. The model is thereby trained to behave smoothly between the examples it has seen, not only on the examples themselves, which reduces Overfitting.
Builds on: Data Augmentation, One-Hot Encoding, Empirical Risk Minimization, Cross-Entropy Loss, Beta Distribution · Leads to: Vicinal Risk Minimization, Label Smoothing
Where it's used
Image classification. The original 2017 paper by Hongyi Zhang and colleagues tested mixup on image datasets such as CIFAR and ImageNet. Image classifiers are the usual home of mixup, because they are trained on many pictures with a small set of labels, and they overfit easily.
Speech and audio. The same paper also reported experiments on speech recognition, where the input is a spectrogram. Mixing two spectrograms and their labels gives a training example that no recording contains, which is the point of the method.
Small labelled datasets. When a team has only a few hundred labelled examples, every example is memorised quickly. Mixup adds many blended examples without any new labelling, which is why it is a cheap first thing to try when overfitting is the main problem.
How it works
We will trace one tiny instance. There are two training examples, each with one input number and a label for two classes, A and B.
- Pick two examples. Example i has input x_i = 2 and label A, written as one-hot (1, 0). Example j has input x_j = 6 and label B, written as (0, 1). See One-Hot Encoding for why the labels are vectors. Check: the labels each add to 1.
- Draw a mixing weight. Draw a number lambda between 0 and 1 from a Beta Distribution. For this walkthrough take lambda = 0.75.
- Mix the inputs. The new input is the same weighted average of the two inputs: 0.75 × 2 + 0.25 × 6 = 1.5 + 1.5 = 3.0. Check: 3.0 lies between 2 and 6, closer to 2 because lambda is larger for example i.
- Mix the labels with the same weight. The new label is 0.75 × (1, 0) + 0.25 × (0, 1) = (0.75, 0.25). Check: the entries still add to 1, so the label is a valid probability distribution.
- Train on the blend. The model sees the input 3.0 and must output probabilities close to (0.75, 0.25). If it outputs (0.6, 0.4), the Cross-Entropy Loss against the blended label is 0.612, a number the optimizer tries to reduce.
- Repeat with new pairs. Each step draws a new pair and a new lambda, so the model sees a fresh blend every time.
flowchart LR A[Draw two examples] --> B[Draw lambda from a Beta distribution] B --> C[Mix inputs with lambda] B --> D[Mix labels with the same lambda] C --> E[Model predicts on the mixed input] D --> F[Cross-entropy against the mixed label] E --> F F --> G[Update the model]
The math
Mixup changes the training data that Empirical Risk Minimization averages its loss over, so it is best read as a rule for building new training pairs.
Given two training examples (x_i, y_i) and (x_j, y_j), where each y is a one-hot or probability vector, draw lambda from a Beta distribution with parameter alpha and form The model is trained on the pair (x-tilde, y-tilde).
Step 3 in symbols: the mixed input
The mixed input is a convex combination: a weighted average with weights that are non-negative and add to 1. The same formula works for images, where x is a vector of pixel values, so each pixel is blended separately.
Step 4 in symbols: the mixed label
The label is blended with the same weight, so that the label's total stays 1. If y_i and y_j are one-hot, the blend has two non-zero entries that add to 1.
Step 5 in symbols: the loss on the blend
Let p(x-tilde) be the model's prediction on the mixed input. The cross-entropy against the blended label is Because the target is linear in the labels, this splits into a weighted sum of the two original losses, both evaluated at the same prediction: where L_i is the cross-entropy of the prediction against y_i, and L_j is the cross-entropy against y_j. So training on the blend pushes the model toward both labels in proportion to lambda.
The mixing weight
The weight lambda is drawn from a Beta(alpha, alpha) distribution, which is symmetric around 0.5. The parameter alpha controls how often lambda is near 0 or 1, meaning the blend is nearly one of the two originals. A small alpha, such as 0.2, puts most of the mass near the ends, so most blends look almost like a pure example. A large alpha concentrates lambda near 0.5, so blends are close to equal mixtures. With alpha = 1 the distribution is uniform on the interval from 0 to 1.
Worked examples
Examples: x_i = 2 with label (1, 0), and x_j = 6 with label (0, 1). Weight lambda = 0.75.
- Mixed input: 0.75 × 2 + 0.25 × 6 = 1.5 + 1.5 = 3.0.
- Mixed label: 0.75 × (1, 0) + 0.25 × (0, 1) = (0.75, 0.25).
- The model predicts p = (0.6, 0.4) on the input 3.0.
- Cross-entropy: minus (0.75 × ln 0.6 + 0.25 × ln 0.4) = minus (0.75 × −0.5108 + 0.25 × −0.9163) = 0.3831 + 0.2291 = 0.6122.
Interpretation: the loss is smallest when the prediction matches the blended label exactly, so the model is pushed toward (0.75, 0.25) on the input 3.0.
Two classes. Example i has input (2, 0) and label (1, 0). Example j has input (0, 4) and label (0, 1). Weight lambda = 0.3.
- Mixed input: 0.3 × (2, 0) + 0.7 × (0, 4) = (0.6, 0) + (0, 2.8) = (0.6, 2.8).
- Mixed label: 0.3 × (1, 0) + 0.7 × (0, 1) = (0.3, 0.7).
- Suppose the model is unsure and predicts p = (0.5, 0.5) on the mixed input.
- Cross-entropy: minus (0.3 × ln 0.5 + 0.7 × ln 0.5) = minus ln 0.5 = ln 2 = 0.6931.
Interpretation: when the model is unsure, the loss equals ln 2, the cost of a fair coin for two classes. A model that predicted (0.3, 0.7) would have a lower loss, because its prediction matches the blend.
Two grey-scale images, each with pixel values between 0 and 1. Look at one pixel. In image A it is 1.0, and in image B it is 0.5. Image A is labelled as a "7" and image B as a "1". Take lambda = 0.2 for the pair.
- Mixed pixel: 0.2 × 1.0 + 0.8 × 0.5 = 0.2 + 0.4 = 0.6.
- Repeat for every other pixel, so the blended image is the same weighted average.
- Mixed label: 0.2 × (the "7" label) + 0.8 × (the "1" label), so the target is 0.2 on "7" and 0.8 on "1".
Interpretation: the blended image looks faintly like both digits, and the target says the same thing. This tells the model that the boundary between "7" and "1" should be a smooth ramp, not a sharp jump.
Try it: take lambda = 0.5 and two pixels, one with value 0.9 in image A and 0.1 in image B. Compute the mixed pixel. Answer: 0.5 × 0.9 + 0.5 × 0.1 = 0.45 + 0.05 = 0.5.
Common mistakes and tradeoffs
It is tempting to think mixup creates realistic new images. In fact the blends are usually unnatural, a ghost of two objects laid over each other. That is intended: the method asks the model to be sensible in the region between examples, which real data does not cover.
It is tempting to think the label stays the original label. In fact the label must be blended too. If the label were kept as the first example's label, the model would learn to ignore the second example's content.
It is tempting to think mixup is the same as Label Smoothing. In fact label smoothing changes only the target, pulling it slightly toward uniform, while mixup also changes the input. The two can be used together, but they are different.
When to use it: image and audio classification where overfitting is the problem, and where averaging two inputs still gives something meaningful, like pixels or spectrograms. It is cheap, because it needs no new labels and only a few lines of code.
When not to use it: inputs where averaging has no meaning, such as discrete tokens, unless the blend is applied to learned representations instead. It also needs care when the classes are defined by a precise threshold, because blends can cross it. Alternatives include the standard augmentations in Data Augmentation such as flips and crops, which keep each example realistic, and Label Smoothing when only the target needs softening.
History
Before 2017, data augmentation for images used transformations such as flips, crops and colour changes. Around 2000, Olivier Chapelle and colleagues described vicinal risk minimization, the idea of training on points near the data rather than only on the data itself. Mixup is a concrete way of doing that.
In 2017, Hongyi Zhang, Moustapha Cisse, Yann Dauphin and David Lopez-Paz published mixup, which appeared as arXiv 1710.09412 and was presented at ICLR in 2018. Its simplicity made it easy to adopt, and it became a standard regulariser in image training.
Recap
- Mixup blends two examples by a weight lambda, mixing their inputs and their labels with the same weight.
- The loss on the blend is a lambda-weighted sum of the two original cross-entropies, both at the mixed input's prediction.
- The weight comes from a Beta distribution, and its parameter alpha sets how close blends are to pure examples.
- The effect is a smoother model between classes, which reduces overfitting.
Read next: Vicinal Risk Minimization for the general idea behind it, and Label Smoothing for the target-only version. The original paper is at mixup: Beyond Empirical Risk Minimization.
Check yourself
QuestionRecall: in mixup, which quantities are blended with the same weight lambda?Show answer
The inputs and the labels. The mixed input is lambda times the first input plus (1 minus lambda) times the second, and the mixed label is the same weighted average of the two labels.
QuestionComputation: two examples have inputs 4 and 10 and one-hot labels (1, 0) and (0, 1). With lambda = 0.25, what are the mixed input and the mixed label?Show answer
Mixed input: 0.25 × 4 + 0.75 × 10 = 1 + 7.5 = 8.5. Mixed label: 0.25 × (1, 0) + 0.75 × (0, 1) = (0.25, 0.75).
QuestionWhy: the blended loss equals lambda times one cross-entropy plus (1 minus lambda) times another. Why does this follow from the definition of cross-entropy?Show answer
Cross-entropy is linear in the target vector. Substituting the blended label into the sum splits it into two sums, one with lambda and one with (1 minus lambda), and each is the cross-entropy of one original label, evaluated at the same prediction on the mixed input.
QuestionApplied: a team trains an image classifier with mixup and finds that the blended images look unnatural. Should they stop using mixup?Show answer
Not necessarily. Unnatural blends are expected, and the method asks the model to behave sensibly between examples. The team should check whether validation accuracy improves and whether the blends still make sense for the task. If the task depends on sharp thresholds, a smaller alpha or a different regulariser may suit better.
Sources
- Zhang, Cisse, Dauphin, Lopez-Paz, mixup: Beyond Empirical Risk Minimization, arXiv 1710.09412: https://arxiv.org/abs/1710.09412
- Data augmentation, Wikipedia: https://en.wikipedia.org/wiki/Data_augmentation