def sequential_scheduled_sampling_for_t2tmodel(t2tmodel, features):
  """Schedule Sampling for T2TModels.

  Args:
    t2tmodel: T2TModel instance.
    features: {str: Tensor}. Input features.

  Returns:
    ss_logits: [batch_size, seq_len, 1, 1, vocab_size].
    losses_dict: {str: scalar Tensor}. Losses to minimize.
  """
  targets = features["targets"]
  targets_size = common_layers.shape_list(targets)
  batch_size = targets_size[0]
  seq_len = targets_size[1]
  targets = tf.reshape(targets, [batch_size, seq_len])

  adapter = ScheduledSamplingAdapter(t2tmodel, features)
  ss_tokens, ss_logits, losses_dict = sequential_scheduled_sampling(
      infer_fn=adapter.infer_fn,
      mix_fn=adapter.mix_fn,
      loss_fn=adapter.loss_fn,
      targets=targets)

  _ = ss_tokens  # unused.
  targets_vocab_size = t2tmodel.problem_hparams.vocab_size["targets"]
  ss_logits = tf.reshape(ss_logits,
                         [batch_size, seq_len, 1, 1, targets_vocab_size])

  return ss_logits, losses_dict
Schedule Sampling for T2TModels.

  Args:
    t2tmodel: T2TModel instance.
    features: {str: Tensor}. Input features.

  Returns:
    ss_logits: [batch_size, seq_len, 1, 1, vocab_size].
    losses_dict: {str: scalar Tensor}. Losses to minimize.
  
tensor2tensor/utils/scheduled_sampling.py