Recurrent Neural Networks focus on capturing the sequential information at time t by using historical states only. However, bidirectional RNN train the model from both directions using two RNN layers with one moving forwards from start to end and another RNN layer moving backwards from end to start of sequence.
Thus, the model is dependent on historical and future data. The bidirectional RNN models are useful where causal structure exists such as in text and speech. The unfolded structure of bidirectional RNN is shown in the following figure:
Unfolded bidirectional RNN architecture
Install and set up TensorFlow:
- Load required packages:
library(tensorflow)
- Load
MNIST
dataset. - The image from
MNIST
dataset is reduced to 16 x 16 pixels and normalized (Details are discussed in the Setting-up RNN model section).