Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
  • Derivatives0/5
  • Probability0/6
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
P(x)P(x)P(x)Maths, module 13: Probability, lesson 4 of 6

Cross-entropy

How do you score a prediction that is a whole distribution? Look at the probability it gave to what actually happened, and take minus its logarithm.

8 minute readOne thing to try6 questionsFree

Read the whole lesson free

Make a free account to read on, try the interactive parts, answer the 6 practice questions and keep your progress.

Create a free accountLog in

What this lesson covers

  • The loss for one prediction is −ln⁡p-\ln p−lnp, where ppp is the probability given to the true answer.
  • Cross-entropy is the average of that over the data. Guessing uniformly over VVV options costs ln⁡V\ln VlnV.
  • With softmax, the gradient at the logits is simply pi−yip_i - y_ipi​−yi​.

More in Probability

  1. 1Probability and distributions
  2. 2Conditional probability and the next token
  3. 3Softmax and temperature
  4. 4Cross-entropy
  5. 5Bayes' rule
  6. 6Entropy and information