code: def target_mask_op(data, pad_val=0):
      """Return the mask of the input sequence data based on the padding values.
  
      Parameters
      -----------
      data : tf.Tensor
          A tensor with 2 or 3 dimensions.
      pad_val: int, float, string, etc
          The value that represent padding. By default, 0. For tf.string, you may use empty string.
  
      Examples
      -----------
      >>> data = [['hello', 'world', '', '', ''],
      >>>         ['hello', 'world', 'tensorlayer', '', ''],
      >>>         ['hello', 'world', 'tensorlayer', '2.0', '']]
      >>> data = tf.convert_to_tensor(data, dtype=tf.string)
      >>> mask = tl.layers.target_mask_op(data, pad_val='')
      >>> print(mask)
      tf.Tensor(
      [[1 1 0 0 0]
       [1 1 1 0 0]
       [1 1 1 1 0]], shape=(3, 5), dtype=int32)
      >>> data = [[[1], [0], [0], [0], [0]],
      >>>         [[1], [2], [3], [0], [0]],
      >>>         [[1], [2], [0], [1], [0]]]
      >>> data = tf.convert_to_tensor(data, dtype=tf.float32)
      >>> mask = tl.layers.target_mask_op(data)
      >>> print(mask)
      tf.Tensor(
      [[1 0 0 0 0]
       [1 1 1 0 0]
       [1 1 0 1 0]], shape=(3, 5), dtype=int32)
      >>> data = [[[0,0],[2,2],[1,2],[1,2],[0,0]],
      >>>         [[2,3],[2,4],[3,2],[1,0],[0,0]],
      >>>         [[3,3],[0,1],[5,3],[1,2],[0,0]]]
      >>> data = tf.convert_to_tensor(data, dtype=tf.float32)
      >>> mask = tl.layers.target_mask_op(data)
      >>> print(mask)
      tf.Tensor(
      [[0 1 1 1 0]
       [1 1 1 1 0]
       [1 1 1 1 0]], shape=(3, 5), dtype=int32)
      """
  
      if not isinstance(data, tf.Tensor):
          raise AttributeError(
              "target_mask_op: the type of input data should be tf.Tensor but got %s."
              % type(data)
          )
      data_shape_size = data.get_shape().ndims
      if data_shape_size == 3:
          return tf.cast(
              tf.reduce_any(
                  input_tensor=tf.not_equal(data, pad_val), axis=2
              ),
              dtype=tf.int32,
          )
      elif data_shape_size == 2:
          return tf.cast(tf.not_equal(data, pad_val), dtype=tf.int32)
      elif data_shape_size == 1:
          raise ValueError(
              "target_mask_op: data_shape %s is not supported. "
              "The shape of data should have 2 or 3 dims."
              % (data.get_shape())
          )
      else:
          raise ValueError(
              "target_mask_op: handling data_shape %s hasn't been implemented! "
              "The shape of data should have 2 or 3 dims"
              % (data.get_shape())
          )
  
imports: import numpy
  import tensorflow
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.decorators import deprecated_alias
  from tensorlayer.layers.core import Layer
label_desc: Use image node_id 4 for calling a global function with example usage: target_mask_op(data, pad_val) and returns: tf, tf