code: def build_model(batch, train_data, self_sampling_proba):
      """
      Assembles the seq2seq model.
      It is the same as build_model() in baseline_seq2seq_attn.py except
      using ScheduledEmbeddingTrainingHelper.
      """
      source_embedder = tx.modules.WordEmbedder(
          vocab_size=train_data.source_vocab.size,
          hparams=config_model.embedder,
      )
  
      encoder = tx.modules.BidirectionalRNNEncoder(
          hparams=config_model.encoder
      )
  
      enc_outputs, _ = encoder(
          source_embedder(batch["source_text_ids"])
      )
  
      target_embedder = tx.modules.WordEmbedder(
          vocab_size=train_data.target_vocab.size,
          hparams=config_model.embedder,
      )
  
      decoder = tx.modules.AttentionRNNDecoder(
          memory=tf.concat(enc_outputs, axis=2),
          memory_sequence_length=batch["source_length"],
          vocab_size=train_data.target_vocab.size,
          hparams=config_model.decoder,
      )
  
      helper = tx.modules.get_helper(
          helper_type="ScheduledEmbeddingTrainingHelper",
          inputs=target_embedder(batch["target_text_ids"][:, :-1]),
          sequence_length=batch["target_length"] - 1,
          embedding=target_embedder,
          sampling_probability=self_sampling_proba,
      )
  
      training_outputs, _, _ = decoder(
          helper=helper,
          initial_state=decoder.zero_state(
              batch_size=tf.shape(batch["target_length"])[0],
              dtype=tf.float32,
          ),
      )
  
      train_op = tx.core.get_train_op(
          tx.losses.sequence_sparse_softmax_cross_entropy(
              labels=batch["target_text_ids"][:, 1:],
              logits=training_outputs.logits,
              sequence_length=batch["target_length"] - 1,
          ),
          hparams=config_model.opt,
      )
  
      start_tokens = (
          tf.ones_like(batch["target_length"])
          * train_data.target_vocab.bos_token_id
      )
      beam_search_outputs, _, _ = tx.modules.beam_search_decode(
          decoder_or_cell=decoder,
          embedding=target_embedder,
          start_tokens=start_tokens,
          end_token=train_data.target_vocab.eos_token_id,
          beam_width=config_model.beam_width,
          max_decoding_length=60,
      )
  
      return train_op, beam_search_outputs
  
file_path: texar/examples/seq2seq_exposure_bias/scheduled_sampling_main.py
imports: from io import open
  import math
  import importlib
  import tensorflow
  import texar.tf
  from rouge import Rouge
label_desc: Use image node_id 2 for calling a global function with example usage: build_model(batch, train_data, _sampling_proba) and returns: train_op,  beam_search_outputs