Home / Deep Learning

Neural Network Visualizer

By Updated

Interactive architecture builder. Drag to pan, scroll to zoom, right-click to edit.

Overview

One layer, written out

Each layer takes the previous layer's output and applies

a(l) = f(W(l) a(l−1) + b(l))

where W is a weight matrix, b is a bias vector, and f is the activation. Stack these and the network can represent increasingly complex functions — but only because f is non-linear. Remove it and the whole stack collapses into a single matrix.

Analysis

Layers -
Neurons -
Total Params -

Selection

Hover over nodes for details.

Neural Network Visualizer: A Practical Guide

A neural network is one operation repeated: multiply by a matrix, add a bias, bend the result. Depth is just how many times you do it.

Counting the parameters

Take 4 input features → one hidden layer of 8 → 3 output classes.

  • Input to hidden: 4 × 8 = 32 weights, plus 8 biases = 40
  • Hidden to output: 8 × 3 = 24 weights, plus 3 biases = 27
  • Total: 67 learnable parameters

Add a second hidden layer of 8 and you insert another 8 × 8 + 8 = 72 — more than doubling the model. Parameter count grows with the product of adjacent layer widths, which is why wide layers next to each other get expensive fast.

Why stacking layers buys anything

A layer computes a weighted sum and applies an activation. Stack two linear layers and you have gained nothing at all: the composition of two matrix multiplications is another matrix multiplication, so a hundred linear layers collapse to a single equivalent one.

The activation is what breaks that collapse. Because it is non-linear, the composition cannot be flattened, and each additional layer can express something the previous one could not. This is the entire reason depth exists — remove the activations and a deep network is exactly as powerful as logistic regression, however many layers it has.

What the hidden layers represent

The universal approximation theorem says one sufficiently wide hidden layer can approximate any continuous function to arbitrary accuracy. That is reassuring and almost useless in practice, because “sufficiently wide” can mean exponentially many neurons.

Depth is what makes it tractable. Layers build features hierarchically: in a vision network the first layer responds to edges, the second to corners and textures assembled from those edges, the third to object parts, and so on. Each layer reuses the previous layer’s features rather than rediscovering them, so a deep network needs far fewer neurons than a shallow one to express the same function.

Choosing width and depth

There is no formula, but there are reliable starting points. Begin with one or two hidden layers for tabular data; deeper networks rarely help there and images or sequences are better served by architectures designed for them. Set the width somewhere between the input and output sizes, and prefer a rough funnel — wider near the input, narrowing toward the output.

Then let the training curves decide. If the model cannot drive training loss down it lacks capacity, so widen or deepen it. If training loss is near zero while validation loss climbs, it has too much capacity for the data available, and the answer is regularisation or more data rather than a smaller network. Increase capacity until the model can overfit, then regularise back — that order is far more reliable than guessing an architecture up front.

Layers of weighted sums, with a bend between them

A neural network is a chain of very simple operations. Each layer takes a vector of numbers, multiplies it by a matrix of weights, adds a bias, and pushes the result through a non-linear function.

a(1) = f(W(1)x + b(1))  →  a(2) = f(W(2)a(1) + b(2))  →  …

That is the whole forward pass. A network with 175 billion parameters is doing exactly this, many times.

The three parts of the architecture:

  • Input layer — one unit per feature. Not really a layer; it holds the data.
  • Hidden layers — where the representation is built. "Deep" simply means more than one or two.
  • Output layer — one unit per class for classification, one for a single regression target.

Why the non-linearity is the whole point

Remove the activation function and stack two layers: W₂(W₁x) = (W₂W₁)x. That is a single matrix. A hundred stacked linear layers can express exactly what one can — a straight boundary.

Insert a non-linear bend between them, and the layers stop collapsing. Each one can reshape the space the next one sees, so the network can represent curves, corners and disjoint regions.

This is the answer to "why not just use one very wide layer?" The universal approximation theorem says one hidden layer, made wide enough, can approximate any continuous function. In practice depth is dramatically more efficient: a function that needs an exponentially wide shallow network can often be represented by a narrow deep one, because layers compose features rather than enumerating them.

What each layer learns

The layers build a hierarchy, and it is visible when you inspect trained networks.

DepthOn imagesOn text
Layer 1Edges, colour blobsCharacter and word shapes
MiddleTextures, partsPhrases, syntax
DeepObjectsMeaning, topic, intent

This is why you cannot usefully read a single weight in a deep network: a feature's influence is spread across many paths, and the meaningful units are combinations rather than individual neurons.

It is also why transfer learning works. Early layers learn primitives that apply to almost any task in the domain, so they can be reused; only the last layers are specific to the original labels.

Training, in four steps

  1. Forward pass. Push a batch through the network and get predictions.
  2. Loss. Compare predictions with the truth, producing one number.
  3. Backward pass. Compute how much each weight contributed to that number — the chain rule, applied backwards.
  4. Update. Nudge every weight against its gradient, scaled by the learning rate.

Repeat for every batch, for many epochs. Nothing else happens. Everything else in deep learning — optimisers, normalisation, schedules, regularisation — is a refinement of one of those four steps.

Try this above

  1. Set Input Features to 4, one Hidden Layer of 8, and Output Classes to 3, then count the connections against the arithmetic above.
  2. Add a second hidden layer and watch the connection count jump rather than creep.
  3. Widen one hidden layer and note that the layers on both sides of it grow, because it participates in two weight matrices.

What usually goes wrong

Depth without non-linearity. Stacking linear layers gains you nothing at all mathematically — it is the single most common misunderstanding about why deep networks work.A first hidden layer far wider than the input. Four inputs into a 512-unit layer adds thousands of parameters without adding any information; there were only ever four numbers to work with. Width is worth adding where there is signal to spread out, not at the front by default.

In one line

Multiply, add a bias, bend — repeated, with the bend being the part that matters.

The choices you actually make

DecisionTypical answer
Hidden layersStart with 2–3 for tabular data; use a proven architecture for images or text
Units per layer64–512, often narrowing towards the output
Hidden activationReLU, or GELU in transformers
Output activationNone for regression, softmax for multi-class, sigmoid for multi-label
LossMSE for regression, cross-entropy for classification
OptimiserAdamW
Learning rate1e-3 for Adam, then tune — the most important hyperparameter
Batch size32–256, as large as memory allows
RegularisationWeight decay, dropout, early stopping

Two notes on that table. The output layer usually has no activation in modern frameworks, because the loss function applies softmax or sigmoid internally in a numerically stable way — applying it twice is a real and quiet bug. And the learning rate deserves its label: it affects results more than the number of layers, the width, or the choice of optimiser.

When a neural network is the wrong tool

Deep learning is not the default answer to a modelling problem. It wins decisively on unstructured data — images, audio, text, video — where the raw input has spatial or sequential structure a network can exploit.

On tabular data, gradient-boosted trees usually match or beat a neural network while needing less tuning, less data and no GPU. This has been tested repeatedly and the result is consistent.

Three other reasons to look elsewhere: you have a few hundred rows, you need to explain each decision to a regulator, or you need the model to extrapolate outside the range it was trained on.

Common mistakes

  • Forgetting to scale the inputs. Networks assume roughly unit-scale features; unscaled columns make the first layer's activations enormous and training unstable.
  • Applying softmax in the model and again in the loss. Trains slowly, silently.
  • A learning rate that is wrong by an order of magnitude. Too high diverges to NaN; too low crawls. Find it with a short learning-rate sweep.
  • No validation set, so overfitting is invisible until deployment.
  • Too big a model for the data. With a few thousand rows, a smaller network plus regularisation beats a larger one.
  • Not shuffling the training data, so batches contain one class at a time and batch normalisation's statistics become meaningless.

A whole network, forty lines, no framework

Two layers, a forward pass, a backward pass and a training loop -- on a problem a linear model cannot touch. Everything a framework does is here, just written out.

example_01.pyNumPy
Output

Questions people ask

How many layers should I use? For tabular data, two or three. For images and text, start from a proven architecture rather than designing one.

What is an epoch? One full pass through the training data. Batches are the chunks within it, and one update happens per batch.

Why does my loss go to NaN? Learning rate too high, a log(0) in the loss, or unscaled inputs. Check in that order.

Do I need a GPU? For images and text, effectively yes. For small tabular models, a CPU is fine.

How much data do I need? Thousands of examples per class as a rough floor, and far fewer if you fine-tune a pretrained model.

Why is it called a "neuron"? Historical analogy to biology. The resemblance is loose; a unit is a weighted sum with a threshold, not a cell.

Recap in one screen

  • Each layer is a matrix multiply, a bias, and a non-linear function.
  • Without the non-linearity, any number of layers collapses into one.
  • Layers build a hierarchy of features, which is why depth and transfer learning both work.
  • Training is forward pass, loss, backward pass, update — repeated.
  • Excellent on images, audio and text; usually beaten by boosted trees on tabular data.

Check yourself

0 of 3

Answer without scrolling back up.

  1. What do the hidden layers of a network actually do?

  2. Widening a layer from 64 to 512 units mainly increases:

  3. All weights are initialised to exactly zero. What happens?

Cheat sheet

Neural Network Visualizer

where W is a weight matrix, b is a bias vector, and f is the activation. Stack these and the network can represent increasingly complex functions — but only because f is non-linear. Remove it and the whole stack collapses into a single matrix.

DEEP LEARNING · vizlearn.in/deep_learning/neural_network.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.