TRANSFORMER INTERNALS · LESSON 139 OF 278

Logits, Softmax, and Sampling

Follow how model outputs become token probabilities and then a generated token.

What you will learn

Follow how model outputs become token probabilities and then a generated token.

In simple words

The model produces one score per candidate token. Softmax converts those logits into probabilities, and a decoding strategy chooses the next token from that distribution.

Visual explanation: Logits, Softmax, and Sampling

Trace how Logits becomes Next token through softmax + decoder.

WATCH THE IDEA

Logits, Softmax, and Sampling

Playing
LogitsThemodelpredictsnext▮Next tokenSoftmax + decoder
  1. 1Observe: Logits
  2. 2Transformation: Softmax + decoder
  3. 3Outcome: Next token

Observe: Logits. Trace how Logits becomes Next token through softmax + decoder.

The diagram highlights Logits, Softmax + decoder, Next token. Use the labels to trace the main relationship from left to right.

Real-world example: Operational AI decision

A team applies logits, softmax, and sampling to a real business workflow.

What the team decides: Generation is a repeated score → probability → token selection process.

Risk to avoid: A strong technical concept still needs measurement, safeguards, and ownership in production.

Technical explanation

The model produces one score per candidate token. Softmax converts those logits into probabilities, and a decoding strategy chooses the next token from that distribution.

Python and implementation examples

Use these examples to connect the concept to working code. Package-based examples assume the named library is installed in your own environment.

Convert logits into token probabilities

python
import torch

logits = torch.tensor([2.4, 1.2, -0.5])
probabilities = torch.softmax(logits, dim=-1)

for index, probability in enumerate(probabilities):
    print(index, round(float(probability), 4))

Softmax normalizes arbitrary token scores into a probability distribution.

Common misconception

This concept is not a guarantee of a correct outcome by itself. Its value depends on suitable evidence, careful implementation, and evaluation against the real task.

QUICK QUIZ

What are logits?

Practical application

Generation is a repeated score → probability → token selection process.

Key takeaway

Generation is a repeated score → probability → token selection process.

Next concept

Continue with Temperature, Top-k, and Top-p.

Engineering view

Generation is a repeated score → probability → token selection process.

Internals view

Follow how model outputs become token probabilities and then a generated token. The model produces one score per candidate token. Softmax converts those logits into probabilities, and a decoding strategy chooses the next token from that distribution.

Architecture view

Consider the Logits → Softmax + decoder → Next token flow, and make the system's inputs, checks, and outcomes explicit.

Was this lesson helpful?

Lesson discussion

Comments are reviewed before publication. Keep discussion focused on learning and do not post private information.

Loading discussion…

Your quiz answer and current lesson are saved on this device. Sign in to explore account-backed learning features.

Content version 1 · Last reviewed 2026-10-16