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.