The fundamental unit of a neural network:
- Linear transformation: — weighted sum of inputs plus bias
- Nonlinear activation: — 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:
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 inputs is processed at once by stacking them as rows of , so a layer is with and broadcast across rows.
PyTorch detail: nn.Linear stores its weight as and computes X @ W.T. The transpose is free (it only changes the stride), and storing it this way makes the gradient come out already shaped like .
Parameters per layer: for input dim , output dim : weights + biases.
See also: Activation Functions, Backpropagation, Loss Functions