1. Home
  2. Explore
  3. Computer Science
  4. Deep Learning Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Deep Learning Fundamentals

Deep Learning and Neural Networks

Deep learning and neural networks

Deep learning is a type of machine learning that extracts useful features from input data by applying multiple layers of mathematical operations. As data passes through the layers, the model transforms it into representations that may help it produce an output or identify patterns.

Many well-known deep learning approaches use neural networks, including:

  • Deep neural networks

  • Deep belief networks

  • Recurrent neural networks

  • Convolutional neural networks

  • Deep reinforcement learning

The terms deep learning and neural network are closely related, but they do not mean exactly the same thing. A neural network is a particular kind of algorithm that can be used to implement artificial intelligence. Deep learning refers to machine learning methods that use multiple layers to process data. Most modern deep learning models are based on neural networks, so the terms are sometimes used interchangeably. However, some reinforcement learning methods can be implemented without neural networks.


Artificial neurons and neural networks

An artificial neural network is an algorithm made up of connected artificial neurons. Despite their names, artificial neurons and networks do not work like biological neurons in organisms. An artificial neuron is a mathematical function or combination of functions that processes numerical inputs and returns a numerical output.

An artificial neural network connects many such functions so that it can derive information from input data. At a basic level, an artificial neuron:

  1. Receives one or more input values.

  2. Applies weights to the inputs.

  3. Combines the weighted values.

  4. Passes the result through an activation function.

  5. Sends the resulting output onward.

An activation function determines how a neuron converts its input into an output. Different activation functions can be selected depending on the task, the data, or the role of the neuron.

Data and features

A neural network works with numbers. Since many real-world facts can be represented numerically, data about real-world phenomena can be supplied to a neural network in numerical form.

As input data passes through a network, it is transformed into features: representations derived from the input that may help the model perform a task. Some learned features may be useful, while others may not contribute much to the final result.

A neural network processes numerical representations of data and transforms them through connected functions to produce an output.


Layers and forward propagation

Neural networks can connect neurons in different ways. One common arrangement is a fully connected neural network, in which each neuron in one layer sends its output to every neuron in the next layer.

A network typically has:

  • An input layer, which receives the data.

  • One or more hidden layers, which process and transform the data.

  • An output layer, which returns the network’s result.

A hidden layer is any layer that is neither the input layer nor the output layer.

Each neuron has one or more input ports. These inputs may come directly from the network’s data or from the outputs of neurons in the preceding layer. In a fully connected network, every neuron passes its output to all neurons in the next layer.

Each input port can have a weight, which controls how strongly that input contributes to the neuron’s calculation. A neuron combines its weighted inputs, typically by summing them, and then applies an activation function. The result becomes an input to the next layer.

The process of passing values from the input layer through the network to produce an output is called forward propagation.

For a neuron with inputs x1,x2,…,xnx_1, x_2, \ldots, x_nx1​,x2​,…,xn​ and corresponding weights w1,w2,…,wnw_1, w_2, \ldots, w_nw1​,w2​,…,wn​, a basic weighted sum is:

z=∑i=1nwixiz = \sum_{i=1}^{n} w_i x_iz=∑i=1n​wi​xi​

The neuron then applies an activation function fff:

y=f(z)y = f(z)y=f(z)

Here, zzz is the weighted sum and yyy is the neuron’s output.


Example: detecting spam email

A simple neural network can be used to classify an email as spam or not spam. An email contains many possible sources of information, such as its sender, recipient, and text. A model can select features that may be relevant to spam detection.

Consider three binary inputs, where each input is either true or false:

  • x1x_1x1​: The sender is on a blacklist.

  • x2x_2x2​: The email contains the word “password.”

  • x3x_3x3​: The email has an attached file with the “exe” extension.

A true input is represented by 111 and a false input by 000. Suppose the inputs receive these weights:

  • w1=0.5w_1 = 0.5w1​=0.5

  • w2=0.2w_2 = 0.2w2​=0.2

  • w3=0.3w_3 = 0.3w3​=0.3

The weighted sum is:

z=0.5x1+0.2x2+0.3x3z = 0.5x_1 + 0.2x_2 + 0.3x_3z=0.5x1​+0.2x2​+0.3x3​

For an email whose sender is blacklisted, which does not contain “password,” and which has an “exe” attachment, the inputs are:

(x1,x2,x3)=(1,0,1)(x_1, x_2, x_3) = (1, 0, 1)(x1​,x2​,x3​)=(1,0,1)

The weighted sum is therefore:

z=(0.5)(1)+(0.2)(0)+(0.3)(1)=0.8z = (0.5)(1) + (0.2)(0) + (0.3)(1) = 0.8z=(0.5)(1)+(0.2)(0)+(0.3)(1)=0.8

Suppose the activation rule classifies an email as spam when the weighted sum is greater than 0.50.50.5. Because 0.8>0.50.8 > 0.50.8>0.5, the network classifies this email as spam.

In an actual model, the activation function would typically return a numerical value. A simple binary classifier could interpret the result as 111 for spam and 000 for not spam. This example is deliberately small; practical models may use many more inputs and layers.

Training the network means adjusting its weights so that its predictions become more accurate.


Supervised learning

One common way to train a neural network is supervised learning. A supervised model learns from pairs consisting of:

  • An input.

  • The correct answer, also called the target or label.

This is similar to memorizing question-and-answer pairs while preparing for a quiz. The model receives an input, calculates an output through its activation functions, and compares that output with the known correct answer.

If the model’s output is not correct, training adjusts the network’s weights so that the same or similar input is more likely to produce an output closer to the target in the future.

In this way, supervised learning changes the model’s internal calculations in response to its errors. Supervised neural networks are widely used in modern artificial intelligence.


Error, loss, and training

The error describes the difference between the model’s output and the correct answer. A loss is a numerical measure of how wrong the model’s output is. One possible loss is the square of the error, though neural networks can use different loss functions.

For an output y^\hat{y}y^​ and target yyy, a squared-error loss can be written as:

L=(y−y^)2L = (y - \hat{y})^2L=(y−y^​)2

The key idea is that larger errors generally produce larger loss values. Training aims to change the model so that the loss decreases.

Training is the process of adjusting a model’s internal parameters, such as its weights, to reduce its loss on training examples.

Forward and backward processes

The overall supervised training process has two complementary directions:

  • Forward propagation: Input values travel through the network to produce an output.

  • Back propagation: The loss is used to determine how the weights should change to reduce future errors.

During forward propagation, each layer’s outputs become the next layer’s inputs. After the network produces its final output, that output is compared with the correct answer to calculate the loss. Back propagation then uses the loss to guide adjustments to the network’s weights, working backward through the layers.


Back propagation and the chain rule

To adjust a weight effectively, the model needs to know how changing that weight affects the loss. This relationship is expressed by the derivative of the loss with respect to the weight.

The chain rule makes it possible to calculate this derivative by combining simpler derivatives. For a simple neuron, let:

  • www be a weight.

  • xxx be the input multiplied by the weight.

  • z=wxz = wxz=wx be the weighted sum.

  • y^=f(z)\hat{y} = f(z)y^​=f(z) be the activation-function output.

  • LLL be the loss.

The chain rule expresses the effect of the weight on the loss as:

∂L∂w=∂L∂y^⋅∂y^∂z⋅∂z∂w\frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat{y}} \cdot \frac{\partial \hat{y}}{\partial z} \cdot \frac{\partial z}{\partial w}∂w∂L​=∂y^​∂L​⋅∂z∂y^​​⋅∂w∂z​

Each factor describes one link in the chain:

  • ∂L∂y^\frac{\partial L}{\partial \hat{y}}∂y^​∂L​ describes how the loss changes when the output changes.

  • ∂y^∂z\frac{\partial \hat{y}}{\partial z}∂z∂y^​​ describes how the activation output changes when the weighted sum changes.

  • ∂z∂w\frac{\partial z}{\partial w}∂w∂z​ describes how the weighted sum changes when the weight changes.

For the sigmoid activation function,

y^=σ(z)\hat{y} = \sigma(z)y^​=σ(z)

its derivative can be expressed in terms of its output:

∂y^∂z=y^(1−y^)\frac{\partial \hat{y}}{\partial z} = \hat{y}(1-\hat{y})∂z∂y^​​=y^​(1−y^​)

Because z=wxz = wxz=wx, the derivative of the weighted sum with respect to the weight is:

∂z∂w=x\frac{\partial z}{\partial w} = x∂w∂z​=x

Thus, for this simple neuron:

∂L∂w=∂L∂y^⋅y^(1−y^)⋅x\frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat{y}} \cdot \hat{y}(1-\hat{y}) \cdot x∂w∂L​=∂y^​∂L​⋅y^​(1−y^​)⋅x

The exact loss derivative depends on the loss function being used. The important principle is that the chain rule allows the model to calculate how each weight contributes to the final loss. In a network with many layers, the same idea is applied repeatedly as the gradient is passed backward through the network.


Gradients and weight updates

The derivative of the loss with respect to a weight is called the gradient for that weight. It describes how the loss changes as the weight changes. For a single weight, the gradient can be viewed as the slope of the loss curve at the current weight value.

  • If the gradient is positive, increasing the weight increases the loss. To reduce the loss, the weight should generally be decreased.

  • If the gradient is negative, increasing the weight decreases the loss. To reduce the loss, the weight should generally be increased.

A common update rule is:

wnew=wold−η∂L∂ww_{\text{new}} = w_{\text{old}} - \eta \frac{\partial L}{\partial w}wnew​=wold​−η∂w∂L​

Here, η\etaη is the learning rate, a positive value that controls the size of each weight adjustment. A small learning rate, such as 0.00050.00050.0005, makes smaller changes; a larger learning rate makes larger changes.

The update moves the weight in the direction that is expected to reduce the loss. If the gradient is positive, the subtraction decreases the weight. If the gradient is negative, the subtraction increases it.

The learning rate must be chosen carefully. It determines how far the weight moves during each update, so it directly affects the size of the changes made during training.


Training across examples and epochs

A single input-and-answer pair provides information for updating the network’s weights. When a training set contains many examples, the learning process is applied across the data so that the model can learn from all of them.

An epoch is one complete pass of training through all examples in the training dataset, including the associated back-propagation updates. Neural networks are usually trained for multiple epochs, allowing their weights to be adjusted repeatedly.

The number of epochs required depends on factors such as the amount of data and the model. A large dataset may sometimes allow a model to reach a useful result in fewer epochs, though the appropriate training duration depends on the specific task and model.

As networks and datasets grow, the number of calculations required for training increases. Graphics processing units (GPUs) are often used to perform these calculations quickly.


Training, inference, and prediction

Training modifies a model’s weights based on errors and loss. In supervised learning, this process uses input-and-answer pairs and adjusts the weights to reduce the difference between model outputs and the correct answers.

Inference is the process of using a trained model to produce an output for an input. In a neural network, inference is performed through forward propagation.

Prediction is one type of inference: the model uses an input to estimate an output, such as whether an email is spam.


Key ideas

  • A neural network is a connected system of mathematical functions called artificial neurons.

  • Each neuron combines weighted inputs and applies an activation function.

  • Layers transform numerical input data into features and then into a final output.

  • Forward propagation carries input values through the network.

  • Supervised learning trains a model using input-and-correct-answer pairs.

  • Loss measures how far a model’s output is from the desired answer.

  • Back propagation uses the loss and the chain rule to calculate how weights should change.

  • Gradient-based updates adjust weights in the direction expected to reduce loss.

  • An epoch is a complete pass through the training data.

  • Inference uses a model to produce an output without updating its weights.

Neural networks are not the only basis for deep learning: some deep learning models use statistical or probabilistic methods. Understanding more advanced methods may require additional mathematics and computer science, especially in statistics and probability theory.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent