def infer(model_config,
          input_embeddings,
          source_len,
          output_vocab_size,
          output_vocab_embeddings_table,
          mode,
          input_copy_mask=None,
          clean_output_mask=None,
          beam_size=1):
  """Constructs encoder and decoder transformation for training and eval.

  In the shapes described below, B is batch size, L is sequence length,
  D is the dimensionality of the model embeddings, T is the target vocab
  size, W is the beam width, and X is the max decode length.

  Args:
    model_config: ModelConfig proto.
    input_embeddings: Tensor of shape (B, L, D) representing inputs.
    source_len: Tensor of shape (B) containing length of each input sequence.
    output_vocab_size: Size of output vocabulary.
    output_vocab_embeddings_table: Tensor of shape (T, D) representing table of
      embeddings for output symbols.
    mode: Enum indicating model mode, which should be INFER.
    input_copy_mask: Mask for copying actions.
    clean_output_mask: MAsk for preventing generating new values.
    beam_size: Size of beam for inference.

  Returns:
    A dictionary of tensors. The dictionary will contain
    'predicted_ids' tensor of shape (W, X) and 'scores' tensor of
    shape (W).

  Raises:
    ValueError: Invalid model configuration.
  """
  # Currently, we don't allow batched inputs for inference. Support for this
  # could be added in the future, but this assumption simplifies some code.
  if input_embeddings.get_shape()[0] != 1:
    raise ValueError("Batch size must be 1 for inference.")
  if beam_size > 1:
    return _beam_decode(
        input_embeddings,
        ALPHA,
        output_vocab_size,
        constants.TARGET_END_SYMBOL_ID,
        constants.TARGET_START_SYMBOL_ID,
        output_vocab_embeddings_table,
        source_len,
        model_config,
        mode,
        beam_size,
        input_copy_mask,
        clean_output_mask=clean_output_mask)
  else:
    return _greedy_decode(
        input_embeddings,
        output_vocab_size,
        constants.TARGET_END_SYMBOL_ID,
        constants.TARGET_START_SYMBOL_ID,
        output_vocab_embeddings_table,
        source_len,
        model_config,
        mode,
        input_copy_mask,
        clean_output_mask=clean_output_mask)
Constructs encoder and decoder transformation for training and eval.

  In the shapes described below, B is batch size, L is sequence length,
  D is the dimensionality of the model embeddings, T is the target vocab
  size, W is the beam width, and X is the max decode length.

  Args:
    model_config: ModelConfig proto.
    input_embeddings: Tensor of shape (B, L, D) representing inputs.
    source_len: Tensor of shape (B) containing length of each input sequence.
    output_vocab_size: Size of output vocabulary.
    output_vocab_embeddings_table: Tensor of shape (T, D) representing table of
      embeddings for output symbols.
    mode: Enum indicating model mode, which should be INFER.
    input_copy_mask: Mask for copying actions.
    clean_output_mask: MAsk for preventing generating new values.
    beam_size: Size of beam for inference.

  Returns:
    A dictionary of tensors. The dictionary will contain
    'predicted_ids' tensor of shape (W, X) and 'scores' tensor of
    shape (W).

  Raises:
    ValueError: Invalid model configuration.
  
language/xsp/model/transformer.py