It has been demonstrated that recurrent neural networks (RNNs) are efficient at modeling sequences. It may be used in a broad range of text-based contexts, including chatbots, machine translation, language modeling, etc.
But numerous applications of recurrent neural networks (RNNs) still struggle with memory. RNNs should be able to retain data over a number of timesteps and retrieve it when it is needed, however standard RNNs frequently struggle with this. A number of network topologies, including Gated Recurrent Units (GRU) and Long-Short-Term Memory (LSTM) units, have been suggested to address various parts of this issue.
This article's demonstration of a visualization approach aims to show memory in recurrent neural networks more effectively. This insight, perhaps, can lead to deeper comprehension.
What is RNN?
A feedforward neural network with internal memory is known as a recurrent neural network and is built to handle sequential data. The result of the current input depends on the previous calculation, making RNNs recurrent in nature because they carry out the same function for every data input. The output is created, duplicated, and then delivered back into the recurrent network. It takes into account both the current input and the output that it has learned from the prior input when making a decision.
Sequential data here can take the form of text, audio, video, and so on. RNN generates the current output by utilizing prior information in the sequence.
Picture source: aditi-mittal.medium.com
Problem with the RNN?
RNNs have short-term memory issues. It is caused by the vanishing gradient issue. RNN suffers from vanishing gradient more than other neural network designs as it processes more steps.
In RNN, the gradient is determined at each step as you backpropagate through time to train the network. The network's weights are updated using the gradient. The gradient value will be small and vice versa if the impact of the preceding layer on the present layer is minimal. The gradient of the following layer will be even less if the gradient of the preceding layer was already low. As we backpropagate, as a result, the gradients rapidly decrease. A smaller gradient indicates that it won't affect the weight update. As a result, the network is unable to learn the impact of previous inputs. as a result, the short-term memory issue.
The major issue is that RNN finds it too challenging to learn how to maintain information across several timesteps. The hidden state is constantly being rebuilt in a vanilla RNN.
Overcoming the Memorization problem of RNN
Two specialized RNN versions were produced to overcome the memorization problem of RNN. GRU (Gated Recurrent Unit) and LSTM (Long Short Term Memory) are the first two. Let's assume there are two sentences. “My dog is...... he was ill” in the first sentence, and “the dogs..... they were ill” in the second. The network must keep in mind the beginning words "dog" and "dogs" in order to anticipate the words "was" and "were" at the conclusion of the phrase. In order to store the activation value of earlier words in extended sequences, LSTMs and GRUs require memory cells. The idea of gates helps to enhance the whole picture as in a network they are used to regulate the information flow. Gates have the ability to recognize the critical inputs in a sequence and store
Gates have the capacity to learn which inputs in a series are crucial, and they can store this knowledge in the memory unit. They are able to transmit the data in extensive sequences and utilize them to generate predictions.
Connectivity: A insight into the different model's ability
To demonstrate how the LSTM unit memorizes in contrast to other recurrent units, it is qualitatively compared to other recurrent units in the previously released Nested LSTM work by showing individual cell activations. This visual method is effective for locating a certain feature. However, since the output depends only on which attribute the particular cell catches, it is not a strong case for memorizing in general.
The connection between the intended output and the input is examined in order to gain a better understanding of how each model memorizes and uses memory for contextual comprehension. This is determined as:
Unexpectedly much information about the various models' capacity for long-term contextual knowledge is revealed by examining the connectedness.
Image: Connectivity - The goal for the chosen character and the input characters have a strong link, as indicated by the green highlight.
From the above picture, you can see, how the models perform when given only the first two characters as input to predict the word "learning". The Nested LSTM model only proposes popular words that begin with the letter "l" and requires very little prior knowledge. The LSTM and GRU models, however, both propose the word "learning." In contrast to the LSTM model, the GRU model has a better connection with the term "advanced," and we can see from the recommendations that it predicts "learning" with a higher likelihood. The same can be seen and observed for words like “important”, “part”, and “linguists”.
Connection visualization an effective tool
When comparing models, connection visualization is an effective tool for identifying the prior inputs that each model uses for contextual knowledge.
The word that is being predicted itself is frequently involved in short-term contextual knowledge. In other words, when additional letters become accessible, the models begin to use previously used letters from the word itself. In contrast, models, particularly the GRU network, use previously encountered words as context for the prediction at the beginning of the phrase.
Short-term contextual knowledge is better handled by the LSTM model, whereas long-term contextual understanding is better handled by the GRU model. These findings are important because they explain why the GRU and LSTM models' overall accuracy is almost comparable, yet the connection visualization demonstrates how superior the GRU model is at recognizing long-term context.
Using the visualization approach allows for a much deeper understanding of the differences between the models than is attainable when only examining the accuracy and cross-entropy.
It is evident that, for this application, the GRU model relies considerably more heavily than the LSTM and Nested LSTM models on repeated phrases and the semantic significance of previous words when making predictions. This is important information to have when deciding on the final model as well as when creating better models in the future.