Tensorflow中可变长度序列的双向LSTM

时间:2022-09-25 21:40:59

I want to train a bi-directional LSTM in tensorflow to perform a sequence classification problem (sentiment classification).

我想训练张量流中的双向LSTM来执行序列分类问题(情感分类)。

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.

因为序列具有可变长度,所以批次通常用零向量填充。通常,我在单向RNN中使用sequence_length参数来避免对填充向量进行训练。

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?

如何通过双向LSTM进行管理。 “sequence_length”参数是否自动从向后方向的序列中的高级位置开始?

Thank you

谢谢

1 个解决方案

#1


2  

bidirectional_dynamic_rnn also has a sequence_length parameter that takes care of sequences of variable lengths.

bidirectional_dynamic_rnn还有一个sequence_length参数,用于处理可变长度的序列。

https://www.tensorflow.org/api_docs/python/tf/nn/bidirectional_dynamic_rnn (mirror):

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.

sequence_length:int32 / int64向量,大小为[batch_size],包含每个序列的实际长度。

You can see an example here: https://github.com/Franck-Dernoncourt/NeuroNER/blob/master/src/entity_lstm.py

你可以在这里看到一个例子:https://github.com/Franck-Dernoncourt/NeuroNER/blob/master/src/entity_lstm.py

#1


2  

bidirectional_dynamic_rnn also has a sequence_length parameter that takes care of sequences of variable lengths.

bidirectional_dynamic_rnn还有一个sequence_length参数,用于处理可变长度的序列。

https://www.tensorflow.org/api_docs/python/tf/nn/bidirectional_dynamic_rnn (mirror):

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.

sequence_length:int32 / int64向量,大小为[batch_size],包含每个序列的实际长度。

You can see an example here: https://github.com/Franck-Dernoncourt/NeuroNER/blob/master/src/entity_lstm.py

你可以在这里看到一个例子:https://github.com/Franck-Dernoncourt/NeuroNER/blob/master/src/entity_lstm.py