๐ Neural Networks
Descriptionโ
< What is it? >โ
A neural network is a function built by composing many small units โ neurons โ arranged in layers. Each neuron does the same two things: combine its inputs linearly, then pass the result through a non-linear activation. Stacking those layers lets the network approximate mappings that no single linear model can express.
wโ
xโ โโโโโโโโโ
wโ โ
xโ โโโโโโโโโผโโโถ z = ฮฃ wแตขxแตข + b โโโถ a = f(z) โโโถ to the next layer
wโ โ (linear) (activation)
xโ โโโโโโโโโ
b (bias)
- Bionics
- 1 hidden layer neural network


Training adjusts the weights and biases; the structure and the choice of activation stay fixed.
Key pointsโ
< Neurons and connections >โ
A neuron holds no data of its own โ it is a rule for turning a vector of inputs into one number. A connection carries the output of one neuron to the input of another, and every connection has a weight attached to it. In a fully connected layer, every neuron in layer connects to every neuron in layer , so a layer with inputs and outputs has connections.
< Weights and biases >โ
The weight on a connection says how strongly that input pushes the neuron's output up or down; a weight near zero makes the input irrelevant. The bias is an input-independent offset that shifts the neuron's threshold, letting it fire even when every input is zero.
Together they are the network's trainable parameters. A layer collects them into a matrix and a vector :
Their starting values matter โ see Weight Initialization.
< Propagation function: the linear part >โ
The propagation function is what aggregates a neuron's incoming signals into a single pre-activation value . In practice it is the weighted sum plus bias, which for a whole layer is one matrix multiply:
where is the previous layer's output and , the input. This is a linear function of the inputs (affine, once the bias is included): scaling an input scales its contribution proportionally, and contributions add.
< Activation function: the non-linear part >โ
The activation function maps the pre-activation to the neuron's output:
It is applied element-wise, so it changes each value's shape but not the layer's dimensions.
| Activation | Formula | Typically used for |
|---|---|---|
| ReLU | Default for hidden layers โ cheap, and its gradient does not saturate for | |
| GELU | Hidden layers in transformers | |
| Sigmoid | A single output squashed to for binary classification | |
| Tanh | Outputs centred on zero, common in older recurrent networks | |
| Softmax | An output layer producing a distribution over classes |
< Why the non-linearity is required >โ
Without , depth buys nothing. Two stacked linear layers collapse into one:
which is just another affine map. The activation is what makes a deep network more expressive than a single layer. Its derivative also decides how well gradients survive the trip back through many layers โ see Vanishing & Exploding Gradients.
< In PyTorch >โ
import torch.nn as nn
model = nn.Sequential(
nn.Linear(784, 128), # W and b: the propagation function
nn.ReLU(), # f: the activation function
nn.Linear(128, 10), # output layer โ logits, softmax folded into the loss
)
nn.Linear(n, m) allocates the weight matrix and bias vector; nn.ReLU() has no parameters at all.
< Related ideas >โ
- Feed Forward Network is the simplest arrangement of these layers.
- Backpropagation computes how the loss changes with each weight and bias.
- Gradient Descent uses those gradients to update them.