# What Are Logits and What Does Softmax Do?

> What logits are, how softmax turns them into probabilities, and how a language model picks its next token, explained for your AI interview.

**In short:** Logits are the raw scores a model gives each possible output, before anything is scaled. Softmax turns those scores into positive numbers that add up to 1, so the top score gets the biggest share.

AI and LLM interview question Q022, LLM fundamentals. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-are-logits-and-what-does-softmax-do

## Say it in 30 seconds

Logits are the raw scores a model gives each possible answer. They can be any number, positive or negative, so they are hard to read on their own. Softmax turns them into probabilities: each one becomes a positive share, and all the shares add up to one. A language model does this for every token it knows, then picks the next token from those shares. Here is a small example with three decisions.

## Say it in 2 minutes

When a model answers, it does not start with a word. It first gives a raw score to every option it could pick. For a language model, the options are the tokens in its vocabulary, the pieces of text it can write. Those raw scores are called logits. They can be any number, so they are hard to compare or to show to a person.

Softmax is the step that makes them readable. It raises the number e to the power of each score, which makes every value positive and widens the gap between big and small scores. Then it divides each value by the total, so the results sit between 0 and 1 and add up to 1. The highest logit always gets the biggest share, and softmax never changes the order.

Take a claims triage model that scores pay out at 2.1, send to an officer at 0.4 and reject at minus 1.3. Softmax gives about 82% to pay out, 15% to the officer and 3% to reject. The model then takes the top share, or draws one at random by its share. The shares show how strongly the model leaned, but they don't prove it is right.

So in an interview I'd say this: the model writes a logit for each option, softmax turns the logits into probabilities that add up to 1, and the next token is picked by the top share or by sampling. The catch is that softmax assumes one right answer, so a case with several true labels needs a separate yes or no score for each label.

## What are logits and softmax, in plain words?

A language model writes one piece of text at a time, called a token. At each step it has to score every token it knows. Each score is a logit: a raw number that can be big, small or negative, and that means little to a person until it is changed.

Softmax is the change. It takes the list of logits and turns it into probabilities, one per token, so that they add up to 1 (or 100%). A probability of 0.7 is a 70% share of the whole, which a team can read at a glance.

Think of a hospital triage board. A nurse gives each patient a raw urgency score, but the board needs a clear order and a share of attention for each case. Raw scores do the first job badly. Shares of the whole do the second well.

Now the AI version. A claims triage model scores the three decisions it could take on an incoming motor claim. Those three raw scores are its logits, and softmax turns them into shares the queue can act on.

- **Logit:** A raw score a model gives each possible output. It can be any number, positive or negative.
- **Softmax:** A function that turns a list of logits into probabilities that add up to 1.
- **Token:** A piece of text the model reads and writes, often part of a word.
- **Vocabulary:** The full list of tokens a language model can output at each step.
- **Probability distribution:** The full set of shares across all the options, adding up to 100%.

> "The vector of raw (non-normalized) predictions that a classification model generates, which is ordinarily then passed to a normalization function." (Google Machine Learning Glossary, logits)
>
> "A function that determines probabilities for each possible class in a multi-class classification model. The probabilities add up to exactly 1.0." (Google Machine Learning Glossary, softmax)

## How does softmax turn logits into probabilities?

1. **Make every score positive:** Raise the number e (about 2.718, a fixed maths constant) to the power of each logit. Big scores become much bigger numbers, and negative scores become small positive ones.
2. **Add them up:** Add all those positive numbers into one total.
3. **Share the total:** Divide each number by the total. Each result sits between 0 and 1, and all of them add up to exactly 1.

The PyTorch documentation describes the function the same way: it re-scales the values "so that the elements lie in the range [0, 1] and sum to 1". The example below is made up, and the code runs for real.

*Diagram, From raw scores to shares: A claim note goes into a made-up claims model, which writes one raw score per decision. Softmax turns the three scores into shares of 100%. The top share is the one the queue acts on.*
1. The claim notes go into the model as plain text.
2. The model writes one raw score for each decision it could take.
3. Softmax turns the three scores into shares that add up to 100%.
4. The biggest share is the one the queue acts on.

Here it is in plain Python, with the three made-up logits. Lines 9 to 13 hold the softmax itself. The temperature in the second run is a setting that divides the logits before softmax, and a lower value sharpens the shares.

```python
# A claims triage model scores three decisions. Its raw scores are logits.
import math

LABELS = ["pay out", "send to a claims officer", "reject"]
logits = [2.1, 0.4, -1.3]


def softmax(scores, temperature=1.0):
    scaled = [s / temperature for s in scores]
    top = max(scaled)  # subtract the top score first, so exp() never gets huge
    exps = [math.exp(s - top) for s in scaled]
    total = sum(exps)
    return [e / total for e in exps]


def show(probs):
    for label, p in zip(LABELS, probs):
        print(f"{label:<26}{p:7.1%}")
    print(f"{'total':<26}{sum(probs):7.1%}")


print("Raw logits:", logits)
print("Softmax, temperature 1.0:")
show(softmax(logits))
print("Softmax, temperature 0.5 (sharper):")
show(softmax(logits, temperature=0.5))
```

Output:

```text
Raw logits: [2.1, 0.4, -1.3]
Softmax, temperature 1.0:
pay out                     82.2%
send to a claims officer    15.0%
reject                       2.7%
total                      100.0%
Softmax, temperature 0.5 (sharper):
pay out                     96.7%
send to a claims officer     3.2%
reject                       0.1%
total                      100.0%
```

Two things to notice. The shares always add up to 100%, even though the raw scores don't. And the second run uses a temperature, a setting that divides the logits before softmax. A lower temperature sharpens the picture, so pay out moves from 82% to 97%.

The order never changes. Softmax keeps the scores in the same order, so the biggest logit always gets the biggest share. Softmax only changes the numbers you show. The option the model prefers stays the same.

## What does a language model do with its logits?

At each step a language model gives a logit to every token in its vocabulary. Softmax turns that list into a probability distribution, and the model then picks one token from it. The picked token joins the text, and the whole process runs again for the next token.

- **Greedy: Always the top share.** The model takes the token with the biggest share every time. It is simple and steady, and it is the default decoding strategy in Hugging Face's open-source library, but it can repeat itself.
- **Sampling: A draw by share.** The model draws one token at random, weighted by its share. A token with a 15% share wins about 15 draws in 100, so answers vary from run to run.

*Diagram, How a language model picks the next token: The text so far goes into a language model, which scores every token. Softmax makes the shares, then one rule takes the top share or draws by chance. The chosen token joins the text, and the loop runs again.*
1. The text so far goes into the model.
2. The model writes a score for every token it knows.
3. The shares go to the greedy rule, which takes the top one.
4. The same shares can go to sampling, which draws one by chance.
5. The greedy pick becomes the next token.
6. The sampled pick becomes the next token.

Some APIs let you see these numbers. OpenAI's chat API can return the log probability (the log of its chance) of an output token, but only when that token is one of the 20 most likely ones. Each strategy is only a rule for reading the same shares.

## Where does softmax fall short?

> "Softmax assumes that each example is a member of exactly one class." (Google Machine Learning Crash Course, multi-class)

- **One right answer only:** A claim that is both a flood claim and a fraud review needs a separate yes or no score for each label. Google's course says that case needs several yes or no models instead.
- **Shares are the model's own score:** A 90% share shows how strongly the model leaned. It says nothing certain about accuracy, so measure accuracy on past cases before you quote a rate.
- **Cost grows with the number of options:** Scoring every token in a large vocabulary is heavy work at each step, and Google's course notes that full softmax gets expensive as the number of classes climbs.

> **Tip:** Asked what softmax does, name the three steps first: raise to the power, add up, divide. Then say what the shares are for, and where they can mislead.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Logits are raw scores, before any scaling.
- [ ] Softmax makes positive numbers, adds them, then divides, so the shares add up to 1.
- [ ] It keeps the order: the top logit gets the top share.
- [ ] A language model scores every token, then picks one by the greedy rule or by sampling.
- [ ] Limits: one right answer per example, and cost grows with many options.
- [ ] Shares show how strongly a model leaned. Measure accuracy on past cases before you quote a rate.

**Common traps**

- Trap: "Logits are the probabilities." Better: Logits are raw scores. Softmax turns them into probabilities.
- Trap: "Softmax makes the model more accurate." Better: It only reshapes the scores into shares. The order stays the same, so accuracy depends on the model itself.
- Trap: "A 95% share means it's right 95% of the time." Better: A share shows how strongly the model leaned. Measure accuracy on real past cases.

## Can you spot the mistake?

**Spot the mistake:** A teammate explains a bank's fraud model to the risk committee. Which sentence is wrong?

A. The model writes a logit for each option before softmax runs.
B. Softmax turns the logits into shares that add up to 1.
C. A 90% share means the model is right nine times in ten.
D. Softmax keeps the order, so the top logit gets the top share.

**Answer:** C. A share only shows how strongly the model leaned on that option. Measure accuracy on past cases before you quote a rate.

**Quick check:** A claims model may tag one claim as both flood and fraud. Which change fits?

A. Keep softmax and take the top label
B. Use a separate yes or no score for each label
C. Raise the temperature
D. Add more tokens to the prompt

**Answer:** B. Softmax assumes one right class per example, so several true labels need a separate yes or no score for each label.

## Can you answer these from memory?

**Flash cards**

- **What is a logit?** A raw score a model gives each possible output, before any scaling.
- **What does softmax do?** Turns the logits into positive shares that add up to exactly 1.
- **How is softmax computed?** Raise e to each score, add them up, then divide each one by the total.
- **Does softmax change the ranking?** No. The highest logit always keeps the biggest share.
- **Greedy vs sampling?** Greedy takes the top share. Sampling draws one token by its share.
- **Where does softmax fall short?** It assumes one right class per example, and costs grow with many options.

## Likely follow-up questions

- Q002 What does "predict the next token" mean? https://designervenkat.online/interview/ai/what-does-predict-the-next-token-mean
- Q038 What are log-probabilities, and how can you use them? (full answer coming)
- Q039 What are frequency and presence penalties? (full answer coming)
- Q023 What is a hallucination, and why does it happen? https://designervenkat.online/interview/ai/what-is-an-ai-hallucination
- Q041 What is a transformer? https://designervenkat.online/interview/ai/what-is-a-transformer
- Q029 What do stop sequences and max tokens do? https://designervenkat.online/interview/ai/what-do-stop-sequences-and-max-tokens-do

## Learn it in depth

- [Sampling Parameters](https://designervenkat.online/learn/ai-engineering/sampling-parameters)
