Bi-directional LSTM for variable-length sequence in Tensorflow

▼魔方 西西 提交于 2019-12-05 07:46:05

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

In forward pass, rnn cell will stop at sequence_length which is the no-padding length of the input and is a parameter in tf.nn.bidirectional_dynamic_rnn. In backward pass, it firstly use function tf.reverse_sequence to reverse the first sequence_length elements and then traverse like that in the forward pass.

https://tensorflow.google.cn/api_docs/python/tf/reverse_sequence

This op first slices input along the dimension batch_axis, and for each slice i, reverses the first seq_lengths[i] elements along the dimension seq_axis.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!