📘 CodingMarble Learn

Neural Networks and Deep Learning

A neural network is a computer model made of many small units called artificial neurons. Each neuron multiplies its inputs by weights, adds them with a bias and passes the sum through an activation function. Neurons are arranged in layers: input, hidden and output. The network learns by training: it makes a guess, measures the error with a loss function, and changes the weights backwards (backpropagation with gradient descent) so the error becomes smaller. Networks with many hidden layers are called deep learning. CNNs are good at images, RNNs at sequences like text and speech.

🎬 Step-by-step story

  1. Meet one artificial neuron. Each input x is multiplied by a weight w. The neuron adds these up and adds a bias b.
  2. The sum goes into an activation function. A small sum keeps the neuron quiet. A big sum makes it fire.
  3. Many neurons side by side make a layer. Input layer, hidden layers, output layer: that is a neural network.
  4. Training: data flows forward, we measure the error, then we nudge every weight backwards to cut the error. Repeat many times.
  5. Deep learning uses many layers. A CNN slides a small filter over a picture. An RNN remembers what came before.
  6. Free play: move the sliders for inputs, weights and bias. Find a setting where the neuron fires.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Is an artificial neuron really like a brain cell?

Only loosely. It copies the idea "add up signals, fire if strong enough", but it is just multiplication and addition.

What does the bias do if we already have weights?

The bias moves the firing point. Even with all inputs zero, the bias decides whether the neuron starts on or off. Try the bias slider in free play.

Why not just output the sum z directly?

Then the whole network would be one straight-line rule. The activation curve in step 2 adds the bend that lets networks learn complex things.

What is actually 'hidden' in hidden layers?

Nothing secret: we just do not see their values in the input or output. They hold the patterns the network found.

How does the network know which weight to change?

Backpropagation measures how much each weight added to the error and changes the guilty ones most (red pulses going back in step 4).

Why does a CNN use a small filter instead of looking at the whole image?

The same small filter is reused at every place, so it finds an edge anywhere with very few weights. Watch the yellow 3×3 window slide in step 5.

From brain cells to artificial neurons

Your brain has billions of nerve cells. Each one receives signals, and if the total signal is strong enough, it sends a signal on. Computer scientists copied this idea (not the biology) to make an artificial neuron.

The very first model of this kind, the perceptron (1958), used a simple yes/no rule: output 1 if z ≥ 0, otherwise 0.

Activation functions: when does a neuron fire?

Without an activation function, a network could only draw straight lines. Activation adds a bend, so the network can learn curved, complex patterns.

Layers: input, hidden and output

Neurons are arranged in layers. The input layer just holds the data (for a 28 × 28 picture, 784 numbers). The hidden layers find patterns: early ones notice simple things like edges, later ones combine them into shapes. The output layer gives the answer, for example 10 neurons for the digits 0–9.

If every neuron in one layer connects to every neuron in the next, the layer is fully connected (dense). The number of weights between a layer of 3 and a layer of 4 is 3 × 4 = 12, plus 4 biases.

How a network learns: loss, backpropagation and gradient descent

  1. Forward pass: put an example in, let the numbers flow to the output.
  2. Loss: compare the output with the correct label. The loss is a number that is big when the guess is bad.
  3. Backpropagation: work backwards from the output to find how much each weight caused the error.
  4. Gradient descent: change each weight a small step in the direction that lowers the loss. The step size is the learning rate.
  5. Repeat for all examples many times. One full pass over the training data is an epoch.

Too few examples or too many epochs can cause overfitting: the network memorises the training data and does badly on new data. That is why we keep a separate test set.

Deep learning: CNN, RNN and frameworks

Deep learning means neural networks with many hidden layers, trained on large data with fast chips (GPUs).

Try it: be a neuron with paper and pencil

Decide whether to go out to play. Inputs: x₁ = 1 if it is sunny, x₂ = 1 if homework is done. Weights: w₁ = 2, w₂ = 3. Bias b = −4. Rule: fire (go out) if z ≥ 0.

Now change the bias to −1 and test again. Then open free play in the 3D above and do the same with sliders.

Key formulas and definitions

Worked examples

1. A neuron has inputs x₁ = 2, x₂ = 1, weights w₁ = 0.5, w₂ = −1 and bias b = 0.5. Find z and the ReLU output.

z = 0.5×2 + (−1)×1 + 0.5 = 1 − 1 + 0.5 = 0.5. ReLU(0.5) = 0.5.

2. A step neuron fires if z ≥ 0. Inputs (1, 1), weights (1, 1), bias −1.5. Does it fire? What does this neuron compute?

z = 1 + 1 − 1.5 = 0.5 ≥ 0 → fires. With (1,0) or (0,1): z = −0.5 → no; (0,0): z = −1.5 → no. It fires only when both inputs are 1: it acts as an AND gate.

3. How many weights and biases does a fully connected network 4 → 5 → 3 have?

Weights: 4×5 + 5×3 = 20 + 15 = 35. Biases: one per non-input neuron = 5 + 3 = 8. Total parameters = 43.

4. A weight is 0.8. The slope of the loss for this weight is 2 and the learning rate is 0.1. Find the new weight.

new w = 0.8 − 0.1 × 2 = 0.6. The weight moves down because increasing it would raise the loss.

5. A 3×3 filter slides one step at a time over a 6×6 image with no padding. What size is the feature map?

Positions in each direction = 6 − 3 + 1 = 4. Feature map = 4 × 4 (as in the 3D, step 5).

6. Find the sigmoid output when z = 0 and when z is very large.

σ(0) = 1 ÷ (1 + 1) = 0.5. For very large z, e^(−z) ≈ 0, so σ ≈ 1. Sigmoid always stays between 0 and 1.

Common mistakes

Practice quiz

1. What does a weight in a neural network show?
2. Which layers find patterns between input and output?
3. Backpropagation is used to:
4. Which network is best for images?
5. ReLU(−3) equals:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a neural network in simple words?

A program made of many tiny calculators (neurons) in layers. Each multiplies inputs by weights and adds them; the network learns by adjusting the weights until its answers are right.

What is the difference between machine learning and deep learning?

Deep learning is a type of machine learning that uses neural networks with many hidden layers and lots of data.

What is the difference between CNN and RNN?

A CNN uses sliding filters and is best for images; an RNN has a loop with memory and is best for sequences such as text and speech.

Where this is taught

CBSE (India)Class 12Understanding Neural Networks
South Korea고등학교 2학년AI and learning
China高三Sel.4 Introduction to AI

Learn first

Learn next

Related lessons

All Computer Science lessons