W3cubDocs

/TensorFlow Python

tf.sequence_mask(lengths, maxlen=None, dtype=tf.bool, name=None)

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]]

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.

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