def get_sequence_length(sequence, scope=None):
"Determine the length of a sequence that has been padded with zeros."
with tf.variable_scope(scope, 'SequenceLength'):
used = tf.sign(tf.reduce_max(tf.abs(sequence), reduction_indices=[-1]))
length = tf.cast(tf.reduce_sum(used, reduction_indices=[-1]), tf.int32)
return length
评论列表
文章目录