التعلم الآلي والذكاء الاصطناعي

دوال الخسارة والتدرجات وargmax وتباعد KL وترميز الشبكات العصبية.

Gradient symbol in LaTeX and other machine learning notation

The gradient symbol in LaTeX is \nabla, which prints ∇ and needs no package: write \nabla f for the gradient of f, or \nabla_\theta \mathcal{L} for the gradient of a loss with respect to the parameters. Partial derivatives use \partial, predictions are \hat{y}, expectation is \mathbb{E} and argmax is \operatorname*{arg\,max}. The table lists the commands people use most when writing a gradient in LaTeX, with the package each one needs; the full list of machine learning symbols follows below.

SymbolCommandUsePackageCopy
∇\nabla
\nablaGradient symbol (nabla, del)built in
∇θL\nabla_\theta \mathcal{L}
\nabla_\theta \mathcal{L}Gradient of the loss with respect to θbuilt in
∂\partial
\partialPartial derivativebuilt in
∂L∂w\frac{\partial \mathcal{L}}{\partial w}
\frac{\partial \mathcal{L}}{\partial w}Partial derivative of the lossbuilt in
L\mathcal{L}
\mathcal{L}Loss functionbuilt in
θ\theta
\thetaModel parametersbuilt in
y^\hat{y}
\hat{y}Prediction, estimatebuilt in
E\mathbb{E}
\mathbb{E}Expectationamssymb
arg max⁡θ\operatorname*{arg\,max}_\theta
\operatorname*{arg\,max}_\thetaArgmax with a limit underneathamsmath
arg min⁡θ\operatorname*{arg\,min}_\theta
\operatorname*{arg\,min}_\thetaArgmin with a limit underneathamsmath
∥w∥2\|w\|_2
\|w\|_2L2 norm of the weightsbuilt in
⊙\odot
\odotHadamard (element-wise) productbuilt in

Load \usepackage{amsmath, amssymb} for \mathbb and \operatorname*. Vectors and matrices are usually bold, written \mathbf{x} or \boldsymbol{\theta} (amsmath), and the transpose is X^\top. For calculus notation in general see our guide to math functions in LaTeX and the calculus symbols page.

Frequently asked questions

How do I write the gradient symbol in LaTeX?
The gradient symbol ∇ is \nabla, built into LaTeX and used in math mode: $\nabla f$. Put the variable you differentiate with respect to in a subscript, as in \nabla_\theta \mathcal{L}(\theta), and write the Laplacian as \nabla^2 f. No package is needed.
How do I write a partial derivative in LaTeX?
Use \partial: \frac{\partial f}{\partial x} for a first derivative and \frac{\partial^2 f}{\partial x^2} for a second derivative. A single component of the gradient is written the same way, for example \frac{\partial \mathcal{L}}{\partial w_i}.
How do I write argmax and argmin in LaTeX?
With amsmath, write \operatorname*{arg\,max}_\theta f(\theta); the star puts the subscript underneath in display math. For repeated use declare it once in the preamble with \DeclareMathOperator*{\argmax}{arg\,max} and then write \argmax_\theta. The shortcut \arg\max_\theta also works, but the subscript then sits under max alone rather than under the whole arg max.
How do I write the expectation and the loss function in LaTeX?
Expectation is blackboard bold \mathbb{E}, which needs \usepackage{amssymb}, as in \mathbb{E}_{x \sim p}[f(x)]. The loss function is usually a calligraphic L, \mathcal{L}, which is built in.
L\mathcal{L}

Loss Function

\mathcal{L}
E\mathbb{E}

Expectation

\mathbb{E}
E[X]\mathbb{E}[X]

Expectation of X

\mathbb{E}[X]
DKL(P∥Q)D_{\text{KL}}(P \| Q)

KL Divergence

D_{\text{KL}}(P \| Q)
KL(P∥Q)\text{KL}(P \| Q)

KL Divergence Alt

\text{KL}(P \| Q)
arg⁡max⁡\arg\max

Argmax

\arg\max
arg⁡min⁡\arg\min

Argmin

\arg\min
arg⁡max⁡θ\arg\max_{\theta}

Argmax Subscript

\arg\max_{\theta}
arg⁡min⁡θ\arg\min_{\theta}

Argmin Subscript

\arg\min_{\theta}
⊗\otimes
⊙\odot
softmax\text{softmax}

Softmax

\text{softmax}
σ\sigma

Sigmoid

\sigma
ReLU\text{ReLU}

ReLU

\text{ReLU}
∇\nabla

Gradient

\nabla
∇θL\nabla_{\theta} \mathcal{L}

Gradient of L

\nabla_{\theta} \mathcal{L}
∂L∂θ\frac{\partial \mathcal{L}}{\partial \theta}

Partial Derivative

\frac{\partial \mathcal{L}}{\partial \theta}
η\eta
θ\theta
θ∗\theta^*

Theta Star

\theta^*
W\mathbf{W}

Weight Matrix

\mathbf{W}
b\mathbf{b}

Bias Vector

\mathbf{b}
H(p,q)H(p, q)
H(X)H(X)
I(X;Y)I(X; Y)
log⁡p(x∣θ)\log p(x | \theta)

Log Likelihood

\log p(x | \theta)
p(x)p(x)
p(y∣x)p(y | x)
∑c=1C\sum_{c=1}^{C}

Sum Over Classes

\sum_{c=1}^{C}
∏i=1N\prod_{i=1}^{N}

Product Over Samples

\prod_{i=1}^{N}
∥θ∥1\| \theta \|_1

L1 Norm

\| \theta \|_1
∥θ∥2\| \theta \|_2

L2 Norm

\| \theta \|_2
∥W∥F\| \mathbf{W} \|_F

Frobenius Norm

\| \mathbf{W} \|_F