MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _reverse_seq

Function _reverse_seq

tensorflow/contrib/learn/python/learn/models.py:188–213  ·  view source on GitHub ↗

Reverse a list of Tensors up to specified lengths. Args: input_seq: Sequence of seq_len tensors of dimension (batch_size, depth) lengths: A tensor of dimension batch_size, containing lengths for each sequence in the batch. If "None" is specified, simply rev

(input_seq, lengths)

Source from the content-addressed store, hash-verified

186## This will be in TensorFlow 0.7.
187## TODO(ilblackdragon): Clean this up when it's released
188def _reverse_seq(input_seq, lengths):
189 """Reverse a list of Tensors up to specified lengths.
190
191 Args:
192 input_seq: Sequence of seq_len tensors of dimension (batch_size, depth)
193 lengths: A tensor of dimension batch_size, containing lengths for each
194 sequence in the batch. If "None" is specified, simply
195 reverses the list.
196
197 Returns:
198 time-reversed sequence
199 """
200 if lengths is None:
201 return list(reversed(input_seq))
202
203 for input_ in input_seq:
204 input_.set_shape(input_.get_shape().with_rank(2))
205
206 # Join into (time, batch_size, depth)
207 s_joined = array_ops_.pack(input_seq)
208
209 # Reverse along dimension 0
210 s_reversed = array_ops_.reverse_sequence(s_joined, lengths, 0, 1)
211 # Split again into list
212 result = array_ops_.unpack(s_reversed)
213 return result
214
215
216@deprecated(None, 'Please consider `tf.nn.bidirectional_dynamic_rnn`.')

Callers 1

bidirectional_rnnFunction · 0.70

Calls 5

with_rankMethod · 0.80
set_shapeMethod · 0.45
get_shapeMethod · 0.45
packMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected