def transformer_edit_ops_layer(decoder_input,
                               hparams,
                               encoder_output,
                               features,
                               cache=None,
                               decode_loop_step=None,
                               nonpadding=None,
                               losses=None,
                               layer_collection=None):
  """Layer that conditions on the error tag and start and end token pointers."""
  if isinstance(encoder_output, list):  # Select forward encoder
    encoder_output = encoder_output[0]
  with tf.variable_scope("edit_ops_layer"):
    with tf.variable_scope("ffn"):
      x = decoder_input
      # Shorthand for layer preprocessing
      # pylint: disable=g-long-lambda
      preproc = lambda z: common_layers.layer_preprocess(
          z, hparams, layer_collection=layer_collection)
      # pylint: enable=g-long-lambda

      feedback_start_token = (hparams.use_start_token or
                              not hparams.feedback_end_token)
      if feedback_start_token:
        start_token = _pointer_feedback(
            features["targets_start_token"],
            encoder_output,
            shift=hparams.feedback_end_token)
      if hparams.feedback_end_token:
        end_token = _pointer_feedback(features["targets_end_token"],
                                      encoder_output)
      layer_inputs = [preproc(x)]
      if hparams.use_error_tags:
        error_tags = common_layers.shift_right_3d(
            common_layers.flatten4d3d(features["targets_error_tag"]))
        layer_inputs.append(preproc(error_tags))
      if feedback_start_token:
        layer_inputs.append(start_token)
      if hparams.feedback_end_token:
        layer_inputs.append(end_token)
      y = transformer_layers.transformer_ffn_layer(
          tf.concat(layer_inputs, axis=2),
          hparams,
          conv_padding="LEFT",
          nonpadding_mask=nonpadding,
          losses=losses,
          cache=cache,
          decode_loop_step=decode_loop_step,
          layer_collection=layer_collection)
      x = common_layers.layer_postprocess(x, y, hparams)
      return x
Layer that conditions on the error tag and start and end token pointers.
tensor2tensor/models/research/transformer_seq2edits.py