4
$\begingroup$

I just realized I have not given this issue much thought. In a classification task, there is an argmax happening after the softmax to get the most likely class. So how does backpropagation go through that operation?

$\endgroup$
1
  • 2
    $\begingroup$ Indeed, as Tim mentioned, typically we would use a softmax rather than an argmax. Though I feel as though I should mention that it is possible to compute a subgradient of the "hard"-maximum function, which acts like the identity function wrt the maximizing input, and the zero function for other inputs (almost everywhere). $\endgroup$ Commented Feb 25, 2023 at 18:04

1 Answer 1

14
$\begingroup$

It does not. Almost always the model is trained to predict real-valued score (e.g. probability) by minimizing some smooth loss function. While training such a model never makes hard classifications, so never use argmax. The final layer of most of the classification neural networks is softmax rather than hardmax. You can make the hard classification only after the training, by using the score returned by the model.

See also the related thread Why is accuracy not the best measure for assessing classification models? that discusses problems with accuracy as a metric, but many of the points apply as well to other non-smooth metrics. Training the model to minimize such metric would actually be harder.

$\endgroup$
5
  • $\begingroup$ When computing categorical cross-entropy loss, the negative classes are ignored. Isn't that in some sense doing argmax? $\endgroup$
    – Sam
    Commented Feb 25, 2023 at 9:08
  • $\begingroup$ @Sam no it isn't. $\endgroup$
    – Tim
    Commented Feb 25, 2023 at 10:36
  • 1
    $\begingroup$ @Sam Where is the argmax in that? It literally does not consider the magnitude of the outputs $\endgroup$
    – Firebug
    Commented Feb 25, 2023 at 13:41
  • $\begingroup$ ok I get it. It only considers the magnitude of the probability of the relevant class, not which class. But it does care about the 'magnitude of the outputs' $\endgroup$
    – Sam
    Commented Feb 25, 2023 at 14:40
  • 2
    $\begingroup$ @Sam No, cross-entropy very much cares about which particular output should be maximized! The negative classes do get involved through softmax, where the score ("logit") of the target class has to compete with the rest, which is expressed in the denominator. Fortunately, the Jacobian turns out to be pretty nice :-) $\endgroup$
    – dedObed
    Commented Feb 25, 2023 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.