def decode_features_and_labels(sequence_decoder,
                               feature_keys,
                               label_keys,
                               data_sources,
                               batch_size,
                               static_padded_shapes=None,
                               drop_remainder=False,
                               shuffle=False,
                               num_epochs=None,
                               scope='input_fn'):
  """Creates a dataset tensor out of a dataset given placeholders."""
  with tf.variable_scope(scope):

    def decode_record(record):
      """(key, serialized SequenceExample) to dict of <feature name, Tensor>."""
      decode_items = feature_keys + label_keys
      decoded = sequence_decoder.decode(record, items=decode_items)
      return dict(list(zip(decode_items, decoded)))

    tf.logging.info('Reading from sources: ' + str(data_sources))

    # Load the datasets, and construct batches alternating between them.
    datasets = [
        get_dataset([source], num_epochs, batch_size, decode_record,
                    static_padded_shapes, shuffle, drop_remainder)
        for source in data_sources
    ]
    choices = tf.data.Dataset.range(len(datasets)).repeat()
    dataset = tf.data.experimental.choose_from_datasets(datasets, choices)

    # Separate features and labels.
    batched_examples = dataset.make_one_shot_iterator().get_next()
    features_batch = {k: batched_examples[k] for k in feature_keys}
    labels_batch = {k: batched_examples[k] for k in label_keys}

    return features_batch, labels_batch
Creates a dataset tensor out of a dataset given placeholders.
language/xsp/model/input_utils.py