Softmax & Cross-Entropy Loss
Multiclass classification activation function and categorical cross-entropy loss formulation.
Equation Breakdown & Typography Guide
Essential package requirements, math delimiters, and typesetting standards for this template.
Package Requirements
\usepackage{amsmath}Requires amsmath for multi-character operator definitions, sum limits, and bold vector fonts.
Inline vs. Display 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.
\[ \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.
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.