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: Universal Transformer main model_fn.
  
  Args:
    features: Map of features to the model. Should contain the following:
        "inputs": Transformer inputs [batch_size, input_length, hidden_dim]
        "targets": Target decoder outputs.
            [batch_size, decoder_length, hidden_dim]
        "target_space_id"
  
  Returns:
    Final decoder representation. [batch_size, decoder_length, hidden_dim]
docstr_tok: ["Universal","Transformer","main","model_fn",".","Args",":","features",":","Map","of","features","to","the","model",".","Should","contain","the","following",":","``","inputs","''",":","Transformer","inputs","[","batch_size",",","input_length",",","hidden_dim","]","``","targets","''",":","Target","decoder","outputs",".","[","batch_size",",","decoder_length",",","hidden_dim","]","``","target_space_id","''","Returns",":","Final","decoder","representation",".","[","batch_size",",","decoder_length",",","hidden_dim","]"]
code: def body(self, features):
      """Universal Transformer main model_fn.
  
      Args:
        features: Map of features to the model. Should contain the following:
            "inputs": Transformer inputs [batch_size, input_length, hidden_dim]
            "targets": Target decoder outputs.
                [batch_size, decoder_length, hidden_dim]
            "target_space_id"
  
      Returns:
        Final decoder representation. [batch_size, decoder_length, hidden_dim]
      """
      hparams = self._hparams
  
      assert self.has_input, (
          "universal_transformer_encoder is applicable on "
          "problems with inputs"
      )
  
      inputs = features["inputs"]
      target_space = features["target_space_id"]
      encoder_output, enc_extra_output = self.encode(
          inputs, target_space, hparams, features=features
      )
  
      encoder_output = tf.expand_dims(encoder_output, 2)
  
      if (
          hparams.recurrence_type == "act"
          and hparams.act_loss_weight != 0
      ):
          ponder_times, remainders = enc_extra_output
          act_loss = hparams.act_loss_weight * tf.reduce_mean(
              ponder_times + remainders
          )
          contrib.summary().scalar("act_loss", act_loss)
  
          return encoder_output, {"act_loss": act_loss}
      return encoder_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 2 for calling the UniversalTransformerEncoder obj's underlying member method code with example usage: obj.body(features) and returns: encoder_output, encoder_output,  dict