Automatic Differentiation, Gradient Optimization, Regularization, and Maximum Likelihood Classification

Automatic Differentiation and Computational Graphs

All numerical evaluations executed within computational learning systems decompose into sequential elementary operations, such as addition, multiplication, exponentiation, and nonlinear activations. Because the analytical derivatives of each elementary operation are known, automatic differentiation (AD) systematically computes the exact total derivatives of arbitrary composite functions by chaining local gradients. Unlike finite-difference approximations, automatic differentiation introduces zero numerical truncation errors, and unlike symbolic differentiation, it evaluates derivatives directly without generating unwieldy, algebraically expanded symbolic expressions.

Mathematical models in automatic differentiation are formalized as directed acyclic computational graphs. Consider the nonlinear multivariable function y = F(x_1, x_2) = \rexp(x_1 x_2) + \rlog(x_2), defined on the domain x2>0x_2 > 0. This evaluation breaks down into an ordered series of intermediate variables: v1=x1v_1 = x_1, v2=x2v_2 = x_2, v3=v1v2v_3 = v_1 v_2, v_4 = \rlog(v_2), v_5 = \rexp(v_3), v6=v5+v4v_6 = v_5 + v_4, and finally y=v6y = v_6. Within the computational graph, each node stores its evaluated intermediate scalar value, and directed edges indicate variable dependencies.

Computation graph for evaluating y = exp(x1 x2) + log(x2)

Forward-mode automatic differentiation propagates tangent derivatives forward from the primary input nodes toward the terminal output node simultaneously with the evaluation of intermediate functions. To evaluate the partial derivative of the scalar output yy with respect to an input x1x_1, each node defines a forward derivative \rdot{v}_i = \frac{\rpartial v_i}{\rpartial x_1}. Seeding the input nodes with respect to x1x_1 gives \rdot{v}_1 = 1 and \rdot{v}_2 = 0. Applying local chain rules sequentially through the graph yields:

v_3 = v_1 v_2 \implies \rdot{v}_3 = v_2 \rdot{v}_1 + v_1 \rdot{v}_2 = x_2(1) + x_1(0) = x_2

v_4 = \rlog(v_2) \implies \rdot{v}_4 = \frac{\rdot{v}_2}{v_2} = \frac{0}{x_2} = 0

v_5 = \rexp(v_3) \implies \rdot{v}_5 = \rexp(v_3) \rdot{v}_3 = x_2 \rexp(x_1 x_2)

v_6 = v_5 + v_4 \implies \rdot{v}_6 = \rdot{v}_5 + \rdot{v}_4 = x_2 \rexp(x_1 x_2)

This yields the derivative \frac{\rpartial y}{\rpartial x_1} = x_2 \rexp(x_1 x_2). Differentiating with respect to x2x_2 requires setting seeds \rdot{v}_1 = 0 and \rdot{v}_2 = 1, which results in \frac{\rpartial y}{\rpartial x_2} = x_1 \rexp(x_1 x_2) + \frac{1}{x_2}. Because each forward sweep isolates one directional derivative, calculating the gradient for dd input parameters requires dd independent forward evaluations.

Reverse-mode automatic differentiation reverses the propagation direction, computing adjoint derivatives from the terminal output back toward input variables. The forward evaluation is executed first to compute and store intermediate states v1v_1 through v6v_6. For every node, its adjoint variable is defined as \rbar{v}_i = \frac{\rpartial y}{\rpartial v_i}, measuring the sensitivity of the final output to perturbations in viv_i. The reverse sweep initializes at the final output node with adjoint \rbar{v}_6 = \frac{\rpartial y}{\rpartial v_6} = 1.

Adjoint values propagate backward through intermediate dependencies according to local derivatives:

\rbar{v}_5 = \rbar{v}_6 \frac{\rpartial v_6}{\rpartial v_5} = 1(1) = 1

\rbar{v}_4 = \rbar{v}_6 \frac{\rpartial v_6}{\rpartial v_4} = 1(1) = 1

\rbar{v}_3 = \rbar{v}_5 \frac{\rpartial v_5}{\rpartial v_3} = 1 \times \rexp(v_3) = \rexp(v_3)

Because input variable v1v_1 influences yy solely through v3v_3, its adjoint is:

\rbar{v}_1 = \rbar{v}_3 \frac{\rpartial v_3}{\rpartial v_1} = \rexp(v_3) v_2 = x_2 \rexp(x_1 x_2)

Variable v2v_2 branches toward two distinct operations, v3v_3 and v4v_4. The multivariable chain rule accumulates all downstream contributions:

\rbar{v}_2 = \rbar{v}_3 \frac{\rpartial v_3}{\rpartial v_2} + \rbar{v}_4 \frac{\rpartial v_4}{\rpartial v_2} = v_1 \rexp(v_3) + 1 \times \frac{1}{v_2} = x_1 \rexp(x_1 x_2) + \frac{1}{x_2}

In general computation graphs where node viv_i is used by multiple subsequent nodes vjv_j, its total adjoint is governed by:

\rbar{v}_i = \sum_{j: v_j \text{ uses } v_i} \rbar{v}_j \frac{\rpartial v_j}{\rpartial v_i}

Reverse-mode automatic differentiation calculates the exact gradients with respect to all primary input variables simultaneously in a single reverse sweep, making it the foundational engine for neural network backpropagation.

Gradient Descent Optimization Frameworks

Supervised regression models optimize trainable parameter vectors θ\boldsymbol{\theta} over a training dataset S={(xi,yi)}i=1n\mathcal{S} = \{(\mathbf{x}_i, y_i)\}_{i=1}^n. For a model prediction h(xi;θ)h(\mathbf{x}_i; \boldsymbol{\theta}), the empirical training objective is defined as the mean squared error loss function:

L(θ)=1n∑i=1n[h(xi;θ)−yi]2\mathcal{L}(\boldsymbol{\theta}) = \frac{1}{n} \sum_{i=1}^n [h(\mathbf{x}_i; \boldsymbol{\theta}) - y_i]^2

The true gradient of the training objective across the entire dataset is:

∇θL(θ)=1n∑i=1n∇θ[h(xi;θ)−yi]2\nabla_{\boldsymbol{\theta}} \mathcal{L}(\boldsymbol{\theta}) = \frac{1}{n} \sum_{i=1}^n \nabla_{\boldsymbol{\theta}} [h(\mathbf{x}_i; \boldsymbol{\theta}) - y_i]^2

Optimization algorithms differ based on the sample size used to estimate this gradient at each iteration step.

In batch gradient descent (full-batch gradient descent), every parameter update incorporates all nn training examples. At iteration step tt, the gradient of the entire empirical loss is calculated at the current parameter position θt\boldsymbol{\theta}_t, and parameters update via:

θt+1=θt−α∇θL(θ)t\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \alpha \nabla_{\boldsymbol{\theta}} \mathcal{L}(\boldsymbol{\theta})_t

where α>0\alpha > 0 denotes the learning rate. Batch gradient descent evaluates every training instance using identical parameters θt\boldsymbol{\theta}_t, resulting in stable, smooth trajectories across elliptical error contours directly toward local or global minima.

Stochastic gradient descent (SGD) calculates parameter updates using only a single training instance per step (b=1b = 1). At iteration tt, an individual index ItI_t is sampled uniformly from the index set {1,…,n}\{1, \dots, n\}. The local gradient vector is evaluated as:

gt=∇θ[h(xIt;θ)−yIt]2∣θ=θt\mathbf{g}_t = \nabla_{\boldsymbol{\theta}} [h(\mathbf{x}_{I_t}; \boldsymbol{\theta}) - y_{I_t}]^2 \vert_{\boldsymbol{\theta} = \boldsymbol{\theta}_t}

Parameters update along this single-sample gradient using learning rate η\eta:

θt+1=θt−η∇θ[h(xIt;θ)−yIt]2∣θ=θt\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \eta \nabla_{\boldsymbol{\theta}} [h(\mathbf{x}_{I_t}; \boldsymbol{\theta}) - y_{I_t}]^2 \vert_{\boldsymbol{\theta} = \boldsymbol{\theta}_t}

Because individual sample loss surfaces differ significantly from the global loss, SGD generates high variance, noisy, erratic parameter trajectories that fluctuate around optimal basins.

Mini-batch gradient descent provides a balanced compromise between batch stability and stochastic efficiency. At step tt, a random subset Bt⊂{1,…,n}\mathcal{B}_t \subset \{1, \dots, n\} containing bb unique examples is sampled, where 1<b<n1 < b < n. The mini-batch loss is formulated as:

LBt(θ)=1b∑i∈Bt[h(xi;θ)−yi]2\mathcal{L}_{\mathcal{B}_t}(\boldsymbol{\theta}) = \frac{1}{b} \sum_{i \in \mathcal{B}_t} [h(\mathbf{x}_i; \boldsymbol{\theta}) - y_i]^2

The corresponding parameter update is given by:

θt+1=θt−η1b∑i∈Bt∇θ[h(xi;θ)−yi]2∣θ=θt\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \eta \frac{1}{b} \sum_{i \in \mathcal{B}_t} \nabla_{\boldsymbol{\theta}} [h(\mathbf{x}_i; \boldsymbol{\theta}) - y_i]^2 \vert_{\boldsymbol{\theta} = \boldsymbol{\theta}_t}

All examples within mini-batch Bt\mathcal{B}_t are evaluated simultaneously against θt\boldsymbol{\theta}_t, and parameters undergo a single update per batch.

Loss contour trajectory comparison of Batch, Mini-batch, and Stochastic gradient descent

An epoch represents one complete pass through the entire training dataset, whereas an update represents a single modification to the parameter vector. When partition size is bb, the total number of parameter updates per epoch is governed by the ceiling function:

Updates per epoch=⌈nb⌉\text{Updates per epoch} = \lceil \frac{n}{b} \rceil

For a representative dataset size of n=1000n = 1000:

Batch gradient descent operates with batch size b=1000b = 1000, yielding exactly 11 update per epoch.

Mini-batch gradient descent configured with b=100b = 100 produces ⌈1000100⌉=10\lceil \frac{1000}{100} \rceil = 10 updates per epoch.

Stochastic gradient descent with b=1b = 1 produces ⌈10001⌉=1000\lceil \frac{1000}{1} \rceil = 1000 parameter updates per epoch.

Comparing optimization algorithms purely after an equal number of parameter updates is fundamentally misleading, as the quantity of processed data instances differs by orders of magnitude. Rigorous convergence evaluations must be benchmarked against epochs or cumulative data points processed.

Sequential iterative optimization steps update parameters across iterations according to current model states:

θ(1)=θ(0)−η∇θL,L=1n∑i=1n(yi−f(0)(xi,θ(0)))2\boldsymbol{\theta}^{(1)} = \boldsymbol{\theta}^{(0)} - \eta \nabla_{\boldsymbol{\theta}} \mathcal{L}, \quad \mathcal{L} = \frac{1}{n} \sum_{i=1}^n (y_i - f^{(0)}(\mathbf{x}_i, \boldsymbol{\theta}^{(0)}))^2

θ(2)=θ(1)−η∇θL,L=1n∑i=1n(yi−f(1)(xi,θ(1)))2\boldsymbol{\theta}^{(2)} = \boldsymbol{\theta}^{(1)} - \eta \nabla_{\boldsymbol{\theta}} \mathcal{L}, \quad \mathcal{L} = \frac{1}{n} \sum_{i=1}^n (y_i - f^{(1)}(\mathbf{x}_i, \boldsymbol{\theta}^{(1)}))^2

θ(3)=θ(2)−η∇θL,L=1n∑i=1n(yi−f(2)(xi,θ(2)))2\boldsymbol{\theta}^{(3)} = \boldsymbol{\theta}^{(2)} - \eta \nabla_{\boldsymbol{\theta}} \mathcal{L}, \quad \mathcal{L} = \frac{1}{n} \sum_{i=1}^n (y_i - f^{(2)}(\mathbf{x}_i, \boldsymbol{\theta}^{(2)}))^2

Regularization Methods in Deep Learning

Deep neural networks possess high parametric capacity, predisposing them to overfitting where the model memorizes sample-specific noise rather than underlying data-generating distributions. Regularization techniques impose structural or procedural constraints to preserve out-of-sample generalization.

Norm-based regularization directly modifies the objective function by penalizing the magnitudes of the network weights. For a model with mm trainable weights θj\theta_j, the objective incorporates an LpL_p penalty:

min⁡θ1n∑i=1n(yi−h(xi,θ))2+λ∑j=1m∣θj∣p\min_{\boldsymbol{\theta}} \frac{1}{n} \sum_{i=1}^n (y_i - h(\mathbf{x}_i, \boldsymbol{\theta}))^2 + \lambda \sum_{j=1}^m |\theta_j|^p

Here, λ≥0\lambda \ge 0 governs regularization strength. When p=2p = 2, this penalty corresponds to L2L_2 regularization (weight decay), penalizing large weight vectors quadratically. When p=1p = 1, it corresponds to L1L_1 regularization (Lasso), driving non-critical weights to zero. These norm penalties are applied exclusively to network weights θj\theta_j and are never applied to network bias terms.

Early stopping regulates model complexity procedurally rather than altering the objective function. Available data is divided into disjoint training, validation, and test subsets. The training set calculates gradient updates, the validation set monitors generalization and parameter checkpoints, and the test set remains unobserved until final post-training evaluation.

During gradient descent optimization, training loss decreases monotonically across epochs. Validation loss decreases initially, attains a minimum, and subsequently climbs as parameter updates fit idiosyncratic training noise. Early stopping halts training before overfitting degrades generalization.

The early stopping protocol follows five sequential procedural steps:

  1. Train the network for one epoch, corresponding to a single comprehensive pass across the training partition.

  2. Evaluate loss on the validation dataset without updating network parameters.

  3. Save the model parameter vector if the validation loss improves upon the previous best recorded loss.

  4. Terminate optimization if validation loss fails to achieve an improvement for a predetermined window of consecutive epochs, defined as the patience.

  5. Restore and output the parameter checkpoint corresponding to the absolute minimum validation loss recorded throughout optimization.

For parameter vectors θ(t)\boldsymbol{\theta}^{(t)} monitored across epoch index tt, the selected optimal checkpoint t∗t^* satisfies:

t∗=arg⁡min⁡t among monitored epochsLval(θ(t))t^* = \arg\min_{t \text{ among monitored epochs}} \mathcal{L}_{\text{val}}(\boldsymbol{\theta}^{(t)})

Early stopping schematic illustrating minimum validation loss, patience window, and optimal checkpoint

Early stopping functions as an implicit regularizer by bounding the reachable volume of parameter space from initialization. The test set must never be used to guide early stopping decisions, as doing so introduces information leakage and compromises evaluation integrity.

Dropout provides stochastic regularizing effects during feedforward training iterations. Each neuron within a hidden layer is retained with a probability pp and set to zero with probability 1−p1 - p, termed the dropout rate. At each training step, neurons are dropped independently with probability 1−p1 - p, temporarily excising their forward activations and backward gradient contributions.

Dropout architecture schematic showing deactivated units

Dropping units at random prevents neurons from developing brittle co-adaptations where hidden features rely on the presence of specific counterpart units. Instead, each neuron learns robust features independently, mimicking the ensembling of exponentially many thinned neural sub-networks.

Model Complexity, Generalization, and Hyperparameter Optimization

The expected prediction error of statistical learning models breaks down into squared bias, variance, and irreducible error. Model complexity dictates the trade-off balance between bias and variance.

Bias-variance tradeoff curve vs model complexity

Underfitting occurs at low model complexity, where restricted functional capacity prevents the model from capturing true input-output relationships. This state displays high squared bias and low variance. Conversely, overfitting occurs at high model complexity, where excessive functional flexibility captures idiosyncratic dataset noise, yielding low bias but severe variance. The optimum model complexity lies at the trough of the total error curve, where the sum of squared bias and variance is minimized.

Training and validation error across epochs showing bias and variance regimes

Plotting error across training epochs reveals similar dynamics. Training error continuously declines toward zero. Validation error exhibits a characteristic U-shaped profile, decreasing initially during the high-bias underfitting regime, reaching an optimal minimum, and subsequently diverging upward as high variance drives overfitting.

Consider an empirical regression setting with input xx, eight hidden neurons (h1h_1 through h8h_8), and an output neuron y^\hat{y}. The input layer connects to hidden neurons through the weight vector:

wx→h=[−0.21,−0.50,0.35,−0.49,0.34,0.20,−0.34,−0.88]Tw_{x \rightarrow h} = [-0.21, -0.50, 0.35, -0.49, 0.34, 0.20, -0.34, -0.88]^T

The hidden units connect to the output y^\hat{y} through the weight vector:

wh→y^=[−0.19,0.43,−0.08,−0.39,−0.29,0.10,0.05,0.39]Tw_{h \rightarrow \hat{y}} = [-0.19, 0.43, -0.08, -0.39, -0.29, 0.10, 0.05, 0.39]^T

Neural network architecture with weights connecting input x to hidden units h1-h8 and output y_hat

Fitting this architecture against noisy sinusoidal data samples produces a function fit score of 0.50040.5004. When model capacity is insufficient relative to training progress, the predicted curve y^(x)\hat{y}(x) flattens relative to true f(x)f(x), capturing only coarse macroscopic trends before additional training epochs or hidden units lower the training loss.

Function fit comparison of true f(x) and predicted curve alongside loss curve

Selecting optimal structural configurations—including layer dimensions, learning rates, regularizers, and batch sizes—requires systematic hyperparameter optimization. Standard search strategies include Grid Search, Random Grid Search, and Bayesian Optimization.

Comparison of Grid Search, Random Grid Search, and Bayesian Optimization across hyperparameter search spaces

Grid search tests configurations across an evenly spaced, coordinate grid within hyperparameter space. While deterministic and simple, it scales exponentially with dimensionality, evaluating redundant points along uninfluential hyperparameter axes without adapting to the underlying loss landscape.

Random grid search samples coordinate evaluations uniformly at random across the bounded hyperparameter space. Given a fixed evaluation budget, random search evaluates far more unique coordinate values along critical hyperparameter dimensions than grid search, yielding superior optimization performance on high-dimensional surfaces with low effective dimensionality.

Bayesian optimization treats hyperparameter evaluation as a black-box global optimization problem. It fits a probabilistic surrogate model (such as a Gaussian process) over prior evaluation points and optimizes an acquisition function to determine subsequent evaluation coordinates. This balances exploration of uncertain regions with exploitation of known minima, converging on optimal hyperparameters with substantially fewer total model evaluations.

Maximum Likelihood Estimation and Classification Frameworks

Maximum likelihood estimation (MLE) is a foundational statistical approach for estimating distribution parameters from empirical data. Unlike forward probability, which computes the likelihood of sample outcomes from known distributions, MLE solves the inverse problem: given observed data samples, infer the unknown probability distribution parameters θ\boldsymbol{\theta}.

Given nn independent and identically distributed observations S={x1,…,xn}\mathcal{S} = \{x_1, \dots, x_n\} drawn from a density or mass function p(x;θ)p(x; \boldsymbol{\theta}), the likelihood function is defined as the joint probability of the sample set:

L(θ;S)=∏i=1np(xi;θ)L(\boldsymbol{\theta}; \mathcal{S}) = \prod_{i=1}^n p(x_i; \boldsymbol{\theta})

Within this expression, observations S\mathcal{S} are fixed, while parameters θ\boldsymbol{\theta} vary. Crucially, the likelihood function is not a probability distribution over parameter space; its integral or sum over θ\boldsymbol{\theta} does not equal unity. The maximum likelihood parameter estimate θ^\hat{\boldsymbol{\theta}} maximizes the likelihood:

θ^=arg⁡max⁡θL(θ;S)\hat{\boldsymbol{\theta}} = \arg\max_{\boldsymbol{\theta}} L(\boldsymbol{\theta}; \mathcal{S})

Because the natural logarithm is strictly monotonically increasing, maximizing L(θ;S)L(\boldsymbol{\theta}; \mathcal{S}) is equivalent to maximizing the log-likelihood function l(θ)l(\boldsymbol{\theta}):

l(\boldsymbol{\theta}) = \rlog(L(\boldsymbol{\theta}; \mathcal{S})) = \sum_{i=1}^n \rlog(p(x_i; \boldsymbol{\theta}))

Taking logarithms converts products into sums, which prevents arithmetic underflow during numerical computation with small probabilities. In machine learning optimization, this is framed as minimizing the negative log-likelihood (NLL):

-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \rlog(p(x_i; \boldsymbol{\theta}))

For binary classification with neural networks, target labels belong to binary classes yi∈{0,1}y_i \in \{0, 1\}. The network produces a single scalar logit output zi=f(xi;θ)z_i = f(\mathbf{x}_i; \boldsymbol{\theta}), which passes through the logistic sigmoid activation function:

p_i = \sigma(z_i) = \frac{1}{1 + \rexp(-z_i)}

The activated output represents class probabilities:

P(Y=1∣xi;θ)=pi,P(Y=0∣xi;θ)=1−piP(Y = 1 \mid \mathbf{x}_i; \boldsymbol{\theta}) = p_i, \quad P(Y = 0 \mid \mathbf{x}_i; \boldsymbol{\theta}) = 1 - p_i

The conditional probability assigned to observed label yiy_i is:

p(yi∣xi;θ)={pi,yi=11−pi,yi=0p(y_i \mid \mathbf{x}_i; \boldsymbol{\theta}) = \begin{cases} p_i, & y_i = 1 \\ 1 - p_i, & y_i = 0 \end{cases}

This is expressed compactly as a Bernoulli distribution:

p(yi∣xi;θ)=piyi(1−pi)1−yip(y_i \mid \mathbf{x}_i; \boldsymbol{\theta}) = p_i^{y_i} (1 - p_i)^{1 - y_i}

The joint likelihood across dataset S={(xi,yi)}i=1n\mathcal{S} = \{(\mathbf{x}_i, y_i)\}_{i=1}^n is:

L(θ;S)=∏i=1npiyi(1−pi)1−yiL(\boldsymbol{\theta}; \mathcal{S}) = \prod_{i=1}^n p_i^{y_i} (1 - p_i)^{1 - y_i}

Taking the negative logarithm yields the binary cross-entropy (BCE) loss:

-l(\boldsymbol{\theta}) = -\sum_{i=1}^n [y_i \rlog(p_i) + (1 - y_i) \rlog(1 - p_i)]

For every training example, only the log-probability of the observed target class contributes to the overall loss and subsequent gradient updates.

Multiclass classification extends this formulation to KK discrete classes, where target labels satisfy yi∈{1,…,K}y_i \in \{1, \dots, K\}. Target classes are encoded as one-hot vectors yi=[yi1,…,yiK]T\mathbf{y}_i = [y_{i1}, \dots, y_{iK}]^T, where:

yik={1,yi=k0,yi≠ky_{ik} = \begin{cases} 1, & y_i = k \\ 0, & y_i \ne k \end{cases}

For K=3K = 3, one-hot encodings evaluate as:

yi=1  ⟹  yi=(100),yi=2  ⟹  yi=(010),yi=3  ⟹  yi=(001)y_i = 1 \implies \mathbf{y}_i = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}, \quad y_i = 2 \implies \mathbf{y}_i = \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}, \quad y_i = 3 \implies \mathbf{y}_i = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}

The network terminal layer contains KK neurons outputting raw logits zi=f(xi;θ)=[zi1,…,ziK]T\mathbf{z}_i = f(\mathbf{x}_i; \boldsymbol{\theta}) = [z_{i1}, \dots, z_{iK}]^T. Logits are mapped to normalized class probabilities using the softmax activation function:

p_{ik} = P(Y = k \mid \mathbf{x}_i; \boldsymbol{\theta}) = \frac{\rexp(z_{ik})}{\sum_{j=1}^K \rexp(z_{ij})}

The softmax output satisfies the probability axioms:

pik>0,∑k=1Kpik=1p_{ik} > 0, \quad \sum_{k=1}^K p_{ik} = 1

For observed class yiy_i, the conditional probability is p(yi∣xi;θ)=pi,yip(y_i \mid \mathbf{x}_i; \boldsymbol{\theta}) = p_{i, y_i}. If yi=3y_i = 3, the sample contribution is pi3p_{i3}. The total likelihood is:

L(θ;S)=∏i=1npi,yiL(\boldsymbol{\theta}; \mathcal{S}) = \prod_{i=1}^n p_{i, y_i}

The corresponding negative log-likelihood is:

-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \rlog(p_{i, y_i})

Using one-hot vector representations, the conditional probability per example is rewritten as:

p(yi∣xi;θ)=∏k=1Kpikyikp(y_i \mid \mathbf{x}_i; \boldsymbol{\theta}) = \prod_{k=1}^K p_{ik}^{y_{ik}}

Taking the negative logarithm over all training examples yields the categorical cross-entropy loss:

-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \sum_{k=1}^K y_{ik} \rlog(p_{ik})

Minimizing categorical cross-entropy via gradient descent maximizes the joint likelihood that the network assigns to the observed multi-class training data.