liveBook · Manning

Logit

As explained in Build a Large Language Model (From Scratch)

The model’s unnormalized output scores over the vocabulary before conversion to probabilities or token selections.

Logits are the model’s unnormalized output scores for every vocabulary token. A GPT model produces them after embedding input tokens, adding positional information, processing transformer blocks, and applying final normalization and a linear output head. section 4.6

Follow the data flow from input text to generated text:

  • A tokenizer converts text into token IDs. section 5.1.1
  • The GPT model maps each input position to a vector of vocabulary-sized logits. section 4.6
  • Generation converts logits into token IDs, then decodes those IDs into text. section 5.1.1

Shape in a GPT configuration

For a batch containing two sequences of four tokens, the model returns a tensor with shape [2, 4, 50257]. The final dimension represents one logit for each token in the 50,257-token vocabulary, while the first two dimensions preserve batch and sequence positions. section 4.6

Figure 4.15 An overview of the GPT model architecture showing the flow of data through the GPT model. Starting from the bottom, tokenized text is first converted into token embeddings, which are then augmented with positional embeddings. This combined information forms a tensor that is passed through a series of transformer blocks shown in the center (each containing multi-head attention and feed forward neural network layers with dropout and layer normalization), which are stacked on top of each other and repeated 12 times.
figure

Trace how token embeddings and positional embeddings move through stacked transformer blocks before producing vocabulary-level logits. section 4.6

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Explains the output head and tensor shape, but defers the detailed conversion from logits into selected tokens.
Examples
Demonstrates logits through a [2, 4, 50257] output tensor and a token-ID-to-text generation example.
What it assumes
Assumes tokenized input and basic GPT architecture, while showing how embeddings and transformer blocks lead to vocabulary scores.
What you can do after
Evaluate and understand how GPT outputs encode next-token scores before token selection and decoding.
How it connects
Connects logits with token embeddings, positional embeddings, transformer blocks, tokenizers, token IDs, and text generation.

Also explained in

Compare how 17 books explain logit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.