code: def testMultipleTargetModalities(self):
      # Use existing hparams and override target modality.
      hparams = trainer_lib.create_hparams(
          "transformer_tiny",
          data_dir=algorithmic.TinyAlgo.data_dir,
          problem_name="tiny_algo",
      )
      # Manually turn off sharing. It is not currently supported for multitargets.
      hparams.shared_embedding_and_softmax_weights = (
          0  # pylint: disable=line-too-long
      )
      hparams.problem_hparams.modality = {
          "targets": hparams.problem_hparams.modality["targets"],
          "targets_A": hparams.problem_hparams.modality["targets"],
          "targets_B": hparams.problem_hparams.modality["targets"],
      }
      hparams.problem_hparams.vocab_size = {
          "targets": hparams.problem_hparams.vocab_size["targets"],
          "targets_A": hparams.problem_hparams.vocab_size["targets"],
          "targets_B": hparams.problem_hparams.vocab_size["targets"],
      }
      hparams.problem._hparams = hparams.problem_hparams
  
      # Dataset
      problem = hparams.problem
      dataset = problem.dataset(
          tf_estimator.ModeKeys.TRAIN, algorithmic.TinyAlgo.data_dir
      )
      dataset = dataset.repeat(None).padded_batch(
          10, dataset.output_shapes
      )
      features = dataset.make_one_shot_iterator().get_next()
      features = data_reader.standardize_shapes(features)
      features["targets_A"] = features["targets_B"] = features[
          "targets"
      ]
  
      # Model
      model = registry.model("transformer")(
          hparams, tf_estimator.ModeKeys.TRAIN
      )
  
      def body(args, mb=model.body):
          out = mb(args)
          return {"targets": out, "targets_A": out, "targets_B": out}
  
      model.body = body
  
      logits, losses = model(features)
  
      self.assertTrue("training" in losses)
      loss = losses["training"]
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          sess.run([logits, loss])
  
file_path: tensor2tensor/tensor2tensor/utils/trainer_lib_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from tensor2tensor.data_generators import algorithmic
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import data_reader
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import trainer_lib
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 5 for calling the TrainerLibTest obj's underlying member method code with example usage: obj.testMultipleTargetModalities() and returns: dict