Many-to-one attention mechanism for Keras. We demonstrate that using attention yields a higher accuracy on the IMDB dataset. We consider two LSTM networks: one with this attention layer and the other one with a fully connected layer. Both have the same number of parameters for a fair comparison (250K). The attention is expected to be the highest after the delimiters. An overview of the training is shown below, where the top represents the attention map and the bottom the ground truth. As the training progresses, the model learns the task and the attention map converges to the ground truth. We consider many 1D sequences of the same length. The task is to find the maximum of each sequence. We give the full sequence processed by the RNN layer to the attention layer. We expect the attention layer to focus on the maximum of each sequence.
Features
- Find max of a sequence
- Many-to-one attention mechanism for Keras
- Attention mechanism Implementation
- Browse examples