code: def cycle_gan_internal(inputs, targets, _, hparams):
      """Cycle GAN, main step used for training."""
      with tf.variable_scope("cycle_gan"):
          # Embed inputs and targets.
          inputs_orig, targets_orig = tf.to_int32(inputs), tf.to_int32(
              targets
          )
          inputs = common_layers.embedding(
              inputs_orig,
              hparams.vocab_size,
              hparams.hidden_size,
              "embed",
          )
          targets = common_layers.embedding(
              targets_orig,
              hparams.vocab_size,
              hparams.hidden_size,
              "embed",
              reuse=True,
          )
  
          x, _ = split_on_batch(inputs)
          _, y = split_on_batch(targets)
  
          # Y --> X
          y_fake = generator(y, hparams, "Fy", reuse=False)
          y_to_x_loss = lossfn(y, y_fake, True, hparams, True, "YtoX")
  
          # X --> Y
          x_fake = generator(x, hparams, "Gx", reuse=False)
          x_to_y_loss = lossfn(y, x_fake, True, hparams, True, "XtoY")
  
          # Cycle-Consistency
          y_fake_ = generator(y_fake, hparams, "Gx", reuse=True)
          x_fake_ = generator(x_fake, hparams, "Fy", reuse=True)
          x_to_x_loss = hparams.cycle_loss_multiplier1 * tf.reduce_mean(
              tf.abs(x_fake_ - x)
          )
          y_to_y_loss = hparams.cycle_loss_multiplier2 * tf.reduce_mean(
              tf.abs(y_fake_ - y)
          )
          cycloss = x_to_x_loss + y_to_y_loss
  
          sample_generated = generator(
              inputs, hparams, "Gx", reuse=True
          )
          sample_generated = tf.layers.dense(
              sample_generated,
              hparams.vocab_size,
              name="softmax",
              reuse=None,
          )
          sample_generated = tf.stop_gradient(
              tf.expand_dims(sample_generated, axis=2)
          )
  
          losses = {
              "cycloss": cycloss,
              "y_to_x_loss": y_to_x_loss,
              "x_to_y_loss": x_to_y_loss,
          }
  
          return sample_generated, losses
  
file_path: tensor2tensor/tensor2tensor/models/research/cycle_gan.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.models.research import transformer_vae
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling a global function with example usage: cycle_gan_internal(inputs, targets, _, hparams) and returns: sample_generated,  losses