A Guide to Deep Learning and Neural Networks
Tags: machinelearning, ai, deeplearning, beginners
Published: 2021-02-14 13:35:53

---
title: A Guide to Deep Learning and Neural Networks
published: true
date: 2020-10-08 00:00:00 UTC
tags: machinelearning, artificialintelligence, deeplearning, beginners
canonical_url: https://serokell.io/blog/deep-learning-and-neural-network-guide
---

# A Guide to Deep Learning and Neural Networks

As a subset of artificial intelligence, deep learning lies at the heart of various innovations: self-driving cars, natural language processing, image recognition and so on. Companies that deliver DL solutions (such as Amazon, Tesla, Salesforce) are at the forefront of stock markets and attract impressive investments. According to [Statista](https://www.statista.com/statistics/621468/worldwide-artificial-intelligence-startup-company-funding-by-year/), the total funding of artificial intelligence startup companies worldwide in 2014–2019 is equal to more than $26 billion. This high interest can be explained by the amazing benefits of deep learning and its architectures — artificial neural networks.

![AI startup funding graph](https://serokell.io/files/3s/3slpcvqe.1_(32)_(1).jpg)

## What is deep learning?

![what is deep learning](https://serokell.io/files/yc/yctimg60.deviator-1_(1).jpg)

Deep learning is one of the subsets of machine learning that uses deep learning algorithms to implicitly come up with important conclusions based on input data.

Usually, deep learning is unsupervised or semi-supervised. Deep learning is based on [representation learning](https://en.wikipedia.org/wiki/Feature_learning#:~:text=In%20machine%20learning%2C%20feature%20learning,or%20classification%20from%20raw%20data.). Instead of using task-specific algorithms, it learns from representative examples. For example, if you want to build a model that recognizes cats by species, you need to prepare a database that includes a lot of different cat images.

The main architectures of deep learning are:

- Convolutional neural networks
- Recurrent neural networks
- Generative adversarial networks
- Recursive neural networks

We are going to talk about them more in detail later in this text.

### Difference between machine learning and deep learning

Machine learning attempts to extract new knowledge from a large set of pre-processed data loaded into the system. Programmers need to formulate the rules for the machine, and it learns based on them. Sometimes, a human might intervene to correct its errors.

However, deep learning is a bit different:

| Deep learning | Machine learning |
| --- | --- |
| large amounts of data | small datasets as long as they are high-quality |
| computation-heavy | not always |
| an draw accurate conclusions from raw data | carefully pre-processed data |
| take much longer to train | can be trained in a reduced amount of time |
| you can't know what are the particular features that the neurons represent | logic behind the machine’s decision is clear |
| can be used in unexpected ways | algorithm is built to solve a specific problem |

## Advantages of deep learning

Now that you know what the difference between DL and ML is, let us look at some advantages of deep learning.

- In 2015, a group of Google engineers was conducting research about [how NN carry out classification tasks](https://ai.googleblog.com/2015/07/deepdream-code-example-for-visualizing.html). By chance, they also noticed that neural networks can hallucinate and [produce rather interesting art](https://www.youtube.com/watch?v=uSUOdu_5MPc&t=932s).
- The ability to identify patterns and anomalies in large volumes of raw data enables deep learning to efficiently deliver accurate and reliable analysis results to professionals. For example, Amazon has more than [560 million items on the website and 300+ million users](https://www.digitalcommerce360.com/article/amazon-sales/). No human accountant or even a whole army of accountants would be able to track that many transactions without an AI tool.
- Deep learning doesn’t rely on human expertise as much as traditional machine learning. DL allows us to make discoveries in data even when the developers are not sure what they are trying to find. For example, you want your algorithms to be able to [predict customer retention](https://www.digitalocean.com/community/tutorials/how-to-build-a-deep-learning-model-to-predict-employee-retention-using-keras-and-tensorflow), but you’re not sure which characteristics of a customer will enable the system to make this prediction.

![Deep learning advantages](https://serokell.io/files/b3/b37v6nzo.2_(24)_(1).jpg)

## Problems of deep learning

- Large amounts of quality data are resource-consuming to collect. For many years, the largest and best-prepared collection of samples was [ImageNet with 14 million different images](https://www.zdnet.com/article/worlds-largest-image-database-to-help-computers-learn-to-see/#:~:text=To%20develop%20a%20system%20that,holds%2014%20million%20labeled%20images.) and more than 20,000 categories. It was founded in 2012, and only last year, [Tencent released a database](https://neurohive.io/en/datasets/tencent-dataset/) that is larger and more versatile.
- Another difficulty with deep learning technology is that it cannot provide reasons for its conclusions. Therefore, it is difficult to assess the performance of the model if you are not aware of what the output is supposed to be. Unlike in traditional machine learning, you will not be able to test the algorithm and find out why your system decided that, for example, it is a cat in the picture and not a dog.
- It is very costly to build deep learning algorithms. It is impossible without qualified staff who are trained to work with sophisticated maths. Moreover, deep learning is a resource-intensive technology. It requires powerful GPUs and a lot of memory to train the models. A lot of memory is needed to store input data, weight parameters, and activation functions as an input propagates through the network. Sometimes deep learning algorithms become so power-hungry that researchers prefer to use [other algorithms](https://serokell.io/blog/how-to-choose-ml-technique), even sacrificing the accuracy of predictions.

However, in many cases, deep learning cannot be substituted.

<iframe width="560" height="315" src="https://www.youtube.com/embed/0VH1Lim8gL8"></iframe>
## How can you apply DL to real-life problems?

![Deep learning applications](https://serokell.io/files/66/66a4xqmg.4_(18)_(1).jpg)

Today, deep learning is applied across different industries for various use cases:

- **Speech recognition.** All major commercial speech recognition systems (like Microsoft Cortana, Alexa, Google Assistant, Apple Siri) are based on deep learning.
- **Pattern recognition.** Pattern recognition systems are already able to give more accurate results than the human eye in [medical diagnosis](https://www.bbc.com/news/health-50857759#:~:text=Artificial%20intelligence%20is%20more%20accurate,images%20from%20nearly%2029%2C000%20women.).
- **Natural language processing.** Neural networks have been used to implement language models since the early 2000s. The invention of [LSTM](https://en.wikipedia.org/wiki/Long_short-term_memory) helped improve machine translation and language modeling.
- **Discovery of new drugs.** For example, the [AtomNet neural network](https://arxiv.org/abs/1510.02855) has been used to predict new biomolecules that can potentially cure diseases such as Ebola and multiple sclerosis.
- **Recommender systems.** Today, deep learning is being used to study user preferences across many domains. [Netflix](https://www.netflix.com/) is one of the brightest examples in this field.

## What are artificial neural networks?

![What are artificial neural networks](https://serokell.io/files/vd/vd78l0x8.deviator-2_(1).jpg)

“Artificial neural networks” and “deep learning” are often used interchangeably, which isn’t really correct. Not all neural networks are “deep”, meaning “with many hidden layers”, and not all deep learning architectures are neural networks. There are also [deep belief networks](https://en.wikipedia.org/wiki/Deep_belief_network#:~:text=In%20machine%20learning%2C%20a%20deep,between%20units%20within%20each%20layer.), for example.

![neural networks](https://serokell.io/files/vk/vkpzrxrf.5_(12)_(1).jpg)

However, since neural networks are the most hyped algorithms right now and are, in fact, very useful for solving complex tasks, we are going to talk about them in this post.

### Definition of an ANN

An artificial neural network represents the structure of a human brain modeled on the computer. It consists of neurons and synapses organized into layers.

ANN can have millions of neurons connected into one system, which makes it extremely successful at analyzing and even memorizing various information.

Here is a video for those who want to dive deeper into the technical details of how artificial neural networks work.

<iframe width="560" height="315" src="https://www.youtube.com/embed/njKP3FqW3Sk"></iframe>
## Components of Neural Networks

There are different types of neural networks but they always consist of the same components: neurons, synapses, weights, biases, and functions.

### Neurons

A neuron or a node is a basic unit of neural networks that receives information, performs simple calculations, and passes it further.

All neurons in a net are divided into three groups:

- Input neurons that receive information from the outside world;
- Hidden neurons that process that information;
- Output neurons that produce a conclusion.

![ML architecture](https://serokell.io/files/yt/ytl4jey2.6_(8)_(1).jpg)

In a large neural network with many neurons and connections between them, neurons are organized in layers. There is an input layer that receives information, a number of hidden layers, and the output layer that provides valuable results. Every neuron performs transformation on the input information.

Neurons only operate numbers in the range [0,1] or [-1,1]. In order to turn data into something that a neuron can work with, we need normalization. We talked about what it is in the [post about regression analysis](https://serokell.io/blog/regression-analysis-overview).

Wait, but how do neurons communicate? Through synapses.

### Synapses and weights

A synapse is what connects the neurons like an electricity cable. Every synapse has a weight. The weights also add to the changes in the input information. The results of the neuron with the greater weight will be dominant in the next neuron, while information from less ‘weighty’ neurons will not be passed over. One can say that the [matrix of weights](https://en.wikipedia.org/wiki/Weighing_matrix) governs the whole neural system.

![Neuron weights](https://serokell.io/files/b9/b92z8vod.7_(9)_(1).jpg)

How do you know which neuron has the biggest weight? During the initialization (first launch of the NN), the weights are randomly assigned but then you will have to optimize them.

### Bias

A bias neuron allows for more variations of weights to be stored. Biases add a richer representation of the input space to the model’s weights.

In the case of neural networks, a bias neuron is added to every layer. It plays a vital role by making it possible to move the activation function to the left or right on the graph.

![bias neurons](https://serokell.io/files/ey/eyarbo1y.8_(5)_(1).jpg)

It is true that ANNs can work without bias neurons. However, they are almost always added and counted as an indispensable part of the overall model.

## How ANNs work

Every neuron processes input data to extract a feature. Let’s imagine that we have three features and three neurons, each of which is connected with all these features.

Each of the neurons has its own weights that are used to weight the features. During the training of the network, you need to select such weights for each of the neurons that the output provided by the whole network would be true-to-life.

To perform transformations and get an output, every neuron has an activation function. This combination of functions performs a transformation that is described by a common function F — this describes the formula behind the NN’s magic.

![ANN: activation function](https://serokell.io/files/ly/ly9z5sh4.9_(3)_(1).jpg)

There are a lot of activation functions. The most common ones are [linear, sigmoid, and hyperbolic tangent](https://medium.com/wwblog/transformation-in-neural-networks-cdf74cbd8da8). Their main difference is the range of values they work with.

## How do you train an algorithm?

Neural networks are trained like any other algorithm. You want to get some results and provide information to the network to learn from. For example, we want our neural network to distinguish between photos of cats and dogs and provide plenty of examples.

Delta is the difference between the data and the output of the neural network. We use calculus magic and repeatedly optimize the weights of the network until the delta is zero. Once the delta is zero or close to it, our model is correctly able to predict our example data.

#### Iteration

This is a kind of counter that increases every time the neural network goes through one training set. In other words, this is the total number of training sets completed by the neural network.

#### Epoch

The epoch increases each time we go through the entire set of training sets. The more epochs there are, the better is the training of the model.

#### Batch

Batch size is equal to the number of training examples in one forward/backward pass. The higher the batch size, the more memory space you’ll need.

What is the difference between an iteration and an epoch?

![Batch: iteration/epoch](https://serokell.io/files/58/587yew4q.13_(1).jpg)

- one epoch is one forward pass and one backward pass of all the training examples;
- number of iterations is a number of passes, each pass using [batch size] number of examples. To be clear, one pass equals one forward pass + one backward pass (we do not count the forward pass and backward pass as two different passes).

## And what about errors?

Error is a deviation that reflects the discrepancy between expected and received output. The error should become smaller after every epoch. If this does not happen, then you are doing something wrong.

The error can be calculated in different ways, for example: Mean Squared Error or Root MSE. 

There is no restriction on which one to use, and you are free to choose whichever method gives you the best results. But each method counts error differently:

In Arctan, the error will almost always be larger since it works according to the principle of the larger the difference, the larger the error.

In Root MSE, the error is the smallest, and it is more balanced in the error calculation. MSE is used most often.

## What kinds of neural networks exist?

There are so many different neural networks out there that it is simply impossible to mention them all. If you want to learn more about this variety, [visit the neural network zoo](https://www.asimovinstitute.org/neural-network-zoo/) where you can see them all represented graphically.

![Examples of neural networks](https://serokell.io/files/ki/ki50qm8t.14_(1).jpg)

### Feed-forward neural networks

This is the simplest neural network algorithm. A feed-forward network doesn’t have any memory. That is, there is no going back in a feed-forward network. In many tasks, this approach is not very applicable. For example, when we work with text, the words form a certain sequence, and we want the machine to understand it.

Feedforward neural networks can be applied in supervised learning when the data that you work with is not sequential or time-dependent. You can also use it if you don’t know how the output should be structured but want to build a relatively fast and easy NN.

### Recurrent neural networks

A recurrent neural network can process texts, videos, or sets of images and become more precise every time because it remembers the results of the previous iteration and can use that information to make better decisions.

Recurrent neural networks are widely used in natural language processing and speech recognition.

### Convolutional neural networks

Convolutional neural networks are the standard of today’s deep machine learning and are used to solve the majority of problems. Convolutional neural networks can be either feed-forward or recurrent.

Let’s see how they work. Imagine we have an image of Albert Einstein. We can assign a neuron to all pixels in the input image.

But there is a big problem here: if you connect each neuron to all pixels, then, firstly, you will get a lot of weights. Hence, it will be a very computationally intensive operation and take a very long time. Then, there will be so many weights that this method will be very unstable to overfitting. It will predict everything well on the training example but work badly on other images.

![image convolution process](https://serokell.io/files/t6/t6c2e7xj.15_(1).jpg)

Therefore, programmers came up with a different architecture where each of the neurons is connected only to a small square in the image. All these neurons will have the same weights, and this design is called image convolution. We can say that we have transformed the picture, walked through it with a filter simplifying the process. Fewer weights, faster to count, less prone to overfitting.

![convolutional neural networks](https://serokell.io/files/i3/i3kkvxsp.16_(1).jpg)

For an awesome explanation of how convolutional neural networks work, watch this video by Luis Serrano.

<iframe width="560" height="315" src="https://www.youtube.com/embed/2-Ol7ZB0MmU"></iframe>
### Generative adversarial neural networks

A generative adversarial network is an unsupervised machine learning algorithm that is a combination of two neural networks, one of which (network G) generates patterns and the other (network A) tries to distinguish genuine samples from the fake ones. Since networks have opposite goals – to create samples and reject samples – they start an antagonistic game that turns out to be quite effective.

![elon musk faked into nicolas cage](https://serokell.io/files/hv/hvcamtnl.17_(1).jpg)

GANs are used, for example, to generate photographs that are perceived by the human eye as [natural images or deepfakes](https://www.forbes.com/sites/robtoews/2020/05/25/deepfakes-are-going-to-wreak-havoc-on-society-we-are-not-prepared/) (videos where real people say and do things they have never done in real life).

## What kind of problems do NNs solve?

Neural networks are used to solve complex problems that require analytical calculations similar to those of the human brain. The most common uses for neural networks are:

- **Classification.** NNs label the data into classes by implicitly analyzing its parameters. For example, a neural network can analyse the parameters of a bank client such as age, solvency, credit history and decide whether to loan them money.
- **Prediction.** The algorithm has the ability to make predictions. For example, it can foresee the rise or fall of a stock based on the situation in the stock market.
- **Recognition.** This is currently the widest application of neural networks. For example, a security system can use face recognition to only let authorized people into the building.

## Summary

Deep learning and neural networks are useful technologies that expand human intelligence and skills. Neural networks are just one type of deep learning architecture. However, they have become widely known because NNs can effectively solve a huge variety of tasks and cope with them better than other algorithms.

If you want to learn more about applications of machine learning in real life and business, continue reading our blog:

- In our post about [best ML applications](https://serokell.io/blog/best-machine-learning-applications), you can discover the most stunning use cases of machine learning algorithms.
- Read this Medium post if you want to learn more about [GPT-3 and creative computers](https://medium.com/better-programming/creative-computers-are-already-around-the-corner-23e94cdf017b).
- If you want to know how to choose [ML techniques](https://serokell.io/blog/how-to-choose-ml-technique) for your project, you will find the answer in our blog post.