The Artificial Neuron

2 min read

The fundamental unit of a neural network:

a=σ(z)=σ(wx+b)a = \sigma(z) = \sigma(\mathbf{w}^\top\mathbf{x} + b)
  1. Linear transformation: z=wx+bz = \mathbf{w}^\top\mathbf{x} + b — weighted sum of inputs plus bias
  2. Nonlinear activation: a=σ(z)a = \sigma(z) — applies an activation function

Without the nonlinearity, stacking layers would collapse to a single linear transformation (composition of linear maps is linear). The activation function is what makes depth useful.

A single neuron with sigmoid activation = Logistic Regression.

Multi-layer perceptron (MLP): stack layers of neurons:

h1=σ(W1x+b1)\mathbf{h}_1 = \sigma(W_1\mathbf{x} + \mathbf{b}_1) h2=σ(W2h1+b2)\mathbf{h}_2 = \sigma(W_2\mathbf{h}_1 + \mathbf{b}_2) y^=W3h2+b3\hat{y} = W_3\mathbf{h}_2 + \mathbf{b}_3

Universal approximation theorem: a single hidden layer with enough neurons can approximate any continuous function. But depth is more parameter-efficient than width in practice.

Batched form: in practice a whole batch of mm inputs is processed at once by stacking them as rows of XRm×dinX \in \mathbb{R}^{m \times d_\text{in}}, so a layer is H=f(XW+b)H = f(XW + \mathbf{b}) with WRdin×doutW \in \mathbb{R}^{d_\text{in} \times d_\text{out}} and b\mathbf{b} broadcast across rows.

PyTorch detail: nn.Linear stores its weight as dout×dind_\text{out} \times d_\text{in} and computes X @ W.T. The transpose is free (it only changes the stride), and storing it this way makes the gradient L/W\partial L/\partial W come out already shaped like WW.

Parameters per layer: for input dim dind_\text{in}, output dim doutd_\text{out}: din×doutd_\text{in} \times d_\text{out} weights + doutd_\text{out} biases.

See also: Activation Functions, Backpropagation, Loss Functions

Linked from