Neural Networks: From a Single Neuron to Attention
A visual guide to how neural networks learn, why deep models need shortcuts, and how the Transformer uses attention to work with language.
By Sam Zhong
A neural network can look like a wall of circles, arrows, and unfamiliar terms. The useful story is simpler: it turns inputs into a prediction, checks how wrong that prediction was, and adjusts itself. A neural networks cheat sheet helped me connect that basic loop to the Transformer described in Attention Is All You Need.
This is a visual tour rather than a derivation. I have cropped the diagrams directly from the supplied cheat sheet so each one sits beside the idea it explains.
Start with one neuron
A neuron receives several inputs, gives each one a weight, adds a bias, and passes the result through an activation function. Think of the weights as adjustable dials: they control which signals matter most. The activation lets the network represent patterns more flexible than a stack of purely linear calculations.

Connect many neurons in layers and the output of one layer becomes the input to the next. The early layers can learn simple patterns; later layers can combine those patterns into more useful features. For an image, that might progress from edges to shapes. For language, it might progress from token relationships to a representation useful for a prediction.
Learning happens in two directions
On the forward pass, information moves from input to prediction. A loss function compares that prediction with the desired answer. On the backward pass, backpropagation calculates how each weight contributed to the loss. An optimizer then changes the weights a little, and the cycle repeats with more examples.

The learning rate controls the size of each update. Too large and training can jump past a good solution; too small and progress can crawl. Optimizers such as Adam adjust the update using a history of gradients, but they still depend on the same forward, compare, and update loop.
Why deeper networks need shortcuts
As a network grows deeper, the learning signal can become extremely small or large on its way backward. That makes early layers slow to learn or training unstable. Sensible weight initialization, normalization, and gradient clipping all help. A particularly useful idea is a residual connection: let information skip over a block and add it back to the block's output.

The block can learn a useful change to the input while the shortcut preserves an easier path through the model. This idea appears again in the Transformer diagram below.
From sequences to attention
Older sequence models such as recurrent neural networks read tokens one after another, carrying a running summary forward. That design makes long-range relationships hard to retain and limits how much work can be done in parallel. Attention offers a different way to connect positions: a token can weigh information from other relevant tokens directly.

At the bottom, embeddings turn tokens into vectors, and positional information tells the model where the tokens occur. The encoder uses self-attention to connect input positions. The decoder uses masked self-attention for the output generated so far, then cross-attention to read the encoder's output. The feed-forward blocks process each position, while the “Add & Norm” paths include the residual shortcuts discussed above.
The paper's title emphasizes attention, but the architecture also relies on embeddings, position information, feed-forward layers, and normalization. Modern language models often use only part of this original layout: for example, many text generators use a decoder-style stack.
What an attention head does
A token forms a query describing what it is looking for. Other tokens provide keys that can match that query and values that carry information forward. A head gives more weight to the values at positions that match well. Several heads work in parallel, giving the model multiple ways to relate positions before their results are combined.

The heads are learned, so it is tempting to assign each one a tidy role such as “grammar” or “meaning.” In a real model, their behavior can be mixed and is not guaranteed to match a human label.
Why the decoder cannot peek ahead
When generating text, the model should predict the next token using only the tokens available so far. A causal mask blocks attention to future positions. In the diagram, the allowed cells form a triangle: each row can look left and at itself, but not to the right.

This is how an attention-based decoder can learn from full training sequences while still obeying the same no-peeking rule it faces when it generates one token at a time.
The big picture
The same training loop runs through this entire story. Neurons combine signals; layers turn them into useful representations; backpropagation adjusts the weights; residual paths help deep models train; and attention lets tokens draw on context from other positions. The Transformer packages those pieces into a design that made sequence modeling much more parallel and became a foundation for later language models.
If you want to go one level deeper, start with the architecture figure here and read the introduction and model architecture sections of Attention Is All You Need. The diagrams above provide a map for the paper's terminology without requiring all of its math on a first pass.