All field notes
Multilayer perceptron diagram showing two input neurons, two hidden neurons, two output neurons, and the forward and backward flow of computation.

Understanding Multilayer Perceptrons: Forward Propagation and Backpropagation

Learn how an MLP predicts and learns, with a complete numerical example covering forward propagation, output and hidden-layer gradients, weight updates, and practical limitations.

A single perceptron makes a decision using a weighted sum and a threshold. A multilayer perceptron (MLP) connects several layers of artificial neurons, allowing it to learn relationships that a single linear decision boundary cannot capture.

The useful question is how those layers learn. We can answer it by following one small network through a prediction, calculating its error, and tracing that error backward through both the output layer and the hidden layer.

If inputs, weights, bias, and activation functions are new to you, start with the perceptron article.

In this article: Network structure · Activation and loss · Forward propagation · Output gradients · Hidden gradients · Weight updates · Benefits and limitations · References

What is a multilayer perceptron?

An MLP is a feedforward neural network with an input layer, one or more hidden layers, and an output layer. Its hidden neurons apply nonlinear activation functions to weighted sums of the values they receive. In supervised learning, labeled examples guide the adjustment of its weights and biases. 1, 11

Three ideas describe its structure:

  • Input layer: receives features, such as pixel intensities or numerical measurements. These nodes provide values to the first hidden layer.
  • Hidden layers: transform those values into intermediate representations. Each neuron calculates a weighted sum, adds a bias, and applies an activation function.
  • Output layer: produces the values used for the task, such as class scores or a numerical prediction.

In a fully connected, or dense, layer, every neuron receives a connection from every neuron in the immediately preceding layer. An MLP does not require direct connections between every pair of layers. A dense transformation from nn inputs to mm neurons has n×mn\times m weights and, with one bias per destination neuron, mm biases. 2, 4

Feedforward describes the prediction graph: information travels from inputs toward outputs without a recurrent cycle. Backpropagation calculates derivatives through that graph in reverse. It does not turn the prediction network into a recurrent network. 3

An MLP is the model architecture. Backpropagation is the method used to calculate gradients. Gradient descent is an optimization rule that uses those gradients to change parameters. These terms describe different parts of training.

Why hidden layers need nonlinearity

Stacking linear transformations alone produces another linear transformation. Nonlinear activations allow the network to combine features into relationships that cannot be represented by one linear map.

For a layer, the computation is:

zj=∑iwjiai+bjaj=f(zj)z=Wa+b(matrix form)\begin{aligned} z_j &= \sum_i w_{ji}a_i+b_j \\ a_j &= f(z_j) \\ \mathbf{z} &= W\mathbf{a}+\mathbf{b}\qquad\text{(matrix form)} \end{aligned}

Here, aia_i is an incoming value, wjiw_{ji} is a connection weight, bjb_j is the destination neuron's bias, and ff is its activation function.

An intuition: people recognizing a handwritten digit

Michael Stevens's The Stilwell Brain uses people acting as neurons to illustrate layered recognition. A handwritten digit is broken into small pieces. Early groups respond to simple visual features, later groups combine those features, and the final group identifies the digit. 5

The analogy helps explain how intermediate representations can build on one another. In a trained MLP, the representations are learned numerical transformations. We should not assume that each hidden neuron has an obvious label such as “vertical line” or “corner.”

Activation functions and loss functions

An activation function determines a neuron's output. A loss function measures how far the network's prediction is from the target. They have different jobs.

Choosing an activation

ActivationRuleOutput rangeCommon role
Sigmoidσ(z)=11+e−z\displaystyle\sigma(z)=\frac{1}{1+e^{-z}}(0,1)(0, 1)Binary output, or an illustrative smooth neuron
Tanhtanh⁡(z)\tanh(z)(−1,1)(-1,1)A hidden activation with outputs centered around zero
ReLUmax⁡(0,z)\max(0,z)[0,∞)[0,\infty)Hidden layers
Softmaxpj=ezj∑kezk\displaystyle p_j=\frac{e^{z_j}}{\sum_k e^{z_k}}Each value in (0,1)(0, 1); the vector sums to 1Mutually exclusive multiclass outputs

Sigmoid, tanh, and ReLU act on individual values. Softmax considers a vector of scores and normalizes it across classes. For a mutually exclusive classification task, the predicted class is commonly selected with arg max⁡\operatorname*{arg\,max}; every output value still exists before that decision. 6, 12

Choosing a loss

Let tt represent a target and pp a prediction. The following expressions describe one example; averaging across a dataset or batch adds an appropriate reduction.

LossExpressionCommon use
Mean squared error1m∑j=1m(tj−pj)2\displaystyle\frac{1}{m}\sum_{j=1}^{m}(t_j-p_j)^2Regression
Binary cross-entropy−[tln⁡(p)+(1−t)ln⁡(1−p)]-[t\ln(p)+(1-t)\ln(1-p)]Binary classification
Categorical cross-entropy−∑jtjln⁡(pj)\displaystyle-\sum_j t_j\ln(p_j)Mutually exclusive multiclass classification

The negative sign in cross-entropy is necessary: a confident correct prediction should have a small loss. For one-hot targets, categorical cross-entropy reduces to the negative logarithm of the probability assigned to the correct class. 7, 8, 9

In implementations, check what a loss function expects. For example, PyTorch's CrossEntropyLoss takes unnormalized scores, or logits, and combines the required normalization with the loss calculation. Its BCEWithLogitsLoss similarly combines sigmoid and binary cross-entropy for numerical stability. 12

The numerical network we will train

We will use a small example adapted from Matt Mazur's backpropagation tutorial: two inputs, two hidden neurons, and two outputs. Every hidden and output neuron uses sigmoid. 10

Training network with inputs i1 = .05 and i2 = .10; hidden neurons h1 and h2; output targets o1 = .01 and o2 = .99; weights w1 = .15, w2 = .20, w3 = .25, w4 = .30, w5 = .40, w6 = .45, w7 = .50, and w8 = .55; and bias nodes 1 with b1 = .35 and b2 = .60.

The values printed beneath o1o_1 and o2o_2 are the targets t1t_1 and t2t_2. The labels o1o_1 and o2o_2 refer to the network's calculated outputs.

Here, h1h_1 and h2h_2 denote the hidden activations, and o1o_1 and o2o_2 the output activations. Their pre-activation values are written as neth1\mathit{net}_{h_1}, neth2\mathit{net}_{h_2}, neto1\mathit{net}_{o_1}, and neto2\mathit{net}_{o_2}. The bias nodes labeled 11 supply constant inputs multiplied by b1b_1 and b2b_2.

The outputs in this example are independent sigmoid values. They are not a softmax probability distribution and do not need to sum to one. The purpose is to inspect a complete gradient calculation.

Displayed results are rounded to nine decimal places. Calculations use the unrounded values, so rounding an early activation and reusing it may produce a different final result.

The equation notation and worked steps follow slides 23–33 of the course presentation. We use the weight labels in the network diagram consistently, including where the slides' worked formulas use a different labeling order. 16

Inputs:i1=0.05,i2=0.10Targets:t1=0.01,t2=0.99Weights:w1=0.15,w2=0.20,w3=0.25,w4=0.30w5=0.40,w6=0.45,w7=0.50,w8=0.55Hidden bias:b1=0.35(shared by h1 and h2)Output bias:b2=0.60(shared by o1 and o2)Learning rate:η=0.50Activation:σ(z)=11+e−z\begin{aligned} \text{Inputs:}\quad&i_1=0.05,\quad i_2=0.10 \\ \text{Targets:}\quad&t_1=0.01,\quad t_2=0.99 \\ \text{Weights:}\quad&w_1=0.15,\quad w_2=0.20,\quad w_3=0.25,\quad w_4=0.30 \\ &w_5=0.40,\quad w_6=0.45,\quad w_7=0.50,\quad w_8=0.55 \\ \text{Hidden bias:}\quad&b_1=0.35\quad\text{(shared by }h_1\text{ and }h_2\text{)} \\ \text{Output bias:}\quad&b_2=0.60\quad\text{(shared by }o_1\text{ and }o_2\text{)} \\ \text{Learning rate:}\quad&\eta=0.50 \\ \text{Activation:}\quad&\sigma(z)=\frac{1}{1+e^{-z}} \end{aligned}

Forward propagation step by step

1. Calculate the hidden activations

For the first hidden neuron:

neth1=w1i1+w3i2+b1=(0.15×0.05)+(0.25×0.10)+0.35=0.3825outh1=σ(neth1)=11+e−0.3825=h1≈0.594475931\begin{aligned} \mathit{net}_{h_1} &= w_1i_1+w_3i_2+b_1 \\ &= (0.15\times0.05)+(0.25\times0.10)+0.35 = 0.3825 \\ \mathit{out}_{h_1} &= \sigma(\mathit{net}_{h_1}) = \frac{1}{1+e^{-0.3825}} \\ &= h_1 \approx 0.594475931 \end{aligned}

For the second hidden neuron:

neth2=w2i1+w4i2+b1=(0.20×0.05)+(0.30×0.10)+0.35=0.3900outh2=σ(neth2)=11+e−0.3900=h2≈0.596282699\begin{aligned} \mathit{net}_{h_2} &= w_2i_1+w_4i_2+b_1 \\ &= (0.20\times0.05)+(0.30\times0.10)+0.35 = 0.3900 \\ \mathit{out}_{h_2} &= \sigma(\mathit{net}_{h_2}) = \frac{1}{1+e^{-0.3900}} \\ &= h_2 \approx 0.596282699 \end{aligned}

Training network with inputs i1 = .05 and i2 = .10; hidden neurons h1 and h2; output targets o1 = .01 and o2 = .99; weights w1 = .15, w2 = .20, w3 = .25, w4 = .30, w5 = .40, w6 = .45, w7 = .50, and w8 = .55; and bias nodes 1 with b1 = .35 and b2 = .60.

2. Calculate the output activations

The hidden activations become the inputs to the output layer:

neto1=w5h1+w7h2+b2≈(0.40×0.594475931)+(0.50×0.596282699)+0.60≈1.135931722outo1=σ(neto1)=11+e−neto1≈0.756931915neto2=w6h1+w8h2+b2≈(0.45×0.594475931)+(0.55×0.596282699)+0.60≈1.195469653outo2=σ(neto2)=11+e−neto2≈0.767717880\begin{aligned} \mathit{net}_{o_1} &= w_5h_1+w_7h_2+b_2 \\ &\approx (0.40\times0.594475931)+(0.50\times0.596282699)+0.60 \\ &\approx 1.135931722 \\ \mathit{out}_{o_1} &= \sigma(\mathit{net}_{o_1}) = \frac{1}{1+e^{-\mathit{net}_{o_1}}} \approx 0.756931915 \\ \mathit{net}_{o_2} &= w_6h_1+w_8h_2+b_2 \\ &\approx (0.45\times0.594475931)+(0.55\times0.596282699)+0.60 \\ &\approx 1.195469653 \\ \mathit{out}_{o_2} &= \sigma(\mathit{net}_{o_2}) = \frac{1}{1+e^{-\mathit{net}_{o_2}}} \approx 0.767717880 \end{aligned}

The network currently predicts approximately [0.756931915,0.767717880][0.756931915, 0.767717880]. We want [0.01,0.99][0.01, 0.99], so the first output should decrease and the second should increase.

Training network with inputs i1 = .05 and i2 = .10; hidden neurons h1 and h2; output targets o1 = .01 and o2 = .99; weights w1 = .15, w2 = .20, w3 = .25, w4 = .30, w5 = .40, w6 = .45, w7 = .50, and w8 = .55; and bias nodes 1 with b1 = .35 and b2 = .60.

3. Calculate the total error

For this example, use half the sum of squared output errors:

Etotal=12(t1−outo1)2+12(t2−outo2)2≈12(0.01−0.756931915)2+12(0.99−0.767717880)2≈0.278953643+0.024704670≈0.303658314\begin{aligned} E_{\mathrm{total}} &= \frac{1}{2}(t_1-\mathit{out}_{o_1})^2+\frac{1}{2}(t_2-\mathit{out}_{o_2})^2 \\ &\approx \frac{1}{2}(0.01-0.756931915)^2+\frac{1}{2}(0.99-0.767717880)^2 \\ &\approx 0.278953643+0.024704670 \\ &\approx 0.303658314 \end{aligned}

With exactly two outputs, this expression equals their mean squared error. The distinction matters when the number of outputs changes: half the sum and the mean use different scaling factors. Our derivative below follows the expression written here.

The Chain Rule

  • The chain rule is a fundamental calculus principle extensively used in backpropagation.

  • Extremely important for Multilayer Layer Perceptron.

  • Determines the relation between weight and error.

  • ∂Etotal∂w5\displaystyle\frac{\partial E_{\mathrm{total}}}{\partial w_5} is the rate of change in error with respect to change in weight.

  • ∂Etotal∂outo1\displaystyle\frac{\partial E_{\mathrm{total}}}{\partial\mathit{out}_{o_1}} is the rate of change in error with respect to change in output value of a neuron.

  • ∂outo1∂neto1\displaystyle\frac{\partial\mathit{out}_{o_1}}{\partial\mathit{net}_{o_1}} is the rate of change in output value of a neuron with respect to change in net value.

  • ∂neto1∂w5\displaystyle\frac{\partial\mathit{net}_{o_1}}{\partial w_5} is the change in net value with respect to change in weight.

The Chain Rule: ∂net_o1/∂w5 * ∂out_o1/∂net_o1 * ∂E_total/∂out_o1 = ∂E_total/∂w5. The diagram shows output h1 through w5, output h2 through w7, a constant input 1 through b2, and a neuron split into net_o1 and out_o1. Three backward arrows follow the derivatives. E_o1 = ½(target_o1 − out_o1)², and E_total = E_o1 + E_o2.

Backpropagation through the output layer

We need to know how a weight affects EtotalE_{\mathrm{total}}. For w5w_5, the chain of dependencies is:

w5⟶neto1⟶outo1⟶Etotalw_5\longrightarrow\mathit{net}_{o_1}\longrightarrow\mathit{out}_{o_1}\longrightarrow E_{\mathrm{total}}

The chain rule multiplies the derivatives along that path:

∂Etotal∂w5=∂Etotal∂outo1∂outo1∂neto1∂neto1∂w5\frac{\partial E_{\mathrm{total}}}{\partial w_5} = \frac{\partial E_{\mathrm{total}}}{\partial\mathit{out}_{o_1}} \frac{\partial\mathit{out}_{o_1}}{\partial\mathit{net}_{o_1}} \frac{\partial\mathit{net}_{o_1}}{\partial w_5}

Each term has a straightforward meaning.

How the error changes with the output: differentiating the squared error gives o1−t1o_1-t_1.

Etotal=12(t1−outo1)2+12(t2−outo2)2∂Etotal∂outo1=2⋅12(t1−outo1)(−1)+0=outo1−t1≈0.746931915\begin{aligned} E_{\mathrm{total}} &= \frac{1}{2}(t_1-\mathit{out}_{o_1})^2+\frac{1}{2}(t_2-\mathit{out}_{o_2})^2 \\ \frac{\partial E_{\mathrm{total}}}{\partial\mathit{out}_{o_1}} &= 2\cdot\frac{1}{2}(t_1-\mathit{out}_{o_1})(-1)+0 \\ &= \mathit{out}_{o_1}-t_1 \approx 0.746931915 \end{aligned}

How sigmoid changes with its input: its derivative is the activation multiplied by one minus that activation.

outo1=σ(neto1)∂outo1∂neto1=outo1(1−outo1)≈0.183985991\begin{aligned} \mathit{out}_{o_1} &= \sigma(\mathit{net}_{o_1}) \\ \frac{\partial\mathit{out}_{o_1}}{\partial\mathit{net}_{o_1}} &= \mathit{out}_{o_1}(1-\mathit{out}_{o_1}) \\ &\approx 0.183985991 \end{aligned}

How the weighted sum changes with the weight: since neto1=w5h1+w7h2+b2\mathit{net}_{o_1}=w_5h_1+w_7h_2+b_2, the derivative with respect to w5w_5 is h1h_1.

neto1=w5outh1+w7outh2+b2∂neto1∂w5=1⋅outh1+0+0=h1≈0.594475931\begin{aligned} \mathit{net}_{o_1} &= w_5\mathit{out}_{h_1}+w_7\mathit{out}_{h_2}+b_2 \\ \frac{\partial\mathit{net}_{o_1}}{\partial w_5} &= 1\cdot\mathit{out}_{h_1}+0+0 \\ &= h_1 \approx 0.594475931 \end{aligned}

Putting those terms together:

∂Etotal∂w5=(outo1−t1)outo1(1−outo1)h1≈0.081695860\begin{aligned} \frac{\partial E_{\mathrm{total}}}{\partial w_5} &= (\mathit{out}_{o_1}-t_1)\mathit{out}_{o_1}(1-\mathit{out}_{o_1})h_1 \\ &\approx 0.081695860 \end{aligned}

What does it mean?

  • What is the meaning of ∂Etotal∂w5≈0.082\displaystyle\frac{\partial E_{\mathrm{total}}}{\partial w_5}\approx0.082?

It is the local slope of the total error with respect to w5w_5 at the current parameters, while all other weights and biases are held fixed. For a sufficiently small change in this weight:

ΔEtotal≈∂Etotal∂w5 Δw5≈0.081695860×Δw5≈0.082×Δw5\begin{aligned} \Delta E_{\mathrm{total}} &\approx \frac{\partial E_{\mathrm{total}}}{\partial w_5}\,\Delta w_5 \\ &\approx 0.081695860\times\Delta w_5 \\ &\approx 0.082\times\Delta w_5 \end{aligned}
  • So ΔEtotal\Delta E_{\mathrm{total}} and Δw5\Delta w_5 are approximately proportional for sufficiently small changes around the current parameters.
  • The coefficient of this local proportionality is the current gradient, 0.0816958600.081695860, which rounds to 0.0820.082. Its value changes as the network parameters change.

Because this gradient is positive, a small increase in w5w_5 increases the error, and a small decrease lowers it, with the other parameters held fixed.

Reusing the output deltas

Write δoj=∂Etotal∂netoj\displaystyle\delta_{o_j}=\frac{\partial E_{\mathrm{total}}}{\partial\mathit{net}_{o_j}}. The delta collects the error derivative and activation derivative at an output neuron:

δo1=(outo1−t1)outo1(1−outo1)≈0.137425009δo2=(outo2−t2)outo2(1−outo2)≈−0.039638934\begin{aligned} \delta_{o_1} &= (\mathit{out}_{o_1}-t_1)\mathit{out}_{o_1}(1-\mathit{out}_{o_1}) \approx 0.137425009 \\ \delta_{o_2} &= (\mathit{out}_{o_2}-t_2)\mathit{out}_{o_2}(1-\mathit{out}_{o_2}) \approx -0.039638934 \end{aligned}

Each incoming weight gradient is the destination neuron's delta multiplied by the incoming activation:

WeightGradientValue
w5w_5δo1outh1\delta_{o_1}\mathit{out}_{h_1}0.081695860
w6w_6δo2outh1\delta_{o_2}\mathit{out}_{h_1}−0.023564392
w7w_7δo1outh2\delta_{o_1}\mathit{out}_{h_2}0.081944155
w8w_8δo2outh2\delta_{o_2}\mathit{out}_{h_2}−0.023636011

The signs fit the desired direction: subtracting the positive gradients decreases w5w_5 and w7w_7, while subtracting the negative gradients increases w6w_6 and w8w_8.

Backpropagation through the hidden layer

The hidden neurons have no target values of their own. Their gradients come from the effect they have on later neurons.

Crucially, h1h_1 influences both outo1\mathit{out}_{o_1} and outo2\mathit{out}_{o_2}. Its error derivative must include both paths. The same is true for h2h_2. 10

1. Collect both error paths for h1

The first output contributes δo1w5\delta_{o_1}w_5, and the second contributes δo2w6\delta_{o_2}w_6:

∂Etotal∂h1=δo1w5+δo2w6≈(0.137425009×0.40)+(−0.039638934×0.45)≈0.054970003−0.017837520≈0.037132483\begin{aligned} \frac{\partial E_{\mathrm{total}}}{\partial h_1} &= \delta_{o_1}w_5+\delta_{o_2}w_6 \\ &\approx (0.137425009\times0.40)+(-0.039638934\times0.45) \\ &\approx 0.054970003-0.017837520 \approx 0.037132483 \end{aligned}

The two paths pull in opposite directions. We add their contributions before continuing through h1h_1's activation.

2. Apply the hidden activation derivative

∂h1∂neth1=h1(1−h1)≈0.241074299δh1=(δo1w5+δo2w6)h1(1−h1)≈0.008951687\begin{aligned} \frac{\partial h_1}{\partial\mathit{net}_{h_1}} &= h_1(1-h_1) \approx 0.241074299 \\ \delta_{h_1} &= (\delta_{o_1}w_5+\delta_{o_2}w_6)h_1(1-h_1) \\ &\approx 0.008951687 \end{aligned}

This delta measures how the total loss changes with the first hidden neuron's pre-activation value.

3. Calculate w1 and w3 gradients

neth1=w1i1+w3i2+b1\mathit{net}_{h_1}=w_1i_1+w_3i_2+b_1, so its derivatives with respect to w1w_1 and w3w_3 are i1i_1 and i2i_2:

∂Etotal∂w1=δh1i1≈0.008951687×0.05≈0.000447584∂Etotal∂w3=δh1i2≈0.008951687×0.10≈0.000895169\begin{aligned} \frac{\partial E_{\mathrm{total}}}{\partial w_1} &= \delta_{h_1}i_1 \approx 0.008951687\times0.05 \approx 0.000447584 \\ \frac{\partial E_{\mathrm{total}}}{\partial w_3} &= \delta_{h_1}i_2 \approx 0.008951687\times0.10 \approx 0.000895169 \end{aligned}

The full chain rule for w1w_1 is therefore:

∂Etotal∂w1=(δo1w5+δo2w6)h1(1−h1)i1\frac{\partial E_{\mathrm{total}}}{\partial w_1} = (\delta_{o_1}w_5+\delta_{o_2}w_6)h_1(1-h_1)i_1

4. Repeat the calculation for h2

The connections from h2h_2 to the outputs are w7w_7 and w8w_8:

∂Etotal∂h2=δo1w7+δo2w8≈(0.137425009×0.50)+(−0.039638934×0.55)≈0.046911091δh2=(δo1w7+δo2w8)h2(1−h2)≈0.011292890∂Etotal∂w2=δh2i1≈0.000564645∂Etotal∂w4=δh2i2≈0.001129289\begin{aligned} \frac{\partial E_{\mathrm{total}}}{\partial h_2} &= \delta_{o_1}w_7+\delta_{o_2}w_8 \\ &\approx (0.137425009\times0.50)+(-0.039638934\times0.55) \approx 0.046911091 \\ \delta_{h_2} &= (\delta_{o_1}w_7+\delta_{o_2}w_8)h_2(1-h_2) \approx 0.011292890 \\ \frac{\partial E_{\mathrm{total}}}{\partial w_2} &= \delta_{h_2}i_1 \approx 0.000564645 \\ \frac{\partial E_{\mathrm{total}}}{\partial w_4} &= \delta_{h_2}i_2 \approx 0.001129289 \end{aligned}

The general hidden-layer rule

For hidden neuron jj, sum over every neuron kk receiving its output:

δj=f′(zj)∑kwkjδk∂E∂wji=δjai\begin{aligned} \delta_j &= f'(z_j)\sum_k w_{kj}\delta_k \\ \frac{\partial E}{\partial w_{ji}} &= \delta_ja_i \end{aligned}

The first expression collects downstream effects. The second attributes that delta to an individual incoming connection. Repeating these calculations layer by layer extends backpropagation to networks with multiple hidden layers.

Use the original weights from this forward pass when calculating every gradient. Replacing w5w_5 or w6w_6 with an updated value while computing the hidden gradients would mix two different parameter states.

Updating all eight weights

Gradient descent changes a weight using:

wnew=wold−η∂E∂ww_{\mathrm{new}}=w_{\mathrm{old}}-\eta\frac{\partial E}{\partial w}

With η=0.5\eta=0.5, the complete update is:

WeightOld valueGradientNew value
w1w_10.1500000000.0004475840.149776208
w2w_20.2000000000.0005646450.199717678
w3w_30.2500000000.0008951690.249552416
w4w_40.3000000000.0011292890.299435355
w5w_50.4000000000.0816958600.359152070
w6w_60.450000000−0.0235643920.461782196
w7w_70.5000000000.0819441550.459027922
w8w_80.550000000−0.0236360110.561818005

For example:

w1,new=0.15−0.5×0.000447584366…≈0.149776208w_{1,\mathrm{new}}=0.15-0.5\times0.000447584366\ldots\approx0.149776208

All eight gradients were calculated before any weight was changed. For this particular update, we hold b1b_1 at 0.350.35 and b2b_2 at 0.600.60 so the effect of changing the weights is easy to inspect.

Bias gradients

A trainable bias participates in the same computation as a weight on a constant input of 1. In this diagram, b1b_1 is shared by both hidden neurons, and b2b_2 is shared by both output neurons. A shared parameter collects the sum of the deltas from the neurons it feeds:

∂Etotal∂b1=δh1+δh2≈0.020244577∂Etotal∂b2=δo1+δo2≈0.097786074b1,new=b1−η(δh1+δh2)≈0.339877711b2,new=b2−η(δo1+δo2)≈0.551106963\begin{aligned} \frac{\partial E_{\mathrm{total}}}{\partial b_1} &= \delta_{h_1}+\delta_{h_2} \approx 0.020244577 \\ \frac{\partial E_{\mathrm{total}}}{\partial b_2} &= \delta_{o_1}+\delta_{o_2} \approx 0.097786074 \\ b_{1,\mathrm{new}} &= b_1-\eta(\delta_{h_1}+\delta_{h_2}) \approx 0.339877711 \\ b_{2,\mathrm{new}} &= b_2-\eta(\delta_{o_1}+\delta_{o_2}) \approx 0.551106963 \end{aligned}

With a separate bias parameter for each neuron, each bias gradient would equal that neuron's own delta. The values above show the optional shared-bias update for the network drawn here.

The check below uses the weight-only update in the table, with biases unchanged.

Run a fresh forward pass

Recalculate both hidden activations and both output activations using the new weights:

Before the update:o1≈0.756931915,o2≈0.767717880,Etotal≈0.303658314After the update, biases fixed:o1≈0.747855045,o2≈0.770211350,Etotal≈0.296368559\begin{aligned} &\text{Before the update:} \\ o_1 &\approx 0.756931915,\quad o_2\approx0.767717880,\quad E_{\mathrm{total}}\approx0.303658314 \\ &\text{After the update, biases fixed:} \\ o_1 &\approx 0.747855045,\quad o_2\approx0.770211350,\quad E_{\mathrm{total}}\approx0.296368559 \end{aligned}

The first prediction has moved downward and the second upward. The loss has decreased. This is one training step on one example; it does not establish performance on unseen data.

Learning rate and the training loop

The learning rate scales the parameter change. A large value can overshoot a useful region or make training unstable. A very small value can make progress slow. Gradient descent uses the learning rate; selecting it is a separate tuning decision. Schedules and adaptive optimizers can vary effective step sizes during training.

A typical iteration follows this sequence:

  1. Run a forward pass on an example or batch.
  2. Calculate a scalar loss using the targets.
  3. Backpropagate to calculate gradients at the current parameters.
  4. Let an optimizer update the weights and trainable biases.
  5. Repeat, monitoring validation performance as well as training loss.

One epoch is a pass through the training dataset. With batches, an epoch contains multiple parameter updates. Training should be assessed with held-out data; repeatedly fitting the same example cannot show that a model generalizes.

Benefits, limitations, and applications

What an MLP can do well

Nonlinear hidden layers can model interactions between features and support both classification and regression. Increasing width or depth changes the model's capacity. Dense computations can also be expressed as matrix operations, making them suitable for parallel execution.

The universal approximation result explains part of this flexibility: under suitable activation and capacity assumptions, a feedforward network can approximate continuous functions on a compact input domain to arbitrary accuracy. It is an expressive-capacity result, with no guarantee that a particular training run will find the necessary parameters or generalize well. 13

Problems to watch for

ProblemWhy it matters
OverfittingA large network can fit noise or memorize training examples. Regularization and validation help assess generalization.
Parameter and memory costDense layers create many weights as input dimensions and layer widths grow.
Hyperparameter sensitivityDepth, width, learning rate, initialization, and training duration affect results.
Non-convex optimizationTraining can encounter different local minima, saddle points, or flat regions.
Weak or unstable gradientsSaturating activations and long chains of derivatives can make learning difficult.
Feature scalingLarge differences in feature magnitudes can make optimization harder.
InterpretabilityHidden representations may be difficult to explain in terms of familiar input features.
Data qualityIncorrect labels, leakage, or an unrepresentative dataset can undermine evaluation.

These are reasons to evaluate an MLP carefully against simpler baselines. They do not disappear just because more layers are added. 1, 11

Where the model can be useful

The same architecture can be adapted to different tasks by choosing suitable input features, output representations, and losses:

TaskExample inputPossible output
ClassificationCustomer or transaction featuresA class score or probability
RegressionNumerical measurementsA continuous prediction
Pattern recognitionPixels or extracted visual featuresA class prediction
Speech or language classificationAudio features or text representationsA category or score
ForecastingMeasurements from a fixed window of past observationsA future value
Recommendation or anomaly scoringFeatures describing a user, item, or eventA relevance or anomaly score

MLPs have a long history in atmospheric modeling, and dense neural models are also useful in systems working with language and audio features. The choice of architecture still depends on the task. A plain MLP does not automatically encode spatial structure or sequence order; those must be represented in its features or handled by other parts of the system. 1, 14, 15

The main idea to keep

Forward propagation transforms inputs into a prediction. Backpropagation traces how the loss depends on each parameter. A hidden neuron learns through the sum of the effects it has on downstream neurons, and an optimizer uses those gradients to update the model.

Once that hidden-layer calculation is clear, the larger network is a repetition of the same weighted sums, activation derivatives, and chain-rule steps.

References

  1. M. W. Gardner and S. R. Dorling, “Artificial neural networks (the multilayer perceptron)—a review of applications in the atmospheric sciences,” Atmospheric Environment, vol. 32, nos. 14–15, pp. 2627–2636, 1998. DOI: 10.1016/S1352-2310(97)00447-0.
  2. Saturn Cloud, “What is a feedforward fully connected neural network and how to implement it in Matlab,” online article, n.d. Read the article.
  3. Brilliant, “Feedforward Neural Networks,” online learning resource, n.d. Read the resource.
  4. P. Mahajan, “Fully Connected vs Convolutional Neural Networks,” The Startup, Medium, October 23, 2020. Read the article.
  5. Vsauce, “The Stilwell Brain,” Mind Field, season 3, episode 3, video featuring Michael Stevens. Watch the episode.
  6. GeeksforGeeks, “Activation functions in neural networks,” online article, n.d. Read the article.
  7. Wikipedia contributors, “Mean squared error,” online encyclopedia entry. Read the entry.
  8. D. Shah, “Understanding Binary Cross-Entropy and Log Loss for Effective Model Monitoring,” Aporia, August 17, 2023; currently hosted by Coralogix. Read the article.
  9. Neural Threads, “Categorical cross-entropy loss—the most important loss function,” Medium, n.d. Read the article.
  10. M. Mazur, “A Step by Step Backpropagation Example,” March 17, 2015. Source of the numerical network and the output- and hidden-layer gradient walkthrough. Read the tutorial.
  11. Scikit-learn developers, “Neural network models (supervised),” official documentation. Read the guide.
  12. PyTorch contributors, official activation and loss documentation: Softmax, MSELoss, BCEWithLogitsLoss, and CrossEntropyLoss.
  13. K. Hornik, M. Stinchcombe, and H. White, “Multilayer feedforward networks are universal approximators,” Neural Networks, vol. 2, no. 5, pp. 359–366, 1989. DOI: 10.1016/0893-6080(89)90020-8.
  14. M. D. Mohanty and M. N. Mohanty, “Verbal sentiment analysis and detection using recurrent neural network,” in Advanced Data Mining Tools and Methods for Social Computing, Academic Press, pp. 85–106, 2022. DOI: 10.1016/B978-0-32-385708-6.00012-6.
  15. A. Singhal and D. K. Sharma, “Voice signal-based disease diagnosis using IoT and learning algorithms for healthcare,” in Implementation of Smart Healthcare Systems using AI, IoT, and Blockchain, Academic Press, pp. 59–81, 2023. DOI: 10.1016/B978-0-323-91916-6.00005-9.
  16. Group 13, “Multilayer Perceptron,” course presentation, slides 23–33. Source of the activation, forward propagation, error, chain rule, and gradient descent equations. Values here are calculated before rounding, using the network diagram's weight labels.
// thanks for readingContinue the conversation ↗