tf.sequence_mask
tf.sequence_mask
tf.sequence_mask
sequence_mask( lengths, maxlen=None, dtype=tf.bool, name=None )
Defined in tensorflow/python/ops/array_ops.py
.
See the guide: Tensor Transformations > Slicing and Joining
Return a mask tensor representing the first N positions of each row.
Example:
tf.sequence_mask([1, 3, 2], 5) = [[True, False, False, False, False], [True, True, True, False, False], [True, True, False, False, False]]
Args:
-
lengths
: 1D integer tensor, all its values < maxlen. -
maxlen
: scalar integer tensor, maximum length of each row. Default: use maximum over lengths. -
dtype
: output type of the resulting tensor. -
name
: name of the op.
Returns:
A 2D mask tensor, as shown in the example above, cast to specified dtype.
Raises:
-
ValueError
: if the arguments have invalid rank.
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/sequence_mask