class_docstr: Universal Transformer Encoder: Has no decoder (e.g.for classification).
class_docstr_tok: ["Universal","Transformer","Encoder",":","Has","no","decoder","(","e.g.for","classification",")","."]
docstr: Encode transformer inputs.
  
  Args:
    inputs: Transformer inputs [batch_size, input_length, input_height,
      hidden_dim] which will be flattened along the two spatial dimensions.
    target_space: scalar, target space ID.
    hparams: hyperparmeters for model.
    features: optionally pass the entire features dictionary as well.
      This is needed now for "packed" datasets.
    losses: Unused.
  
  Returns:
    Tuple of:
        encoder_output: Encoder representation.
            [batch_size, input_length, hidden_dim]
        encoder_extra_output: which is extra encoder output used in some
          variants of the model (e.g. in ACT, to pass the ponder-time to body)
docstr_tok: ["Encode","transformer","inputs",".","Args",":","inputs",":","Transformer","inputs","[","batch_size",",","input_length",",","input_height",",","hidden_dim","]","which","will","be","flattened","along","the","two","spatial","dimensions",".","target_space",":","scalar",",","target","space","ID",".","hparams",":","hyperparmeters","for","model",".","features",":","optionally","pass","the","entire","features","dictionary","as","well",".","This","is","needed","now","for","``","packed","''","datasets",".","losses",":","Unused",".","Returns",":","Tuple","of",":","encoder_output",":","Encoder","representation",".","[","batch_size",",","input_length",",","hidden_dim","]","encoder_extra_output",":","which","is","extra","encoder","output","used","in","some","variants","of","the","model","(","e.g",".","in","ACT",",","to","pass","the","ponder-time","to","body",")"]
code: def encode(
      self, inputs, target_space, hparams, features=None, losses=None
  ):
      """Encode transformer inputs.
  
      Args:
        inputs: Transformer inputs [batch_size, input_length, input_height,
          hidden_dim] which will be flattened along the two spatial dimensions.
        target_space: scalar, target space ID.
        hparams: hyperparmeters for model.
        features: optionally pass the entire features dictionary as well.
          This is needed now for "packed" datasets.
        losses: Unused.
  
      Returns:
        Tuple of:
            encoder_output: Encoder representation.
                [batch_size, input_length, hidden_dim]
            encoder_extra_output: which is extra encoder output used in some
              variants of the model (e.g. in ACT, to pass the ponder-time to body)
      """
      del losses
      inputs = common_layers.flatten4d3d(inputs)
  
      (
          encoder_input,
          self_attention_bias,
          _,
      ) = transformer.transformer_prepare_encoder(
          inputs, target_space, hparams
      )
  
      encoder_input = tf.nn.dropout(
          encoder_input, 1.0 - hparams.layer_prepostprocess_dropout
      )
  
      (
          encoder_output,
          encoder_extra_output,
      ) = universal_transformer_util.universal_transformer_encoder(
          encoder_input,
          self_attention_bias,
          hparams,
          nonpadding=transformer.features_to_nonpadding(
              features, "inputs"
          ),
          save_weights_to=self.attention_weights,
      )
  
      return encoder_output, encoder_extra_output
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.models import transformer
  from tensor2tensor.models.research import universal_transformer_util
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling the UniversalTransformerEncoder obj's underlying member method code with example usage: obj.encode(inputs, target_space, hparams, features, losses) and returns: encoder_output,  encoder_extra_output