def _get_sequence_decoder(use_segment_ids, use_foreign_key_features,
                          string_alignment_features):
  """Returns a TFSequenceExampleDecoder for decoding input format."""
  keys_to_context_features = get_context_features()
  keys_to_sequence_features = get_sequence_features(use_segment_ids,
                                                    use_foreign_key_features,
                                                    string_alignment_features)

  items_to_handlers = {}

  # Context features.
  items_to_handlers[constants.OUTPUT_TYPE_KEY] = slim.tfexample_decoder.Tensor(
      constants.OUTPUT_TYPE_KEY)
  items_to_handlers[constants.WEIGHT_KEY] = slim.tfexample_decoder.Tensor(
      constants.WEIGHT_KEY)
  items_to_handlers[constants.LANGUAGE_KEY] = slim.tfexample_decoder.Tensor(
      constants.LANGUAGE_KEY)
  items_to_handlers[constants.REGION_KEY] = slim.tfexample_decoder.Tensor(
      constants.REGION_KEY)
  items_to_handlers[constants.TAG_KEY] = slim.tfexample_decoder.Tensor(
      constants.TAG_KEY, default_value='')

  # Sequence features.
  items_to_handlers[
      constants.SOURCE_WORDPIECES_KEY] = slim.tfexample_decoder.Tensor(
          constants.SOURCE_WORDPIECES_KEY)
  items_to_handlers[
      constants.COPIABLE_INPUT_KEY] = slim.tfexample_decoder.Tensor(
          constants.COPIABLE_INPUT_KEY)

  items_to_handlers[
      constants
      .TARGET_ACTION_TYPES_KEY] = slim.tfexample_decoder.ItemHandlerCallback(
          keys=[constants.TARGET_ACTION_TYPES_KEY],
          func=_get_target_action_types)
  items_to_handlers[
      constants
      .TARGET_ACTION_IDS_KEY] = slim.tfexample_decoder.ItemHandlerCallback(
          keys=[constants.TARGET_ACTION_IDS_KEY], func=_get_target_action_ids)

  # Get lengths of sequences. Easiest to do this now prior to padding.
  items_to_handlers[
      constants.SOURCE_LEN_KEY] = slim.tfexample_decoder.ItemHandlerCallback(
          keys=[constants.SOURCE_WORDPIECES_KEY],
          func=input_utils.get_source_len_fn(constants.SOURCE_WORDPIECES_KEY))
  items_to_handlers[
      constants.TARGET_LEN_KEY] = slim.tfexample_decoder.ItemHandlerCallback(
          keys=[constants.TARGET_ACTION_TYPES_KEY], func=_get_target_len)

  # Extra features.
  if use_segment_ids:
    items_to_handlers[constants.SEGMENT_ID_KEY] = slim.tfexample_decoder.Tensor(
        constants.SEGMENT_ID_KEY)

  if use_foreign_key_features:
    items_to_handlers[
        constants.FOREIGN_KEY_KEY] = slim.tfexample_decoder.Tensor(
            constants.FOREIGN_KEY_KEY)

  if string_alignment_features:
    items_to_handlers[constants.ALIGNED_KEY] = slim.tfexample_decoder.Tensor(
        constants.ALIGNED_KEY)

  decoder = sequence_example_decoder.TFSequenceExampleDecoder(
      keys_to_context_features, keys_to_sequence_features, items_to_handlers)

  return decoder
Returns a TFSequenceExampleDecoder for decoding input format.
language/xsp/model/input_pipeline.py