Softmax and cross-entropy calculator
Turn logits into probabilities and measure the loss for a target class. Your inputs stay on your device.
Set up your task
Starting local processing
Ready. Processing stays in this browser.
2 Your result
Your result updates in this browser. Check your input if the result looks unexpected.
How to use Softmax and cross-entropy calculator
Turn logits into probabilities and measure the loss for a target class. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.
- Check the example inputs: Logits in class order, Target position (starts at 1).
- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.
- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.
Supported inputs and limits
Use one to 64 real logits and a target class position starting at 1. The loss is reported in nats using natural logarithms.
How it works
Softmax turns real scores called logits into class probabilities. It exponentiates every score and divides by the sum. Higher logits give larger probabilities. Cross-entropy for a single target class measures the negative natural logarithm of the probability assigned to that target.
Adding the same value to all logits leaves their softmax probabilities unchanged, because it multiplies the numerator and denominator by the same factor. Subtracting the largest logit before exponentiating uses this property to avoid overflow. The loss is calculated from shifted logits so it can remain finite when displayed probabilities round to zero.
Example
Run the pre-filled example. Its first result is “Cross-entropy loss: 0.693147181 nats”.
- Logits in class order
- 1000 1000
- Target position (starts at 1)
- 1
Cross-entropy loss: 0.693147181 nats Softmax probabilities: 0.5 0.5 Target class: 1 Subtract the largest logit before taking exponentials.
Questions about Softmax and cross-entropy calculator
What does target position 1 mean?
It refers to the first logit, counting from 1. This is different from code that indexes an array starting at zero.
Does a large logit always give a probability near one?
Relative differences matter. Two equally large logits still share the probability mass equally if they are the only classes.
Add 100 to both example logits.
The probabilities stay at one half each, and the loss stays at the natural logarithm of two.
Related tools
Last updated