The goal of multi-class classification is to assign an input data example to one of classes, so the target label is .
Examples:
- Predicting which of digits is present in an image of a handwritten number.
- Predicting which of possible words follows an incomplete sentence .
Following the loss function recipe, we first choose a distribution over the target space . In this case, we have , so we choose the categorical distribution, which is defined on this domain. This has parameters , which determine the probability of each category:
- Constraints: Each is in the range and they sum to .
Then, we use a network with outputs to compute these parameters from input . Unfortunately, the network outputs do not necessarily obey the aforementioned constraints; thus, we pass them through a function that ensures these constraints are respected. This is usually a softmax function.
The softmax takes an arbitrary vector of length and returns a vector of the same length but where the elements are now in the range and sum to . The -th output of the softmax function is
where the exponential functions ensure positivity, and the sum in the denominator ensures that the numbers sum to one.
The predicted probability that input belongs to class is therefore
Given a training set , the negative log-likelihood loss is
where and denote the -th and -th outputs of the network, respectively. This is called multiclass cross-entropy loss.
Simplified form
Let be a one-hot encoding of the ground-truth class , so that and every other element is zero. Then the loss can be written more compactly as
where
Because the target vector is one-hot, only the correct class contributes to the loss. For the correct class, we take the negative log of its predicted probability. Every other class has a target value of zero, so its contribution to the sum is zero.
The transformed model output represents a categorical distribution over the possible classes . For a point estimate, we predict the most probable class:
dl
Multiclass cross-entropy
?
Negative log of softmax simplifies to:
where is a one-hot vector such that only the correct class contributes to the loss.
- classes, data samples
+++