def build_input_fns(data_dir, batch_size):
with open(download(data_dir, "<STR_LIT>"), "<STR_LIT:r>") as f:<EOL><INDENT>words_to_idx = pickle.load(f)<EOL><DEDENT>num_words = len(words_to_idx)<EOL>vocabulary = [None] * num_words<EOL>for word, idx in words_to_idx.items():<EOL><INDENT>vocabulary[idx] = word<EOL><DEDENT>def train_input_fn():<EOL><INDENT>dataset = newsgroups_dataset(<EOL>data_dir, "<STR_LIT:train>", num_words, shuffle_and_repeat=True)<EOL>dataset = dataset.batch(batch_size).prefetch(<NUM_LIT:32>)<EOL>return tf.compat.v1.data.make_one_shot_iterator(dataset).get_next()<EOL><DEDENT>def eval_input_fn():<EOL><INDENT>dataset = newsgroups_dataset(<EOL>data_dir, "<STR_LIT:test>", num_words, shuffle_and_repeat=False)<EOL>dataset = dataset.batch(batch_size)<EOL>return tf.compat.v1.data.make_one_shot_iterator(dataset).get_next()<EOL><DEDENT>return train_input_fn, eval_input_fn, vocabulary<EOL>
Builds iterators for train and evaluation data.

    Each object is represented as a bag-of-words vector.

    Arguments:
      data_dir: Folder in which to store the data.
      batch_size: Batch size for both train and evaluation.

    Returns:
      train_input_fn: A function that returns an iterator over the training data.
      eval_input_fn: A function that returns an iterator over the evaluation data.
      vocabulary: A mapping of word's integer index to the corresponding string.