Skip to main content

Softmax & Cross-Entropy Loss

Multiclass classification activation function and categorical cross-entropy loss formulation.

Machine LearningAI & Data Science

Equation Breakdown & Typography Guide

Essential package requirements, math delimiters, and typesetting standards for this template.

01

Package Requirements

\usepackage{amsmath}

Requires amsmath for multi-character operator definitions, sum limits, and bold vector fonts.

02

Inline vs. Display Mode

Inline Math Mode
$\sigma(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}}$

Embeds within running paragraph prose without distending line height.

Display Math Mode
\[ \sigma(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}}, \quad \mathcal{L}_{\text{CE}} = -\sum_{i=1}^{K} y_i \log(\hat{y}_i) \]

Centers formula on its own line with full operator glyph sizes.

03

Common Formatting Tips & Nuances

  • •Use \mathbf{z} or \boldsymbol{z} for input logit vectors to differentiate multidimensional vectors from scalar elements z_i.
  • •Always wrap textual acronyms in subscript using \text{CE} rather than bare CE to prevent LaTeX from kerning it as the multiplication of C and E.
  • •Use \quad or \qquad to provide distinct horizontal whitespace between activation expressions and associated loss function definitions.

Softmax & Cross-Entropy Loss FAQ

How do I write the softmax function in LaTeX?▼

Use \sigma(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}}. The numerator represents exponentiated logits and the denominator normalizes across all K classes.

What packages are needed for machine learning loss equations?▼

Load \usepackage{amsmath} for \text{...} and \DeclareMathOperator, and \usepackage{amssymb} for calligraphy fonts like \mathcal{L}.

How do I typeset cross-entropy loss with softmax output?▼

Write \mathcal{L} = -\sum_{i=1}^K y_i \log(\hat{y}_i), where \hat{y}_i is the softmax output probability for class i.