1. Home
  2. Explore
  3. Computer Science
  4. Artificial Neural Networks

Study methods

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

Artificial Neural Networks

Artificial Neural Networks: Foundations, Architecture, and Training

1. What Artificial Neural Networks Do

Artificial neural networks are computational models inspired by the way the biological nervous system processes information. They are used to identify patterns, make predictions, and support decisions in applications such as:

  • ChatGPT and other generative AI systems

  • Gemini and similar language models

  • Tesla’s self-driving systems

  • Bank fraud-detection systems

  • Enterprise-level prediction and classification systems

  • Image, text, speech, and numerical-data analysis

A neural network receives input data, processes it through connected computational units called neurons, and produces an output or decision.

A neural network learns by adjusting the importance assigned to different inputs until its predictions become increasingly accurate.


2. Biological Inspiration: The Nervous System

The basic idea behind an artificial neural network comes from the human nervous system.

Example: Reacting to a Fast-Moving Car

Suppose a car is approaching a person at high speed:

  1. The person’s eyes detect the car.

  2. The person’s ears may hear the car’s sound.

  3. These signals are transmitted to neurons in the nervous system.

  4. The neurons process the incoming information.

  5. Certain neurons become activated.

  6. The person decides to jump away from the car.

The decision depends on which neurons become activated after processing the sensory inputs.

Example: Feeling Relaxed

When a person sits on a sofa and listens to melodious music:

  1. The ears receive sound signals.

  2. The signals are transmitted to neurons.

  3. The neurons process the signals.

  4. A different group of neurons becomes activated.

  5. The person experiences relaxation.

The two situations activate different neurons and lead to different decisions or emotional responses.

Connection to Artificial Neural Networks

Artificial neural networks imitate this general pattern:

  • Inputs are equivalent to sensory signals.

  • Neurons perform calculations on the inputs.

  • Activation determines whether a neuron contributes strongly to the next stage.

  • Outputs represent a prediction or decision.

The central question is:

How does a neural network calculate which neurons should become activated?

The answer involves inputs, weights, biases, mathematical transformations, activation functions, loss functions, and optimization.


3. High-Level Architecture of a Neural Network

A basic artificial neural network contains three main types of layers:

  1. Input layer

  2. Hidden layer or layers

  3. Output layer

Information generally moves from the input layer toward the output layer during forward propagation.


3.1 Input Layer

The input layer receives the data used by the neural network.

For example, a person’s health-related data might contain:

  • Weekly exercise hours

  • Weekly junk-food consumption

  • Daily sleeping hours

  • Daily water consumption in liters

Each measurable property is called a feature.

If there are four features, the input layer can contain four input neurons:

  • x1x_1x1​: exercise data

  • x2x_2x2​: junk-food data

  • x3x_3x3​: sleep data

  • x4x_4x4​: water-consumption data

The input layer generally does not perform the main mathematical processing. Its primary role is to receive the feature values and pass them to the next layer.


3.2 Hidden Layer

The hidden layer performs most of the intermediate processing.

A neural network may contain:

  • One hidden layer

  • Several hidden layers

  • Many neurons in each hidden layer

A network with many hidden layers is commonly called a deep neural network, which is the basis of deep learning.

Every neuron in an input layer may be connected to neurons in the next hidden layer. These connections carry values that are adjusted during training.

For simplicity, an example may use:

  • Four input neurons

  • One hidden layer

  • Two hidden neurons

  • One output neuron

The hidden neurons do not directly represent obvious concepts such as “fit” or “unfit.” Instead, they learn intermediate patterns by combining the input features.


3.3 Output Layer

The output layer produces the final prediction or decision.

For the health example, the output could represent whether a person is fit:

  • Output value near 111: fit

  • Output value near 000: unfit

The output layer receives the processed values from the previous hidden layer, performs another calculation, and applies an appropriate activation function.


4. Example: Predicting Whether a Person Is Fit

4.1 Features and Label

Suppose the dataset contains information about many people. Each record includes four features:

  1. Hours of exercise per week

  2. Number of times junk food is eaten per week

  3. Hours of sleep per day

  4. Liters of water consumed per day

The target label indicates whether the person is fit:

  • 111: fit

  • 000: unfit

The four features are used to predict the label.

This is a binary classification problem because there are only two possible categories.

Binary classification predicts one of two possible outcomes, commonly represented by 000 and 111.


4.2 Labeled Training Data

During training, the neural network receives both:

  • The input features

  • The correct label

For example, a training record might be represented as:

x1=6,x2=8,x3=2.5,x4=water-consumption valuex_1 = 6,\quad x_2 = 8,\quad x_3 = 2.5,\quad x_4 = \text{water-consumption value}x1​=6,x2​=8,x3​=2.5,x4​=water-consumption value

The exact values are less important than the process. The network initially does not know:

  • Which feature is important

  • Whether a feature should increase or decrease the prediction

  • How the features should be combined

  • Whether the person is fit or unfit

It must learn these relationships from examples.

After training, the network should be able to receive the features of a new person without the label and predict whether that person is fit.


5. Weights: Assigning Importance to Inputs

Each connection between neurons has an associated weight.

A weight controls how strongly an input affects the calculation of the next neuron.

  • A large positive weight gives an input strong positive influence.

  • A small positive weight gives an input weak positive influence.

  • A negative weight gives an input negative influence.

  • A weight near zero gives an input little influence.

For example, if junk-food consumption is expected to reduce the probability of being fit, the corresponding weight may eventually become negative.

Initial Weights

At the beginning of training, the neural network does not know the correct importance of any feature. Therefore, the weights are usually initialized with small random values.

The network gradually changes these weights during training.

Weights represent the learned importance of inputs in a neural network.


6. Calculations Inside a Neuron

A neuron combines its input values and weights. The first calculation is a weighted sum followed by the addition of a bias.

For 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​, the calculation is:

z=x1w1+x2w2+⋯+xnwn+bz = x_1w_1 + x_2w_2 + \cdots + x_nw_n + bz=x1​w1​+x2​w2​+⋯+xn​wn​+b

This can be written more compactly as:

z=∑i=1nxiwi+bz = \sum_{i=1}^{n} x_iw_i + bz=∑i=1n​xi​wi​+b

where:

  • xix_ixi​ is an input feature

  • wiw_iwi​ is the weight associated with that feature

  • bbb is the bias

  • zzz is the neuron’s weighted-sum result before activation

The source describes an example in which this calculation produces a value such as:

z=11.15z = 11.15z=11.15

The value is not yet the final output of the neuron. It must be passed through an activation function.


6.1 Bias

A bias is an additional value added to the weighted sum.

It allows the neuron to shift its output independently of the input values. Without a bias, the neuron would be more restricted in the mathematical functions it could represent.

The bias is also learned during training. It may initially be assigned a small value, such as 0.20.20.2 or 0.30.30.3, depending on the example.

The complete neuron calculation is therefore:

z=∑i=1nxiwi+bz = \sum_{i=1}^{n} x_iw_i + bz=∑i=1n​xi​wi​+b

7. Activation Functions

The weighted sum zzz can be positive or negative. An activation function transforms this value and determines how strongly the neuron should be activated.

Activation functions are important because they:

  • Determine whether a neuron contributes to later calculations

  • Introduce nonlinearity into the network

  • Help the network learn complex relationships

  • Produce outputs suitable for different prediction tasks

Two activation functions discussed are ReLU and sigmoid.


7.1 ReLU Activation Function

ReLU stands for Rectified Linear Unit.

Its definition is:

ReLU⁡(z)=max⁡(0,z)\operatorname{ReLU}(z) = \max(0,z)ReLU(z)=max(0,z)

This means:

  • If zzz is positive, ReLU returns zzz.

  • If zzz is negative, ReLU returns 000.

For example:

ReLU⁡(11.15)=11.15\operatorname{ReLU}(11.15) = 11.15ReLU(11.15)=11.15

If the weighted sum were −3-3−3, then:

ReLU⁡(−3)=0\operatorname{ReLU}(-3) = 0ReLU(−3)=0

Interpretation

A positive weighted sum produces a positive activated value. A negative weighted sum is suppressed to zero.

In the hidden layer, ReLU allows positive signals to continue while preventing negative signals from contributing to the next stage.

ReLU preserves positive values and converts negative values to zero.


7.2 Hidden-Layer Example

Suppose the first hidden neuron receives the input values and weights, producing:

z1=11.15z_1 = 11.15z1​=11.15

After applying ReLU:

a1=ReLU⁡(11.15)=11.15a_1 = \operatorname{ReLU}(11.15) = 11.15a1​=ReLU(11.15)=11.15

The neuron is therefore active and passes 11.1511.1511.15 to the next layer.

A second hidden neuron has different weights, so it produces a different value. For example:

z2=7.95z_2 = 7.95z2​=7.95

After ReLU:

a2=ReLU⁡(7.95)=7.95a_2 = \operatorname{ReLU}(7.95) = 7.95a2​=ReLU(7.95)=7.95

Both hidden neurons are active in this example, but their activation values differ because they use different weights and biases.


8. Processing in the Output Layer

The output layer receives the activated values from the hidden layer.

If the hidden layer produces a1a_1a1​ and a2a_2a2​, the output layer calculates another weighted sum:

zout=a1w1+a2w2+boutz_{\text{out}} = a_1w_1 + a_2w_2 + b_{\text{out}}zout​=a1​w1​+a2​w2​+bout​

The output layer also has weights and a bias. These values are initially random and are learned during training.

For example, the output-layer calculation may produce:

zout=14.146z_{\text{out}} = 14.146zout​=14.146

Because this is a binary classification task, the output should be converted into a value between 000 and 111. The sigmoid activation function is appropriate for this purpose.


9. Sigmoid Activation Function

The sigmoid function is defined as:

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}σ(z)=1+e−z1​

It converts any real-valued input into a number between 000 and 111.

The sigmoid function is useful for binary classification because its output can be interpreted as a probability-like value.

For example:

  • Output near 000: strong evidence for class 000

  • Output near 111: strong evidence for class 111

  • Output near 0.50.50.5: uncertain prediction

If the output layer produces:

zout=14.146z_{\text{out}} = 14.146zout​=14.146

then the sigmoid output is very close to 111, approximately:

σ(14.146)≈0.99\sigma(14.146) \approx 0.99σ(14.146)≈0.99

9.1 Thresholding the Sigmoid Output

A common decision rule is:

  • If the sigmoid output is between 000 and 0.50.50.5, classify the example as 000.

  • If the sigmoid output is between 0.50.50.5 and 111, classify the example as 111.

Thus:

y^≥0.5⇒class 1\hat{y} \geq 0.5 \Rightarrow \text{class } 1y^​≥0.5⇒class 1
y^<0.5⇒class 0\hat{y} < 0.5 \Rightarrow \text{class } 0y^​<0.5⇒class 0

where y^\hat{y}y^​ is the predicted output.

For the fitness example:

  • y^≥0.5\hat{y} \geq 0.5y^​≥0.5: predict fit

  • y^<0.5\hat{y} < 0.5y^​<0.5: predict unfit

An output of 0.990.990.99 indicates a strong prediction for class 111, although it does not guarantee perfect correctness.

The closer a sigmoid output is to 111, the stronger the model’s confidence in class 111; the closer it is to 000, the stronger the confidence in class 000.


10. Forward Propagation

Forward propagation is the process through which input data moves from the input layer to the output layer.

The process is:

  1. Feature values enter the input layer.

  2. The input values are multiplied by connection weights.

  3. The weighted values are added together with a bias.

  4. An activation function is applied in the hidden layer.

  5. The activated hidden-layer values are passed to the output layer.

  6. The output layer calculates another weighted sum.

  7. An output activation function, such as sigmoid, produces the final prediction.

The general flow is:

Input data→Weighted sums→Hidden-layer activations→Output weighted sum→Prediction\text{Input data} \rightarrow \text{Weighted sums} \rightarrow \text{Hidden-layer activations} \rightarrow \text{Output weighted sum} \rightarrow \text{Prediction}Input data→Weighted sums→Hidden-layer activations→Output weighted sum→Prediction

Forward propagation produces a prediction, but it does not by itself tell the network whether the prediction is correct. That requires a comparison with the actual label.


11. Implementing Neural Networks with Libraries

Although the underlying calculations involve many formulas, deep-learning libraries perform most of them automatically.

Common libraries include:

  • TensorFlow

  • Keras

  • PyTorch

A neural-network implementation can specify:

  • The number of layers

  • The number of neurons

  • The activation function for each layer

  • The loss function

  • The optimizer

For example, a network may specify:

  • ReLU for a hidden layer

  • Sigmoid for a binary-classification output layer

The library then performs the repeated mathematical operations required for forward propagation, loss calculation, backpropagation, and weight updates.

Understanding the mathematics remains important because it helps a practitioner:

  • Choose appropriate activation functions

  • Select a suitable loss function

  • Select an optimizer

  • Diagnose training problems

  • Understand how the model learns

  • Improve the network’s performance

The library automates the calculations, but it does not eliminate the need to understand the underlying concepts.


12. Loss Functions

After forward propagation, the neural network has a prediction, but the prediction must be compared with the correct label.

A loss function measures the difference between:

  • The actual output, represented by yyy

  • The predicted output, represented by y^\hat{y}y^​

The loss value indicates how incorrect the prediction is.

  • Loss close to 000: prediction is close to the expected result

  • Large loss: prediction is far from the expected result

The network uses the loss to determine how its weights should be changed.


12.1 Binary Cross-Entropy

For binary classification, a suitable loss function is binary cross-entropy:

L=−[ylog⁡(y^)+(1−y)log⁡(1−y^)]L = -\left[y\log(\hat{y}) + (1-y)\log(1-\hat{y})\right]L=−[ylog(y^​)+(1−y)log(1−y^​)]

where:

  • yyy is the actual label

  • y^\hat{y}y^​ is the predicted probability

  • LLL is the loss

Binary cross-entropy strongly penalizes confident incorrect predictions.

Example of a Correct Positive Prediction

If the actual label is y=1y=1y=1 and the network predicts y^=0.99\hat{y}=0.99y^​=0.99, the loss is small:

L=−log⁡(0.99)L = -\log(0.99)L=−log(0.99)

This is close to zero because the prediction is close to the correct value.

Example of an Incorrect Positive Prediction

If the actual label is y=1y=1y=1 but the network predicts y^=0.1\hat{y}=0.1y^​=0.1, the loss is much larger:

L=−log⁡(0.1)L = -\log(0.1)L=−log(0.1)

The network is confidently moving toward the wrong class, so it receives a substantial penalty.

Important Note About Prediction Values

The size of the loss depends on both the actual label and the predicted value. For example, if the actual label is y=0y=0y=0 and the prediction is y^=0.99\hat{y}=0.99y^​=0.99, the prediction is very wrong and the loss is high. If the actual label is y=1y=1y=1, the same prediction is very good and the loss is low.

Therefore, a prediction such as 0.990.990.99 cannot be judged as correct or incorrect without knowing the actual label.


13. Backpropagation

Backpropagation is the process of sending error information backward through the network.

After forward propagation:

  1. The network produces a prediction.

  2. The prediction is compared with the actual label.

  3. A loss value is calculated.

  4. The loss information is propagated backward through the layers.

  5. The contribution of each weight to the loss is estimated.

  6. The weights and biases are adjusted.

Backpropagation allows the network to determine which connections contributed to the error and by how much.

Forward propagation produces the prediction; backpropagation uses the prediction error to improve the network.


14. Gradient Descent and Weight Updates

Backpropagation provides information about how each parameter affects the loss. Gradient descent uses that information to update the parameters.

A basic weight-update equation is:

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

where:

  • woldw_{\text{old}}wold​ is the current weight

  • wneww_{\text{new}}wnew​ is the updated weight

  • η\etaη is the learning rate

  • LLL is the loss

  • ∂L∂w\frac{\partial L}{\partial w}∂w∂L​ is the derivative of the loss with respect to the weight

The derivative indicates how much the loss changes when the weight changes.


14.1 Derivatives

The derivative is not ordinary division. It comes from differential calculus.

The quantity:

∂L∂w\frac{\partial L}{\partial w}∂w∂L​

indicates how strongly a particular weight contributes to the loss.

  • A large derivative means the weight has a strong effect on the loss.

  • A small derivative means the weight has a weaker effect.

  • The sign indicates the direction in which the weight should change.

For example, if a junk-food feature has a positive weight but should negatively influence fitness, gradient descent may reduce the weight and eventually make it negative.


14.2 Example of a Weight Update

Suppose:

  • The old weight is wold=0.5w_{\text{old}}=0.5wold​=0.5

  • The learning rate is η\etaη

  • The calculated gradient has a particular value

The update follows:

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

The source describes an example in which a weight is updated from a positive value to approximately:

wnew=−0.094w_{\text{new}}=-0.094wnew​=−0.094

This means the network learned that the associated feature should influence the prediction in the negative direction.

For the fitness example, high junk-food consumption may eventually receive a negative weight because it tends to reduce the probability of being classified as fit.


15. The Learning Rate

The learning rate determines the size of each parameter update.

It controls how far the network moves in the direction suggested by the gradient.

15.1 Learning Rate That Is Too Small

If the learning rate is too small:

  • The weights change very gradually.

  • The loss decreases slowly.

  • Training may require many iterations.

  • The network may take a long time to reach a good solution.

15.2 Learning Rate That Is Too Large

If the learning rate is too large:

  • The updates may overshoot the best parameter values.

  • The loss may move back and forth.

  • Training may oscillate instead of converging.

  • The model may fail to approach a low-loss solution.

15.3 Appropriate Learning Rate

A suitable learning rate allows the loss to decrease steadily:

  1. The network makes a prediction.

  2. The loss is calculated.

  3. The weights are adjusted by a controlled amount.

  4. The next prediction is slightly better.

  5. The process continues until the model reaches a low-loss region.

The goal is to reduce the loss as close to zero as practical without making the updates unstable.


16. Complete Neural-Network Training Process

Training combines forward propagation, loss calculation, backpropagation, and gradient descent.

The full process is:

  1. Initialize the weights and biases, usually with small random values.

  2. Pass a labeled training example into the input layer.

  3. Perform forward propagation.

  4. Calculate the predicted output.

  5. Compare the prediction with the actual label.

  6. Calculate the loss using binary cross-entropy.

  7. Perform backpropagation.

  8. Calculate how each weight contributed to the loss.

  9. Update the weights and biases using gradient descent.

  10. Repeat the process for additional training examples.

  11. Continue over many passes through the data.

  12. Evaluate the trained model on new, unlabeled data.

The repeated passes allow the network to gradually learn useful weights.


16.1 Training Across Many Examples

A single training example is not enough for a reliable model. The network must process many examples:

  • Hundreds of examples

  • Thousands of examples

  • Millions of examples, depending on the task

With repeated training, the model adjusts its weights to capture general relationships in the data rather than memorizing only one record.

After training, the result is a generalized model. It can accept new input data and produce predictions even when the correct label is not provided.

The predictions may be highly accurate, but no neural network is guaranteed to be correct 100%100\%100% of the time.


17. Choosing Functions for Different Tasks

Neural-network design requires selecting suitable functions for the problem.

Important choices include:

  • Activation functions

  • Loss functions

  • Optimizers

Hidden-Layer Activation

ReLU is commonly used in hidden layers because it is simple and preserves positive signals while suppressing negative ones.

Binary-Classification Output

Sigmoid is suitable when the output represents one of two classes because it produces values between 000 and 111.

Binary-Classification Loss

Binary cross-entropy is appropriate when the target contains two classes and the output is a probability-like value.

Optimizer

Gradient descent and related optimization methods update the weights to reduce the loss.

The correct choices depend on the type of data and prediction task. For example, binary classification and multi-class classification generally require different output configurations.


18. Neural Networks Process Numerical Inputs

Neural networks operate on numbers.

Even when the original data is not naturally numerical, it must be transformed into numerical representations before being passed into a neural network.

Examples include:

  • Tabular data represented as feature values

  • Images represented as pixel values

  • Text represented as numerical vectors

  • Audio represented as numerical signals

This explains why image classification requires a preprocessing step: an image must be converted into numerical pixel data before the neural network can process it.


19. Binary Classification and Multi-Class Classification

Binary Classification

Binary classification has two possible outcomes.

Example:

  • Fit: 111

  • Unfit: 000

A sigmoid output neuron is commonly used for this type of task.

Multi-Class Classification

Multi-class classification has more than two possible outcomes.

A handwritten-digit recognizer that identifies digits from 000 through 999 has ten possible classes:

{0,1,2,3,4,5,6,7,8,9}\{0,1,2,3,4,5,6,7,8,9\}{0,1,2,3,4,5,6,7,8,9}

The neural network must determine which of the ten classes best matches the input image.

This is different from the fitness example because the network is no longer choosing between only two outcomes. Its output design and activation function are therefore adapted to the multi-class problem.

The general learning process remains similar:

  1. Convert the input into numerical form.

  2. Perform forward propagation.

  3. Produce class-related outputs.

  4. Compare the prediction with the correct class.

  5. Calculate loss.

  6. Backpropagate the error.

  7. Update the weights.


20. Key Relationships Among the Main Concepts

  • Inputs are the feature values provided to the network.

  • Weights determine how strongly each input influences a neuron.

  • Biases shift the weighted-sum calculation.

  • Weighted sums combine inputs and weights.

  • Activation functions determine the signal passed to the next layer.

  • Forward propagation carries information from input to output.

  • Predictions are the output of the final layer.

  • Loss functions measure prediction error.

  • Backpropagation determines how the error affects the network’s parameters.

  • Gradients describe how parameter changes affect the loss.

  • Gradient descent updates weights to reduce the loss.

  • Repeated training produces a model that can generalize to new data.

A neural network learns by repeatedly predicting, measuring its error, tracing that error backward, and adjusting its weights.


21. Summary

An artificial neural network is a layered computational system inspired by biological neurons. It receives numerical input through an input layer, processes the information through one or more hidden layers, and produces a prediction through an output layer.

Each neuron calculates a weighted sum:

z=∑i=1nxiwi+bz = \sum_{i=1}^{n}x_iw_i+bz=∑i=1n​xi​wi​+b

The result is passed through an activation function such as ReLU:

ReLU⁡(z)=max⁡(0,z)\operatorname{ReLU}(z)=\max(0,z)ReLU(z)=max(0,z)

or sigmoid:

σ(z)=11+e−z\sigma(z)=\frac{1}{1+e^{-z}}σ(z)=1+e−z1​

For binary classification, sigmoid produces an output between 000 and 111. The prediction is compared with the actual label using binary cross-entropy. Backpropagation then calculates how the weights contributed to the error, and gradient descent updates them:

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

By repeating this process over many examples, the network gradually learns useful relationships among the features and becomes capable of making predictions on new data.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent