tf.sequence_mask(lengths, maxlen=None, dtype=tf.bool, name=None)
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]]
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.ValueError
: if the arguments have invalid rank.Defined in tensorflow/python/ops/array_ops.py
.
© 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