Change language

Bidirectional LSTM | Natural Language Processing

Bidirectional LSTM | Natural Language Processing

We have already discussed about LSTM i.e.

Long short-term memory and we have already made one project using LSTM We have made next word prediction, right? But what if we want to predict middle word.

Suppose I have one sentence: The color of apple is …….

LSTM may return output as red.

Suppose we have another sentence.

Apple is …….. in color.

This time, we have to predict middle word.

Suppose we have several scenario regarding this: Apple is small in size.

Apple is red in color.

Apple is high in vitamin.

We can’t predict by just analyzing ‘Apple is’ because the output is dependent on both left and right side of that word.

In such a case, we can use bidirectional LSTM.

Bidirectional LSTM keeps forward and backward information about the sequence at every time step.

But remember, we can also predict middle word by LSTM.

How? In this example, we can bring all right side of word to the left side.

Now, the sentence will be Apple is in color …….

LSTM return output as red This way, we can predict middle word with LSTM.

But in this video, I just want to introduce about bidirectional LSTM.

LSTM goes only left to right but what if we want to process a lot of text at a same time.

LSTM increase complexity and also it may take little bit more time.

To deal with this problem, we have bidirectional LSTM.

This is the simple architecture of bidirectional LSTM.

First, I want to mark forward LSTM.

This is just simple LSTM which only moves to forward side i.e. from left to right.

Next, we have backward layer, which is a copy of forward layer but the direction is from right to left.

Next, we have input sequence.

In simple LSTM, input sequence pass only to forward layer, right? But in this bidirectional LSTM, input sequence pass to both forward and backward layer.

Then the output from both layer, that is forward and backward LSTM layer pass to activation function so that we can make certain decision based on a probability.

Then finally, after passing through forward and backward LSTM layer and after making decision, we get output.

This is simple architecture and introduction of bidirectional LSTM.

LSTM focus on past information whereas bidirectional LSTM focus on both past and future information.

To import and to add bidirectional LSTM in our model is very easy.

We can import LSTM and bidirectional LSTM from tensorflow.keras.layers Then to add bidirectional LSTM while creating our model, we have to just write bidirectional before LSTM.

Other all syntax I have explained before.

If you have watched my LSTM and next word prediction using LSTM, I believe you are getting what I am saying right now.

If you want to know more, please feel free to search about this.

If you like this video, hit the like button Subscribe my channel IG Tech Team I will meet you soon.

Stay safe and Keep Learning.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically