class_docstr: Helper to remove padding from a tensor before sending to the experts.
  
  The padding is computed for one reference tensor containing the padding mask
  and then can be applied to any other tensor of shape [dim_origin,...].
  
  Ex:
      input = [
        [tok1, tok2],
        [tok3, tok4],
        [0, 0],
        [0, 0],
        [tok5, tok6],
        [0, 0],
      ]
      output = [
        [tok1, tok2],
        [tok3, tok4],
        [tok5, tok6],
      ]
class_docstr_tok: ["Helper","to","remove","padding","from","a","tensor","before","sending","to","the","experts",".","The","padding","is","computed","for","one","reference","tensor","containing","the","padding","mask","and","then","can","be","applied","to","any","other","tensor","of","shape","[","dim_origin",",","...","]",".","Ex",":","input","=","[","[","tok1",",","tok2","]",",","[","tok3",",","tok4","]",",","[","0",",","0","]",",","[","0",",","0","]",",","[","tok5",",","tok6","]",",","[","0",",","0","]",",","]","output","=","[","[","tok1",",","tok2","]",",","[","tok3",",","tok4","]",",","[","tok5",",","tok6","]",",","]"]
docstr: Remove padding from the given tensor.
  
  Args:
    x (tf.Tensor): of shape [dim_origin,...]
  
  Returns:
    a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin
docstr_tok: ["Remove","padding","from","the","given","tensor",".","Args",":","x","(","tf.Tensor",")",":","of","shape","[","dim_origin",",","...","]","Returns",":","a","tensor","of","shape","[","dim_compressed",",","...","]","with","dim_compressed","<","=","dim_origin"]
code: def remove(self, x):
      """Remove padding from the given tensor.
  
      Args:
        x (tf.Tensor): of shape [dim_origin,...]
  
      Returns:
        a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin
      """
      with tf.name_scope("pad_reduce/remove"):
          x_shape = x.get_shape().as_list()
          x = tf.gather_nd(
              x,
              indices=self.nonpad_ids,
          )
          if not tf.executing_eagerly():
              # This is a hack but for some reason, gather_nd return a tensor of
              # undefined shape, so the shape is set up manually
              x.set_shape([None] + x_shape[1:])
      return x
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import math
  import six
  from six.moves import range
  from six.moves import zip
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers.vq_discrete import DiscreteBottleneck
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling the PadRemover obj's underlying member method code with example usage: obj.remove(x) and returns: x