Image Classification

one-hot label encoding

One-hot encoding is the standard way to represent a categorical class label as a vector for training. For a problem with C classes, the label of class j becomes a length-C vector that is 1 in position j and 0 everywhere else, so 'class 2 of 4' becomes [0, 1, 0, 0]. This turns an arbitrary, unordered category into a numeric target that a network's output layer and the cross-entropy loss can consume directly.

The reason it is one-hot rather than a single integer is to avoid implying a false ordering or distance: encoding classes as the numbers 1, 2, 3 would suggest class 3 is greater than or farther from class 1, which is meaningless for categories like cat, dog, and car. The one-hot vector treats all classes as equidistant and independent, which matches the semantics of nominal categories. Paired with softmax outputs, minimising cross-entropy against a one-hot target is exactly maximum-likelihood estimation of the correct class.

One-hot targets are the baseline that several other terms modify: label smoothing softens the 1 and the 0s toward a small uniform floor, mixup and CutMix interpolate between two one-hot vectors, and hierarchical or multi-label settings replace the single 1 with a structured or multi-hot target. Understanding the plain one-hot target is therefore the foundation for understanding those refinements.

In code, prefer your framework's integer-index cross-entropy, which builds the one-hot internally, over manually materialising one-hot matrices for large C; it saves memory and avoids subtle bugs, but conceptually the target is still the one-hot vector.

Also called
one-hot encoding