In this lesson
The Big Idea
A neural network is a mathematical model built from simple computing units arranged in layers: an input layer, hidden layers and an output layer. Each unit multiplies its inputs by weights, adds them up, adds a bias, and usually applies an activation function. Training means adjusting those weights gradually until the loss on the training data goes down. Deep learning uses many layers in sequence that learn increasingly combined representations, from edges to parts to the whole object. Despite its big achievements, depth alone does not guarantee success and does not mean general understanding.
The Structure of a Neural Network: Layers of Units
A neural network is a mathematical model whose name was historically inspired by the idea of nerve cells, but it is not a copy of the brain. It is made of computing units called nodes or neurons, plus the links between them, which are defined by the model's architecture.
In the simplified teaching example, units are organised into layers (a layer is a group of neurons at one stage), and each layer connects to the next. In real networks the pattern of connections varies with the type of network.
Three kinds of layer, by role
| Layer | Role | |---|---| | Input layer | Represents the values entering the model, such as the pixel values of an image | | Hidden layer (middle layer) | Turns the data into new representations the network learns, i.e. extracts features | | Output layer | Produces values suited to the task, such as probability scores for each class |
The short version students remember: input receives, hidden processes, output answers.
Example: dog or cat?
Data enters through the input layer: the image's pixel values. It passes through hidden layers that may learn patterns linked to edges, shapes or other representations. The output layer then produces scores or probabilities for "dog" and "cat", and a decision rule is applied (for example: pick the class with the highest score).
Who decides the shape of the network?
The designer chooses the architecture: how many layers and how many units in each, based on the task, the data, the resources and the results of experiments. More depth or more units can help with some problems, but it raises the cost (time and computing) and doesn't guarantee better performance or generalisation.
How a Neuron Works
In the common simplified model, a neuron does four things:
- Receives several values from the previous layer.
- Multiplies each value by its own weight, then adds the results: this is the weighted sum.
- Adds a bias, a fixed value the neuron learns that shifts the result up or down.
- Applies an activation function to the result, then passes the output to the next part of the network.
The activation function lets the network learn relationships that are not simply proportional. One of the simplest keeps positive values as they are and turns negative values into zero, written max(0, z).
Weights: how much, and in which direction
A weight is a numerical factor that sets how much and in which direction a value contributes to the calculation:
- A large weight means the input has a strong influence; a small one, a weak influence.
- A weight can be positive, raising the sum, or negative, lowering it.
But careful: a weight on its own does not mean a particular word or feature will decide the result, because a prediction comes from many parameters interacting across the whole network.
A worked example
A neuron has three inputs, 2, 1 and 3, with weights 0.5, −1 and 0.4, and a bias of 0.3:
z = (2 × 0.5) + (1 × −1) + (3 × 0.4) + 0.3
= 1 − 1 + 1.2 + 0.3
= 1.5
output = max(0, 1.5) = 1.5Notice how the negative weight cancelled out the second input's contribution. If the sum had been negative, the activation function in this example would have output zero.
Training: Adjusting the Weights to Reduce the Loss
Before training, the network knows nothing. Training is the process of gradually adjusting the network's parameters (weights and biases) to reduce a loss function on the training data, using an optimisation algorithm. Usually backpropagation computes the gradients needed for this adjustment, i.e. it works out for each weight whether to increase or decrease it, and roughly by how much.
The loss function is a number measuring how far the network's outputs are from the target values. The smaller the loss, the closer the predictions are to correct on the training data.
| Stage | What happens | |---|---| | Before training | Parameters usually start with random or carefully chosen near-random values, so predictions are usually poor | | During training | The loss between outputs and targets is measured, then the parameters are adjusted gradually to reduce it | | After training | Performance is measured on separate validation or test data to see how well the model generalises to new examples; training does not guarantee every prediction is correct |
Overfitting and generalisation
Training aims to find parameters that reduce the loss and improve performance. But a low training error on its own is not enough. Overfitting can happen: the network memorises the training examples in detail, does brilliantly on them, then makes mistakes on new examples.
So we evaluate the model on separate data that was never used to adjust its parameters. The ability we want is called generalisation: working correctly on new data the model has never seen.
Deep Learning and Hierarchical Features
Deep learning is learning with multi-layer neural networks that can learn successive representations from data. "Deep" refers to the depth of the architecture, i.e. many hidden layers one after another. There is no single universal number of layers that separates a deep model from any other.
From edges to a face: hierarchical features
Successive layers may learn more abstract representations the deeper you go. In some image networks, a possible progression is described for teaching purposes like this:
| Layer position | Examples of features extracted | |---|---| | Shallow layers | Simple features such as lines and changes in colour | | Middle layers | Shapes of parts such as eyes, nose and ears | | Deep layers | The structure of the whole face or object |
This is an approximate example to help understanding, not a fixed path every network follows. These successive representations may help a network learn complex relationships and perform well if the data, architecture, training and evaluation are suitable; adding depth alone does not guarantee it.
Why has deep learning spread now?
A combination of factors made it take off:
- Better architectures and algorithms, activation functions and optimisation methods.
- More data and better software tools.
- More computing power: chips such as GPUs and TPUs speed up many operations, but they are not required for every use or every prediction.
Why Deep Learning Brought a Leap in AI
Deep learning made big progress on specific tasks such as image classification, speech recognition and language processing. It may approach or beat human performance on a specific test, but it can fail outside the evaluation conditions, and that does not mean it has general intelligence or general understanding.
| Field | Examples | |---|---| | Image recognition | Face recognition systems, diagnostic support for medical images, object detection for self-driving cars | | Speech recognition | Voice control of smart speakers, speech-to-text, machine translation | | Natural language processing (NLP) | Machine translation, text summarisation, answering questions |
The secret: features are learned automatically
In many traditional methods, people designed the features by hand: an engineer might decide that "number of straight lines" is an important feature for recognising digits. Deep-learning networks can learn many representations from the data itself. Even so, choosing the task, the data, the architecture, the objective and the evaluation remains a human responsibility.
These abilities supported the development of models that generate text, images, audio and software (next lesson's topic), and the quality and risks of their outputs must be evaluated for every use.
A practical example: a voice assistant turns spoken commands into text and works well in many situations nobody wrote separate rules for, because it generalised patterns learned from many examples. But it may make mistakes with a dialect that was under-represented in its data, with heavy noise, or with a rare word.
Try It Yourself
= 1 + (-1) + 1.2 + 0.3
= 1.5
output = max(0, 1.5) = 1.5
Common Mistakes
"A neural network is a mini copy of the human brain and thinks like it"
Neural networks only took their name, historically, from the idea of nerve cells.
A neural network is a mathematical model of computing units (multiplying, adding, applying functions) whose parameters are adjusted by training.
"The bias in a neuron is the same thing as bias in the data"
Same English word, completely different meaning.
A neuron's bias is a number it learns and adds to the weighted sum. Bias in data (lesson 7-1) is skewed data leading to skewed judgments.
"A big weight on one feature means that feature alone decides the result"
A prediction comes from many parameters interacting across all the layers.
A weight sets how much, and in which direction, one value contributes to one neuron's calculation; it can be positive or negative.
"If the training error is very low, the model is excellent"
The network may simply have memorised the training examples: that is overfitting.
Judge a model by its performance on separate data it never trained on, i.e. by how well it generalises.
"More layers always means better performance"
Depth raises the cost, needs suitable data and training, and there is no magic number of layers.
Depth may help represent more complex relationships, but it doesn't guarantee better performance or generalisation.
Key Points
- A neural network is a mathematical model of units (nodes/neurons) in layers: input receives, hidden layers transform representations and extract features, output answers.
- A neuron: weighted sum of inputs + bias, then usually an activation function, then the result goes to the next layer.
- A weight sets how much and in which direction an input contributes; it can be positive or negative and does not decide the result alone.
- Training adjusts the parameters gradually to reduce a loss function with an optimisation algorithm; backpropagation computes the gradients.
- A low training error is not enough: overfitting can happen, so we measure generalisation on separate test data.
- Deep learning uses many layers that build hierarchical features (lines → parts → whole); there is no universal layer count for "deep", and depth alone doesn't guarantee performance.
- It spread thanks to several factors: better architectures and algorithms, data and tools, and computing power (GPUs and TPUs).
- Its leap in images, speech and language comes from learning features automatically from data, but it excels at specific tasks, not general intelligence.
FAQ
What is the difference between a weight and the bias in a neuron?
A weight multiplies one particular input to set how much, and in which direction, it contributes; every input has its own weight. The bias is a single value added to the whole weighted sum, shifting it up or down. Both are parameters the network learns during training.
What does overfitting mean, in simple words?
The network memorises the training examples instead of learning the general pattern, so its training error is very low but it makes mistakes on new examples. You catch it by measuring performance on separate data that was not used for training.
How many layers does a network need to count as deep learning?
According to the Arabic edition, there is no single universal number. Deep refers to the depth of the architecture, meaning many hidden layers in sequence that learn successive representations, not a particular count.
Can deep learning run without a GPU?
Yes, in many cases. GPUs and TPUs speed up many operations, especially in large-scale training, but the book makes clear they are not required for every use or prediction.