# Softmax vs Sigmoid

> When to use softmax or sigmoid, what each one does to a model's scores, and which loss goes with which, explained for your AI interview.

**In short:** Sigmoid scores each label on its own, so several labels can be yes at once. Softmax turns all the scores into shares that add up to 1, so the labels compete and the biggest share is the pick.

AI and LLM interview question Q437, Classic ML and deep-learning basics. Beginner, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/softmax-vs-sigmoid

## Say it in 30 seconds

Sigmoid and softmax both turn raw scores into numbers between 0 and 1, but they answer different questions. Sigmoid scores each label on its own, so a ticket can get several yes answers. Softmax scores all the labels together, and the shares add up to 100%, so the labels compete and the biggest share is the pick. The first question I ask is whether one example can have more than one label. Then I pick the function and the loss that goes with it.

## Say it in 2 minutes

Sigmoid and softmax both take a model's raw scores and turn them into numbers between 0 and 1. The difference is what the numbers mean. Sigmoid works on one score at a time. Each label gets its own yes or no chance, so a bank ticket can be flagged for fraud and for billing at the same time. Softmax works on all the scores together. It gives each label a share, and the shares always add up to 1, so the labels compete and the biggest share is the pick.

The question I ask first is whether an example can belong to more than one label. If it can, I use sigmoid on each label, even when there are many labels. If it must be exactly one, such as one queue for a support ticket, I use softmax. Google's machine learning course puts the softmax rule plainly: it assumes each example is a member of exactly one class.

The loss function is the other half of the pair. For a sigmoid output I use binary cross-entropy, which PyTorch offers as one class that already includes the sigmoid. For a softmax output I use cross-entropy, which expects raw logits too. The trap is applying the function twice, once in my code and once inside the loss.

I also say the limits. Full softmax is cheap with a few classes but gets very expensive as the number of classes grows. A share shows how strongly the model leaned on a label. It says nothing certain about accuracy, so I test the model on past tickets before I quote any rate.

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

A model gives every possible label a raw score, called a logit. A logit can be any number, positive or negative, and on its own it means little to a person. Sigmoid and softmax are two ways to turn those scores into answers people can use.

Sigmoid is a curve that takes any number and squeezes it into a range from 0 to 1. Each score goes through it by itself, so each label ends up with its own chance. Softmax looks at all the scores at once and turns them into shares of one whole. The shares always add up to 100%, so a bigger share means a smaller share for someone else.

Think of a loan application form. The customer can tick home loan, car loan and credit card, or any mix of the three. That is sigmoid: a separate yes or no for each box. Now think of a branch that must send each application to exactly one underwriting queue. That is softmax: the queues share the whole, and one of them wins. In an AI app, the same choice decides whether a support ticket can carry two tags or must go to exactly one queue. The bank case later in this answer uses both.

- **Logit:** The raw score a model gives each possible label, before any scaling. It can be negative.
- **Sigmoid:** A curve that turns any number into a value from 0 to 1, one score at a time.
- **Softmax:** A function that turns all the scores into shares that add up to exactly 1.
- **Multi-class:** Exactly one label per example, chosen from three or more labels.
- **Multi-label:** Any number of labels on one example, each one on or off.

## How do the two functions shape their answers?

- **Sigmoid: Each label on its own.** Every score goes through the curve by itself, so each label gets its own answer between 0 and 1. The answers do not have to add up to anything, so several can be high at once.
- **Softmax: All labels compete.** The scores are weighed against each other, so the shares add up to exactly 1. A bigger share for one label always takes share away from another.

Google's machine learning course describes the same split, under two names. One-vs.-all means one separate yes or no model for each label, each asking 'this label or not'. The course applies a sigmoid to each output on its own, so the outputs need not sum to 1. The course calls the softmax approach one-vs.-one. That is not the same as scikit-learn's one-vs-one method, which trains one classifier for each pair of classes, so do not mix the two up.

> "For one-vs.-all, we applied the sigmoid activation function to each output node independently, which resulted in an output value between 0 and 1 for each node, but did not guarantee that these values summed to exactly 1." (Google Machine Learning Crash Course, multi-class)
>
> "For one-vs.-one, we can instead apply a function called softmax, which assigns decimal probabilities to each class in a multi-class problem such that all probabilities add up to 1.0." (Google Machine Learning Crash Course, multi-class)

*Diagram, Two ways to turn scores into answers: One model's raw scores can go two ways. Sigmoid answers each label separately, so several can be yes. Softmax makes shares of one whole, so the labels compete and the biggest share is the pick.*
1. Each label's raw score goes to sigmoid on its own.
2. All the raw scores go to softmax together.
3. Sigmoid's answers can all be yes at once.
4. Softmax hands back shares, so the labels compete.

Both functions keep the order of the scores, so the top score still ends up with the top answer. What changes is whether the answers have to compete with each other.

## How do you choose for a real bank ticket system?

Take a mid-size bank's support inbox, with about 40,000 made-up tickets a month. The model reads each ticket and must do two jobs. Routing needs exactly one queue: card disputes, loan servicing or account access. Tagging needs any mix of fraud check, billing and urgent, because one ticket can be all three at once.

> "Softmax assumes that each example is a member of exactly one class." (Google Machine Learning Crash Course, multi-class)
>
> "Some examples, however, can simultaneously be a member of multiple classes." (Google Machine Learning Crash Course, multi-class)

So routing uses softmax, and tagging uses one sigmoid per tag. Google's course says that when an example can carry several labels, you must use several logistic regressions instead of softmax. A logistic regression is a simple yes or no model, and each one here is a sigmoid on a single label. The loss is the score that says how wrong the model was, and training pushes it down. Cross-entropy is the usual loss for these outputs. PyTorch is a widely used deep-learning library, and its loss functions are covered in the loss setup section.

*Diagram, Pick the function and the loss together: Ask first whether one example can have several labels. Exactly one label means softmax, and any mix means a sigmoid for each label. Each path has its own loss, which trains it.*
1. One label per ticket: the softmax path.
2. Several labels can be on: the sigmoid path.
3. Softmax's shares train with cross-entropy.
4. Each sigmoid output trains with binary cross-entropy.

Here is the same idea in plain Python, with made-up logits for the two jobs. Lines 10 to 14 hold softmax and lines 17 and 18 hold sigmoid.

```python
# A bank's support model scores one incoming ticket. The logits are made-up numbers.
import math

QUEUES = ["card disputes", "loan servicing", "account access"]
queue_logits = [2.0, 0.5, -1.0]  # exactly one queue must get the ticket
TAGS = ["fraud check", "billing", "urgent"]
tag_logits = [1.5, 0.8, -2.0]  # a ticket can carry several tags


def softmax(scores):
    top = max(scores)  # subtract the top score first, so exp() stays small
    exps = [math.exp(s - top) for s in scores]
    total = sum(exps)
    return [e / total for e in exps]


def sigmoid(score):
    return 1 / (1 + math.exp(-score))


print("One queue (softmax, shares add up to 1):")
for name, p in zip(QUEUES, softmax(queue_logits)):
    print(f"  {name:<16}{p:.3f}")
print(f"  {'total':<16}{sum(softmax(queue_logits)):.3f}")
print("Several tags (sigmoid, each on its own):")
for name, s in zip(TAGS, tag_logits):
    print(f"  {name:<16}{sigmoid(s):.3f}")
print(f"  {'total':<16}{sum(sigmoid(s) for s in tag_logits):.3f}")
gap = tag_logits[0] - tag_logits[1]
print(f"Two options: softmax gives {softmax(tag_logits[:2])[0]:.3f}, sigmoid of the gap gives {sigmoid(gap):.3f}")
```

Output:

```text
One queue (softmax, shares add up to 1):
  card disputes   0.786
  loan servicing  0.175
  account access  0.039
  total           1.000
Several tags (sigmoid, each on its own):
  fraud check     0.818
  billing         0.690
  urgent          0.119
  total           1.627
Two options: softmax gives 0.668, sigmoid of the gap gives 0.668
```

Two things to see. The queue shares add up to 100%, but the tag scores add up to 1.627, which is fine, because each tag stands on its own. And the last line shows the two-option case: softmax over two scores gives the same number as sigmoid of their gap.

### How would you set up the loss for this model?

1. **Pick the output shape first:** Queue routing gets a softmax over the queues. Tagging gets one sigmoid per tag.
2. **Use the loss built for that output:** PyTorch's binary loss for logits includes the sigmoid in one class. Its cross-entropy loss takes raw logits and applies a log-softmax inside, which is a softmax step followed by a log.
3. **Feed raw logits, once:** Do not put a sigmoid or softmax layer in front of these losses. Applying the function twice feeds the loss the wrong numbers.
4. **Check the shapes in a test:** Run one ticket through. The queue shares should add up to 1, and each tag score should sit between 0 and 1.

PyTorch's cross-entropy page says its input is the raw logits for each class, which need not be positive or add up to 1. Its binary loss page says combining the sigmoid and the loss in one class is more numerically stable than a plain sigmoid followed by a binary loss.

> **Tip:** Asked how you would build the output layer, start with the shape of the answer. Exactly one label means softmax with cross-entropy. Several labels mean sigmoid with binary cross-entropy. In both cases, the loss takes the raw logits.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Sigmoid scores each label alone, so several can be yes at once.
- [ ] Softmax makes shares that add up to 1, so the labels compete.
- [ ] The first question: can one example have more than one label?
- [ ] Loss pairing: binary cross-entropy with sigmoid, cross-entropy with softmax.
- [ ] Both losses take raw logits, so the function is never applied twice.
- [ ] Limits: full softmax gets costly with many classes, and a share shows lean, not accuracy.

**Common traps**

- Trap: "Sigmoid is for yes or no, and softmax is for many classes." Better: Ask whether one example can have several labels. With several labels, use a sigmoid for each label, even with many classes.
- Trap: "Softmax is better because its output is a probability." Better: Both give numbers between 0 and 1. The real question is whether the labels can overlap.
- Trap: "The loss needs a sigmoid, so I add one before it." Better: The binary loss already applies the sigmoid. Pass the raw logits, or the numbers go through the function twice.

## Can you spot the mistake?

**Spot the mistake:** A teammate builds the ticket model. Which setup is wrong?

A. A softmax over the three queues, with cross-entropy as the loss.
B. One sigmoid per tag, with binary cross-entropy as the loss.
C. A sigmoid layer in front of a binary loss that already includes one.
D. A softmax over the queues, so the queue shares add up to 100%.

**Answer:** C. The binary loss already applies the sigmoid, so a second one in front feeds it the wrong numbers. Pass the raw logits instead.

**Quick check:** A ticket can be both a fraud check and urgent. Which output fits?

A. Softmax, so the tags share one whole
B. One sigmoid for each tag, so each can be on
C. Raise the learning rate
D. Keep only the top queue

**Answer:** B. Several tags can be on at once, so each tag needs its own yes or no score. Softmax would force the tags to share one whole.

## Can you answer these from memory?

**Flash cards**

- **Sigmoid or softmax: which lets several labels be on?** Sigmoid. Each label gets its own score between 0 and 1.
- **What do softmax shares add up to?** Exactly 1, or 100%, across all the labels.
- **Which loss goes with sigmoid?** Binary cross-entropy. PyTorch's version includes the sigmoid.
- **Which loss goes with softmax?** Cross-entropy, given raw logits. It applies a log-softmax inside.
- **What is the first question to ask?** Can one example have more than one label?
- **What goes wrong with a second sigmoid?** The binary loss already applies one, so the numbers go through it twice.

## Likely follow-up questions

- Q022 What are logits, and what does softmax do? https://designervenkat.online/interview/ai/what-are-logits-and-what-does-softmax-do
- Q419 MSE vs cross-entropy loss? https://designervenkat.online/interview/ai/mse-vs-cross-entropy-loss
- Q432 What is logistic regression? https://designervenkat.online/interview/ai/what-is-logistic-regression
- Q278 How do you evaluate an LLM classifier (confusion matrix)? https://designervenkat.online/interview/ai/how-do-you-evaluate-an-llm-classifier-confusion-matrix

## Learn it in depth

- [Logistic regression: yes or no](https://designervenkat.online/learn/machine-learning/logistic-regression)
- [Loss functions: measuring a mistake](https://designervenkat.online/learn/machine-learning/loss-functions)
