def _build_aux_sequences(self, target_embeddings, target_vocab_size,
                           central_lang_tag="<en>"):
    """Builds sequences in an auxiliary language."""
    aux_keys = ["src>aux", "tgt>aux"]

    # Determine which src and tgt sentences are central.
    central_lang_id = translate_multilingual.get_tag_id(central_lang_tag)
    self._is_central = {
        "src>aux": tf.squeeze(
            self._body_features["input_tags_raw"] == central_lang_id),
        "tgt>aux": tf.squeeze(
            self._body_features["target_tags_raw"] == central_lang_id)}

    for key in aux_keys:
      # Encode (if necessary).
      if key not in self.enc_outputs:
        encode_func = self.get_encode_func(*self.inputs[key])
        self.enc_outputs[key] = encode_func()

      # Decode (if necessary).
      if key not in self.dec_outputs:
        # Prepare for decoding.
        target_seqs, target_lens = self.targets[key]
        hiddens = self.enc_outputs[key].outputs
        hiddens_length = self.inputs[key][1]
        enc_state = self.enc_outputs[key].final_state
        decoder_hparams = contrib_training.HParams(auxiliary=True)
        # Decode.
        decode_func = self.get_decode_func(
            target_embeddings,
            target_seqs, target_lens,
            hiddens, hiddens_length,
            enc_state,
            mode=self._hparams.mode,
            decoder_hparams=decoder_hparams,
            decoder_iterations=self._hparams.aux_decode_length)
        self.dec_outputs[key] = decode_func()
        # Compute logits.
        self.dec_outputs[key]["logits"] = model_utils.build_logits(
            sequences=tf.expand_dims(
                self.dec_outputs[key]["rnn_output"], axis=2),
            embeddings=target_embeddings,
            vocab_size=target_vocab_size)
        # Protect central directions from the gradients.
        for element in self.dec_outputs[key]:
          self.dec_outputs[key][element] = tf.where(
              self._is_central[key],
              tf.stop_gradient(self.dec_outputs[key][element]),
              self.dec_outputs[key][element])

    return aux_keys
Builds sequences in an auxiliary language.
language/labs/consistent_zero_shot_nmt/models/agreement.py