class_docstr: Learns performance embedding and concatenates it with melody embedding.
class_docstr_tok: ["Learns","performance","embedding","and","concatenates","it","with","melody","embedding","."]
docstr: Transformer main model_fn.
  
  Args:
    features: Map of features to the model. Should contain the following:
        "inputs": Transformer inputs. [batch_size, input_length, 1,
          hidden_dim].
        "targets": Target decoder outputs. [batch_size, decoder_length, 1,
          hidden_dim]
        "target_space_id": A scalar int from data_generators.problem.SpaceID.
  
  Returns:
    Final decoder representation. [batch_size, decoder_length, hidden_dim]
docstr_tok: ["Transformer","main","model_fn",".","Args",":","features",":","Map","of","features","to","the","model",".","Should","contain","the","following",":","``","inputs","''",":","Transformer","inputs",".","[","batch_size",",","input_length",",","1",",","hidden_dim","]",".","``","targets","''",":","Target","decoder","outputs",".","[","batch_size",",","decoder_length",",","1",",","hidden_dim","]","``","target_space_id","''",":","A","scalar","int","from","data_generators.problem.SpaceID",".","Returns",":","Final","decoder","representation",".","[","batch_size",",","decoder_length",",","hidden_dim","]"]
code: def body(self, features):
      """Transformer main model_fn.
  
      Args:
        features: Map of features to the model. Should contain the following:
            "inputs": Transformer inputs. [batch_size, input_length, 1,
              hidden_dim].
            "targets": Target decoder outputs. [batch_size, decoder_length, 1,
              hidden_dim]
            "target_space_id": A scalar int from data_generators.problem.SpaceID.
  
      Returns:
        Final decoder representation. [batch_size, decoder_length, hidden_dim]
      """
      hparams = self._hparams
  
      losses = []
  
      if self.has_input:
          # extract appropriate performance and melody inputs
          perf_inputs = features["performance"]
          mel_inputs = features["melody"]
          target_space = features["target_space_id"]
          encoder_output, encoder_decoder_attention_bias = self.encode(
              perf_inputs,
              mel_inputs,
              target_space,
              hparams,
              features=features,
              losses=losses,
          )
      else:
          encoder_output, encoder_decoder_attention_bias = (None, None)
  
      targets = features["targets"]
      targets_shape = common_layers.shape_list(targets)
      targets = common_layers.flatten4d3d(targets)
      (
          decoder_input,
          decoder_self_attention_bias,
      ) = self._prepare_decoder_fn(targets, hparams, features=features)
  
      # Not all subclasses of Transformer support keyword arguments related to
      # recurrent memory, so only pass these arguments if memory is enabled.
      decode_kwargs = {}
      if self.recurrent_memory_by_layer is not None:
          # TODO(kitaev): The chunk_number feature currently has the same shape as
          # "targets", but this is only for the purposes of sharing sharding code.
          # In fact every token within an example must have the same chunk number.
          chunk_number_each_token = tf.squeeze(
              features["chunk_number"], (-1, -2)
          )
          chunk_number_each_example = chunk_number_each_token[:, 0]
          # Uncomment the code below to verify that tokens within a batch share the
          # same chunk number:
          # with tf.control_dependencies([
          #     tf.assert_equal(chunk_number_each_token,
          #                     chunk_number_each_example[:, None])
          # ]):
          #   chunk_number_each_example = tf.identity(chunk_number_each_example)
          decode_kwargs = dict(
              recurrent_memory_by_layer=self.recurrent_memory_by_layer,
              chunk_number=chunk_number_each_example,
          )
      decoder_output = self.decode(
          decoder_input,
          encoder_output,
          encoder_decoder_attention_bias,
          decoder_self_attention_bias,
          hparams,
          nonpadding=features_to_nonpadding(features, "targets"),
          losses=losses,
          **decode_kwargs,
      )
      expected_attentions = features.get("expected_attentions")
      if expected_attentions is not None:
          attention_loss = (
              common_attention.encoder_decoder_attention_loss(
                  expected_attentions,
                  self.attention_weights,
                  hparams.expected_attention_loss_type,
                  hparams.expected_attention_loss_multiplier,
              )
          )
          return decoder_output, {"attention_loss": attention_loss}
  
      ret = tf.reshape(decoder_output, targets_shape)
      if losses:
          return ret, {"extra_loss": tf.add_n(losses)}
      else:
          return ret
  
imports: from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.layers import transformer_layers
  from tensor2tensor.models.transformer import Transformer, transformer_decoder, transformer_prepare_encoder, transformer_prepare_decoder, features_to_nonpadding, _init_transformer_cache
  from tensor2tensor.utils import mlperf_log
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 4 for calling the MelodyPerformanceTransformer obj's underlying member method code with example usage: obj.body(features) and returns: decoder_output,  dict, ret,  dict, ret