liveBook · Manning

Logit

As explained in Deep Learning with PyTorch, Second Edition

Unnormalized model scores produced before applying a probability normalization such as softmax, used here as the direct input to cross-entropy loss.

A logit is a raw numerical score produced by a model before scores are normalized into probabilities by softmax. Logits may have any real value. section 13.4.2 section 7.2.4

Logits play different roles during training and prediction:

  • Feed logits directly to cross-entropy loss; the loss internally combines softmax with negative log likelihood and offers numerical-stability benefits. section 13.4.2 section 7.2.4
  • Convert logits to probabilities with softmax when class probabilities are needed for classification. section 13.4.2
  • Avoid treating logits as probabilities: they are not restricted to the range 0 to 1 and do not need to sum to 1. section 13.4.2 section 7.2.4

From scores to probabilities

For logits [1, -2, 3], exponentiation gives approximately [2.718, 0.135, 20.086]. Dividing by their sum produces softmax probabilities [0.118, 0.006, 0.876], so the third class is selected. section 13.4.2

Listing 13.6 LunaModel forward pass
def forward(self, input_batch):
  bn_output = self.tail_batchnorm(input_batch)

  block_out = self.block1(bn_output)
  block_out = self.block2(block_out)
  block_out = self.block3(block_out)
  block_out = self.block4(block_out)

  conv_flat = block_out.view(
    block_out.size(0),       #1
    -1,
  )
  linear_output = self.head_linear(conv_flat)
  return linear_output, self.head_softmax(linear_output)

A classification model returns its linear-layer output as logits and applies softmax separately to obtain probabilities. section 13.4.2

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Defines logits, demonstrates softmax conversion, and explains their loss-function role without developing deeper mathematical internals.
Examples
Demonstrates logits [1, -2, 3], softmax probabilities, and a PyTorch model returning linear scores alongside probabilities.
What you can do after
Apply it via cross-entropy loss during training and softmax during classification.
How it connects
Connects logits to softmax, cross-entropy loss, negative log likelihood, and LogSoftmax.

Also explained in

Compare how 17 books explain logit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.