def create_placeholder_inputs(use_segment_ids, use_foreign_key_features,
                              use_alignment_features):
  """Generate model input with a placeholder for serialized SequenceExample."""
  feature_keys = FEATURE_KEYS

  if use_foreign_key_features:
    feature_keys.append(constants.FOREIGN_KEY_KEY)
  if use_segment_ids:
    feature_keys.append(constants.SEGMENT_ID_KEY)
  if use_alignment_features:
    feature_keys.append(constants.ALIGNED_KEY)

  serialized_example_placeholder = tf.placeholder(
      dtype=tf.string, shape=[], name='input_example_tensor')
  decoder = _get_sequence_decoder(
      use_segment_ids=use_segment_ids,
      use_foreign_key_features=use_foreign_key_features,
      string_alignment_features=use_alignment_features)

  decode_items = feature_keys + LABEL_KEYS
  decoded = decoder.decode(serialized_example_placeholder, decode_items)
  # Expand dimensions to create 'batch' of size 1.
  decoded_dict = {
      k: tf.expand_dims(tensor, 0) for k, tensor in zip(decode_items, decoded)
  }
  features = {k: decoded_dict[k] for k in feature_keys}
  labels = {k: decoded_dict[k] for k in LABEL_KEYS}
  return (serialized_example_placeholder, features, labels)
Generate model input with a placeholder for serialized SequenceExample.
language/xsp/model/input_pipeline.py