CadetX
CX Learn | Complete Neural Networks Guide
TensorFlow · Keras
CadetX logo CadetX CX Learn
NN-101 · Module 1 Beginner about 30 minutes 11 Lessons Prereq: basic Python; our Machine Learning track helps

Introduction to Neural Networks

← →

Neural networks are the technology behind face unlock, voice assistants, language translation and chatbots like ChatGPT and Claude. They're built from simple pieces, loosely inspired by the brain. This module explains what they are and how they work, in plain English.

  • Level: Beginner
  • Time: about 30 minutes
  • Needs: basic Python; our Machine Learning track helps

By the end of this module you will be able to

  • Explain what a neural network is in one simple sentence
  • Describe how an artificial neuron works: inputs, weights, bias and activation
  • Name the layers of a network and explain what makes it "deep"
  • Describe the training loop in simple terms
  • Explain why neural networks took off when they did
  • Name the main types of network and what each is good at
  • Know when to use a neural network, and when not to
  • Train your first neural network in Python

1.1What is a neural network?

Your brain contains around 86 billion tiny cells called neurons. Each one is very simple: it receives signals from other neurons and decides whether to pass a signal on. But connected together in huge numbers, they let you recognise faces, understand speech and learn new skills.

A neural network borrows that idea. It's made of lots of simple "artificial neurons", each doing a small calculation, connected together in layers. On its own, one artificial neuron can't do much. Thousands or millions of them working together can learn to recognise images, understand language and much more.

A neural network in one sentence

A neural network is a machine learning model made of layers of connected artificial neurons that learns patterns from examples by adjusting the strength of its connections.

An important reality check

Neural networks are inspired by the brain, but they are not artificial brains. A real neuron is enormously complicated; an artificial one is a few lines of maths. It's a bit like how aeroplanes were inspired by birds, but don't flap their wings.

1.2Where neural networks fit

If you've taken our Machine Learning track, you'll remember this picture. Neural networks sit at the heart of deep learning, which is a branch of machine learning.

Nested circles: artificial intelligence contains machine learning, which contains deep learning. Neural networks are the engine of deep learning.Artificial intelligenceMachines that act smartMachine learningLearns from data (our Machine Learning track)Deep learningPowered by neural networksThis track
Figure 1. Deep learning is machine learning using neural networks with many layers. Everything you learned about data, training, testing and overfitting in the Machine Learning track still applies here.
You already know (Machine Learning track)What's the same with neural networks
Features, labels, training and test dataExactly the same
Supervised learning: regression and classificationNeural networks do both
Linear and logistic regressionA single neuron is almost identical to them
Gradient descent: small steps downhill to reduce the errorThis is how neural networks learn
Overfitting, cross-validation and evaluation measuresJust as important, maybe more so

1.3The artificial neuron

Left: a brain cell receives signals through dendrites, processes them in the cell body and sends a signal down the axon. Right: an artificial neuron receives numbers as inputs, multiplies them by weights, adds them up and passes the result through an activation function to produce an output.A brain neuronDendritesCell bodyAxonSignals in → decide → signal outAn artificial neuronx₁x₂x₃w₁w₂w₃ΣyInputsWeightsAdd upActivate
Figure 2. A brain neuron collects signals, decides whether they're strong enough, and fires. An artificial neuron does the same with numbers: it multiplies each input by a weight, adds them up, and passes the total through an activation function.

An artificial neuron does four simple things:

StepWhat happensIn plain English
1. Take inputsReceives some numbers (x₁, x₂, x₃…)The information it's given
2. Weight themMultiplies each input by its own weight (w₁, w₂, w₃…)How much each piece of information matters. A negative weight means "this counts against"
3. Add up, plus a biasAdds everything together, plus a number called the biasThe bias is its starting mood: how easy or hard it is to convince
4. ActivatePasses the total through an activation functionTurns the total into the final output, such as a score between 0 and 1
output = activation( w₁×x₁ + w₂×x₂ + w₃×x₃ + bias )

If that looks familiar, it should. With the sigmoid activation, a single neuron is exactly the logistic regression model from Module 4 of the Machine Learning track. A neural network is, in a sense, lots of small logistic regressions stacked together.

Let's make it real. Imagine one neuron deciding: "Should I go to the park?"

Try it: build a neuron

Switch the inputs on and off, then change the weights and bias to see how the neuron's decision changes.

Bias
Output after the sigmoid activation (0 = no, 1 = yes)

Here's the key question: who chooses the weights and bias? In the lab, you did. In a real neural network, the network learns them from examples. That's what training means. You'll see how in lesson 1.5.

1.4From one neuron to a network

One neuron can only draw a straight-line boundary, just like logistic regression. The power comes from connecting many neurons in layers, where each layer's outputs become the next layer's inputs.

A neural network with an input layer of 3 neurons, two hidden layers of 4 neurons each, and an output layer of 2 neurons. Every neuron is connected to every neuron in the next layer.Input layerHidden layer 1Hidden layer 2Output layerSizeRoomsAreaBuySkipHidden layers: where the "thinking" happens
Figure 3. A small network deciding whether to buy a house. Information flows from left to right. Each line is a connection with its own weight, and each circle is a neuron with its own bias. This tiny network already has 46 weights and biases to learn.
LayerWhat it does
Input layerReceives the features: one neuron per feature (for an image, one per pixel). It doesn't calculate anything; it just passes the numbers in
Hidden layersWhere the learning happens. Each layer combines the patterns found by the layer before into more complex patterns. They're "hidden" because we never see their outputs directly
Output layerGives the final answer: one neuron for a yes/no or a number, or one per class (such as 10 for the digits 0 to 9)

What makes a network "deep"?

A network with several hidden layers is called a deep neural network, and training one is called deep learning. Modern networks can have dozens or even hundreds of layers and billions of weights.

Why layers help: recognising a face

In a network that recognises faces, the first hidden layers learn to spot simple things like edges and colours. The next layers combine edges into shapes: curves, corners and circles. Deeper layers combine shapes into parts: eyes, noses and mouths. The last layers combine parts into whole faces. Nobody programs these steps; the network discovers them during training.

1.5How a neural network learns

A new network starts with random weights, so its first predictions are pure guesses. Training improves them step by step, using a loop you'll recognise from the Machine Learning track:

The training loop: make a prediction, measure the error with a loss function, work out which weights to blame using backpropagation, adjust the weights using gradient descent, and repeat thousands of times.1. PredictData flows forward2. Measure the errorLoss function3. Find who to blameBackpropagation4. Adjust the weightsGradient descentRepeat thousandsof times
Figure 4. The training loop. Each trip round the loop nudges thousands of weights a tiny amount in the direction that reduces the error.
StepNameWhat it means
1Forward passFeed an example in; the numbers flow through the layers to produce a prediction
2LossA single number measuring how wrong the prediction was (like log loss from the ML track)
3BackpropagationWorks backwards through the network to find how much each weight contributed to the error
4Gradient descentNudges every weight a little in the direction that reduces the loss

One pass through the whole training dataset is called an epoch. Training usually takes many epochs. You'll learn exactly how backpropagation and gradient descent work in Modules 4 and 5.

Like tuning a huge mixing desk

Imagine a sound engineer with a mixing desk of 10,000 sliders, trying to make a song sound right. After each play, a listener says how far off it sounds (the loss). Backpropagation tells the engineer which sliders caused the problem, and gradient descent moves each of those sliders a tiny amount. After thousands of plays, the song sounds right. The sliders are the weights.

1.6A short history: why now?

Neural networks aren't new. The first ideas date from the 1940s. So why did they only change the world in the last 15 years?

Timeline of neural networks: 1943 first model of a neuron; 1958 the perceptron; 1969 an AI winter; 1986 backpropagation popularised; 2012 deep learning wins the ImageNet competition; 2017 the Transformer; 2022 ChatGPT released.1943First maths model of a neuronWarren McCulloch and Walter Pitts1958The perceptron: the first neuron that could learnFrank Rosenblatt1969Its limits are exposed, and an "AI winter" followsMarvin Minsky and Seymour Papert1986Backpropagation popularised, so deeper networks can learnDavid Rumelhart, Geoffrey Hinton and Ronald Williams2012Deep learning wins the ImageNet image competitionAlexNet, trained on GPUs2017The Transformer is introduced"Attention Is All You Need"2022ChatGPT brings large language models to the publicBuilt on Transformers
Figure 5. Neural networks went through cycles of excitement and disappointment for decades before deep learning took off after 2012.

Three things finally came together:

IngredientWhat changed
DataThe internet, smartphones and digital records created huge collections of labelled images, text and audio to learn from
Computing powerGraphics cards (GPUs), built for video games, turned out to be brilliant at the maths neural networks need, making training many times faster
Better methodsImprovements such as better activation functions, dropout and new designs like the Transformer made deep networks much easier to train

1.7The main types of neural network

Different kinds of data need different network designs, called architectures. You'll learn each of these later in this track.

TypeBest forHow it works, in one lineExample
Feedforward network (MLP)Tables of numbersLayers of fully connected neurons, information flows one wayPredicting house prices or churn
Convolutional network (CNN)Images and videoScans small patches of an image to spot local patterns like edgesFace unlock, reading medical scans
Recurrent network (RNN, LSTM)SequencesHas a "memory" that carries information from one step to the nextSpeech, sensor readings, older translation systems
TransformerLanguage, and increasingly everythingUses "attention" to decide which parts of the input matter most to each otherChatGPT, Claude, Google Translate

1.8When to use a neural network (and when not to)

Neural networks are powerful, but they're not always the best tool. As you saw in the Machine Learning track, for data in rows and columns, gradient boosting often wins.

Use a neural networkUse traditional ML (e.g. gradient boosting)
Type of dataImages, audio, text, video ("unstructured" data)Spreadsheets and database tables ("structured" data)
Amount of dataLots: thousands to millions of examplesWorks well with hundreds to thousands
Computing powerOften needs GPUs and longer trainingA normal laptop is usually fine
Need to explain decisions?Harder: often called a "black box"Easier, especially for simpler models
Feature engineeringLearns useful features by itself from raw dataUsually needs you to design good features

The biggest advantage

Traditional models need people to decide which features matter. For an image, what would you even give them? A neural network can take in raw pixels, raw sound or raw words and learn useful features by itself. That's why it transformed computer vision and language.

1.9Neural networks in your everyday life

Where you see itWhat the network doesType
Face unlockChecks that the face in front of the camera is yoursCNN
Voice assistantsTurns your speech into text, then works out what you meanTransformer
Google TranslateTranslates whole sentences between languagesTransformer
ChatGPT and ClaudeUnderstands and writes text by predicting the next wordTransformer
Photo appsFinds all your photos of dogs, beaches or a particular personCNN
HospitalsHelps doctors spot signs of disease on X-rays and scansCNN
Self-driving researchRecognises cars, people and road signs from camerasCNN and Transformer

1.10Your first neural network in Python

Later in this track you'll use dedicated deep learning libraries. To start, scikit-learn has a simple neural network called MLPClassifier (MLP stands for "multi-layer perceptron", another name for a feedforward network). Let's teach it to read the handwritten digits you may remember from the Machine Learning track.

first_network.py
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.neural_network import MLPClassifier

# 1. The data: 1,797 handwritten digits, each 8x8 = 64 pixels
X, y = load_digits(return_X_y=True)
X = MinMaxScaler().fit_transform(X)          # pixel values from 0 to 1
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, random_state=42, stratify=y)

# 2. Build a network: 64 inputs -> 32 neurons -> 16 neurons -> 10 outputs
net = MLPClassifier(hidden_layer_sizes=(32, 16),
                    max_iter=1000, random_state=42)

# 3. Train it: guess, measure the error, adjust the weights, repeat
net.fit(X_train, y_train)
for epoch in [1, 5, 20, 50, 100]:
    print(f"Epoch {epoch:3}: loss = {net.loss_curve_[epoch - 1]:.3f}")

# 4. Test it on digits it has never seen
print("Test accuracy:", round(net.score(X_test, y_test), 3))

# 5. How many weights did it learn?
n_weights = sum(w.size for w in net.coefs_) + sum(b.size for b in net.intercepts_)
print("Weights and biases learned:", n_weights)
print("Prediction for the first test digit:", net.predict(X_test[:1])[0],
      "| Real answer:", y_test[0])
Output
Epoch   1: loss = 2.338
Epoch   5: loss = 2.105
Epoch  20: loss = 0.925
Epoch  50: loss = 0.186
Epoch 100: loss = 0.069
Test accuracy: 0.973
Weights and biases learned: 2778
Prediction for the first test digit: 1 | Real answer: 1
Training loss of the digit network over 312 epochs. It starts at about 2.3, drops sharply between epochs 5 and 50, and flattens out close to zero.00.511.522.5150100150200250300Random guessing at the startLoss close to zero: the network has learnedEpoch (one full pass through the training data)Loss (error)
Figure 6. The real training loss from this code. At first the network is just guessing. Around epoch 20 it starts to "get it", and by epoch 100 the loss is close to zero. It stopped by itself after 312 epochs, once it had stopped improving.

What the output tells us

  • The network has 4 layers: 64 inputs (one per pixel), two hidden layers of 32 and 16 neurons, and 10 outputs (one per digit).
  • The loss falls from 2.34 (random guessing) to 0.07 as the weights are adjusted epoch after epoch.
  • 97.3% test accuracy on digits it has never seen, from a network that started out knowing nothing.
  • It learned 2,778 weights and biases by itself. Nobody told it what a "7" looks like.

Where to run this

You can run this code in any Python environment with scikit-learn installed, such as Jupyter Notebook or Google Colab. It trains in a few seconds on a normal laptop.

SummaryKey takeaways

  • A neural network is made of layers of simple, connected artificial neurons, loosely inspired by the brain.
  • Each neuron multiplies its inputs by weights, adds a bias, and applies an activation function.
  • A single sigmoid neuron is the same as logistic regression.
  • Networks have an input layer, hidden layers and an output layer. Several hidden layers make it deep.
  • Training repeats: forward pass → loss → backpropagation → gradient descent, over many epochs.
  • Deep learning took off thanks to big data, GPUs and better methods.
  • Main types: feedforward (tables), CNNs (images), RNNs (sequences) and Transformers (language).
  • Use neural networks for images, audio and text with lots of data; for tables, gradient boosting is often better.

Check your understanding

Your neural networks roadmap

  1. 01
    Introduction to Neural NetworksYou are here
  2. 02
    The Perceptron and the Artificial NeuronBuild a single neuron from scratch
  3. 03
    Activation FunctionsSigmoid, tanh, ReLU and softmax
  4. 04
    Loss Functions and Gradient DescentHow networks measure and reduce error
  5. 05
    BackpropagationHow every weight learns its share of the blame
  6. 06
    Building Networks with KerasYour first deep learning library
  7. 07
    Training Better NetworksOverfitting, dropout, batch normalisation, early stopping
  8. 08
    Convolutional Neural NetworksTeaching computers to see
  9. 09
    Recurrent Neural Networks and LSTMsWorking with sequences
  10. 10
    Transformers and AttentionThe architecture behind ChatGPT and Claude
  11. 11
    Transfer Learning and Pretrained ModelsStanding on the shoulders of giants
  12. 12
    Capstone ProjectBuild and present a deep learning project