Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\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
Glossary › Cross-entropy

What is cross-entropy?

The loss used for predicting categories or tokens: the average of −ln⁡p-\ln p−lnp, where ppp is the probability the model gave to the correct answer.

Where it is taught

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.

What the lesson leaves you with

  • 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​.
Open the lesson

Questions

What is cross-entropy?
The loss used for predicting categories or tokens: the average of -ln p, where p is the probability the model gave to the correct answer.
Where is cross-entropy used in AI?
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.
What is the key idea to remember about cross-entropy?
The loss for one prediction is <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mi>ln</mi><mo>⁡</mo><mi>p</mi></mrow><annotation encoding="application/x-tex">-ln p</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord">−</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mop">ln</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">p</span></span></span></span>, where <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span></span></span></span> is the probability given to the true answer.
Where can I learn cross-entropy step by step?
In the lesson “Cross-entropy” in Gradient’s course on the maths behind AI, with interactive diagrams and questions.

Related terms

  • Bayes' rule
  • Entropy
  • Logit
  • Perplexity
  • Softmax
  • Temperature