liveBook · Manning

Logit

As explained in Natural Language Processing in Action, Second Edition

A logit is an unconstrained real-valued score obtained by applying the inverse of the logistic or softmax probability transformation.

A logit is an unconstrained real-valued score that can be transformed into a probability with softmax. In GPT-2, logits score every vocabulary token at each input position before the next token is selected. section 10.2.1

When inspecting a language model, logits reveal:

  • The output tensor’s dimensions: batch, sequence position, and vocabulary size. section 10.2.1
  • The final-position scores used to compute next-token probabilities with torch.softmax. section 10.2.1
  • The highest-ranked candidate tokens, such as ' new' and ' non' for 'NLP is a'. section 10.2.1

Inspecting GPT-2 logits

Calling GPT-2 directly returns output.logits. For an input with three tokens, output.logits.shape is [1, 3, 50257]; selecting output.logits[0, -1, :] isolates the scores for the next token. section 10.2.1

>>> output = vanilla_gpt2(input_ids=input_ids)
>>> output.logits.shape
([1, 3, 50257])

Use the listing to inspect the batch, sequence, and vocabulary dimensions of a GPT-2 logit tensor. section 10.2.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains logits through tensor inspection and softmax conversion, but stops short of deriving neural-network training internals.
Examples
Uses GPT-2 outputs, a [1, 3, 50257] tensor shape, and ranked candidates for the prompt 'NLP is a'.
What it assumes
Assumes basic Python and PyTorch familiarity while demonstrating model outputs and probability conversion directly.
What you can do after
Diagnose next-token selection by extracting logits, applying softmax, and ranking vocabulary tokens.
How it connects
Connects logits with softmax, neural networks, tokenization, vocabulary, and next-token prediction.

Also explained in

Compare how 17 books explain logit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.