I want to train a bi-directional LSTM in tensorflow to perform a sequence classification problem (sentiment classification).
Because sequences are of variable lengths, batches are normally padded with vectors of zero. Normally, I use the sequence_length parameter in the uni-directional RNN to avoid training on the padding vectors.
How can this be managed with bi-directional LSTM. Does the "sequence_length" parameter work automatically starts from an advanced position in the sequence for the backward direction?
Thank you
In summary, this concise demonstration stresses the idea that bidirectional LSTMs are effective models for time series forecasting — here, using the Bitstamp dataset for Bitcoin as input data for the network.
Code Implementation of Bidirectional-LSTMSetting up the environment in google colab. In the above, we have defined some objects we will use in the next steps. In the next step, we will load the data set from the Keras library. To fit the data into any neural network, we need to convert the data into sequence matrices.
The main reason is that every component of an input sequence has information from both the past and present. For this reason, BiLSTM can produce a more meaningful output, combining LSTM layers from both directions.
bidirectional_dynamic_rnn
also has a sequence_length
parameter that takes care of sequences of variable lengths.
https://www.tensorflow.org/api_docs/python/tf/nn/bidirectional_dynamic_rnn (mirror):
sequence_length
: An int32/int64 vector, size [batch_size], containing the actual lengths for each of the sequences.
You can see an example here: https://github.com/Franck-Dernoncourt/NeuroNER/blob/master/src/entity_lstm.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With