Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconArtificial Intelligencebreadcumb forward arrow iconRecurrent Neural Networks: Introduction, Problems, LSTMs Explained

Recurrent Neural Networks: Introduction, Problems, LSTMs Explained

Last updated:
8th Feb, 2021
Views
Read Time
5 Mins
share image icon
In this article
Chevron in toc
View All
Recurrent Neural Networks: Introduction, Problems, LSTMs Explained

Introduction

In a traditional feed-forward neural network, the flow of the information is only in one direction, which is from the input layer to the hidden layers and finally the output layer.

Here, the output of each layer depends only on its immediately previous layer, and so it does not have any memory of the past layers while going forward. For example, consider a simple neural network and feed in the word “layer” as the input.

Top Machine Learning and AI Courses Online

Ads of upGrad blog

The neural network will process the word one character at a time. While it reaches the character “e”, it no longer has any memory of the previous characters “l”, “a” and “y”. This is why a feed-forward neural network will never be able to predict the next character output.

Now, this is where a recurrent neural network comes to the rescue. It is able to remember all the previous characters because it possesses a memory of its own. As the name suggests, the flow of information recurs in a loop in the case of a recurrent neural network.

At every stage, it receives two inputs: the current state, and the information gathered from the previous states. Thus, this kind of neural network does well in tasks like predicting the next character and other sequential data in general, like speech, audio, time series, etc.

Taking the above example of the word “layer”, suppose the neural network is trying to predict the fifth character. The hidden block in the diagram above applies a recurrence formula at every time step, which will have the current input as well as its previous state. So for time-step t if the current input is “y” then the previous state is “a” and the formula is applied to both “y” and “a” to get the next output state. 

The formula is represented as–

ht = f(ht-1 , xt)

where ht is the new state, ht-1 is the previous state and it is the current input. Each input corresponds to a time step, and the same weight matrix is assigned to the RNN at each time step along with the same function.

Trending Machine Learning Skills

So taking the f(x) activation function as tanh and assigning the weights (whh and wxh) to the current and previous states, we get-

ht = tanh (Whhht-1 + Wxhxt)

Now the output would be-

yt = Whyht

If we try to have a deeper recurrent neural network, it means having more than one hidden layer. Here, all hidden layers will have different weights and different activation functions so that each layer is independent and behaves differently. Having the same weights and bias for each hidden layer will defeat the purpose and make them behave the same.

Problems

Some problems or issues which occur while training recurrent neural networks are vanishing gradients and exploding gradients. A gradient is simply the measure of how much the output of a function changes with the change in input. Higher the gradient or slope, the faster the recurrent neural network is learning, and vice-versa.

Vanishing gradients take place when the gradient value is so small that the RNN model takes extremely long to learn or doesn’t learn at all. This is a difficult problem to tackle, however, it can be solved by using LSTMs, GRU, or the Relu activation function.

Exploding gradients take place when some of the weights are given far too much importance by assigning them an extremely high value. This problem is easier to tackle than vanishing gradients. RMSprop can be used to adjust the learning rate, or the backpropagation can be truncated at a suitable time step.

Popular AI and ML Blogs & Free Courses

LSTMs

Recurrent neural networks by default tend to have a short-term memory, with the exception of LSTMs. They basically have a 3-gate module—

Forget gate: This gate decides how much of the past information should be remembered and how much should be omitted. 

Input gate: This gate decides how much of the present input is to be added to the current state. 

Output gate: This gate decides how much of the current state will be passed on to the output.

Ads of upGrad blog

Also Read: Machine Learning Project Ideas

Conclusion

This modified version of RNN thus is able to remember things for a longer-term, without having to worry about vanishing gradients. LSTMs are helpful in classifying or predicting series where the duration of time lags are unknown. RNNs in general have always helped in sequenced data modeling, with the added advantage that they can process inputs and outputs of varying lengths.

If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.

Learn ML Course from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

Profile

Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.
Get Free Consultation

Selectcaret down icon
Select Area of interestcaret down icon
Select Work Experiencecaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Machine Learning Course

Explore Free Courses

Suggested Blogs

RPA Developer Salary in India: For Freshers & Experienced [2024]
904648
Wondering what is the range of RPA developer salary in India? According to Forrester, if the Robotic Process Automation or RPA market continues to gr
Read More

by Pavan Vadapalli

29 Jul 2024

15 Interesting MATLAB Project Ideas & Topics For Beginners [2024]
82995
Diving into the world of engineering and data science, I’ve discovered the potential of MATLAB as an indispensable tool. It has accelerated my c
Read More

by Pavan Vadapalli

09 Jul 2024

5 Types of Research Design: Elements and Characteristics
47385
The reliability and quality of your research depend upon several factors such as determination of target audience, the survey of a sample population,
Read More

by Pavan Vadapalli

07 Jul 2024

Biological Neural Network: Importance, Components & Comparison
50612
Humans have made several attempts to mimic the biological systems, and one of them is artificial neural networks inspired by the biological neural net
Read More

by Pavan Vadapalli

04 Jul 2024

Production System in Artificial Intelligence and its Characteristics
86790
The AI market has witnessed rapid growth on the international level, and it is predicted to show a CAGR of 37.3% from 2023 to 2030. The production sys
Read More

by Pavan Vadapalli

03 Jul 2024

AI vs Human Intelligence: Difference Between AI & Human Intelligence
113357
In this article, you will learn about AI vs Human Intelligence, Difference Between AI & Human Intelligence. Definition of AI & Human Intelli
Read More

by Pavan Vadapalli

01 Jul 2024

Career Opportunities in Artificial Intelligence: List of Various Job Roles
89813
Artificial Intelligence or AI career opportunities have escalated recently due to its surging demands in industries. The hype that AI will create tons
Read More

by Pavan Vadapalli

26 Jun 2024

Gini Index for Decision Trees: Mechanism, Perfect & Imperfect Split With Examples
71191
As you start learning about supervised learning, it’s important to get acquainted with the concept of decision trees. Decision trees are akin to
Read More

by MK Gurucharan

24 Jun 2024

Random Forest Vs Decision Tree: Difference Between Random Forest and Decision Tree
51883
Recent advancements have paved the growth of multiple algorithms. These new and blazing algorithms have set the data on fire. They help in handling da
Read More

by Pavan Vadapalli

24 Jun 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon