tf.keras.datasets.reuters.load_data( path="reuters.npz", num_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113, start_char=1, oov_char=2, index_from=3, **kwargs )
Loads the Reuters newswire classification dataset.
This is a dataset of 11,228 newswires from Reuters, labeled over 46 topics.
This was originally generated by parsing and preprocessing the classic Reuters-21578 dataset, but the preprocessing code is no longer packaged with Keras. See this GitHub discussion for more info.
Each newswire is encoded as a list of word indexes (integers). For convenience, words are indexed by overall frequency in the dataset, so that for instance the integer "3" encodes the 3rd most frequent word in the data. This allows for quick filtering operations such as: "only consider the top 10,000 most common words, but eliminate the top 20 most common words".
As a convention, "0" does not stand for a specific word, but instead is used to encode any unknown word.
num_wordsmost frequent words are kept. Any less frequent word will appear as
oov_charvalue in the sequence data. If None, all words are kept. Defaults to
oov_charvalue in the dataset. 0 means no words are skipped. Defaults to
1.. Fraction of the dataset to be used as test data.
0.2means that 20% of the dataset is used as test data. Defaults to
skip_toplimits will be replaced with this character.
(x_train, y_train), (x_test, y_test).
x_train, x_test: lists of sequences, which are lists of indexes
(integers). If the num_words argument was specific, the maximum
possible index value is
num_words - 1. If the
maxlen argument was
specified, the largest possible sequence length is
y_train, y_test: lists of integer labels (1 or 0).
Note: The 'out of vocabulary' character is only used for
words that were present in the training set but are not included
because they're not making the
num_words cut here.
Words that were not seen in the training set but are in the test set
have simply been skipped.
Retrieves a dict mapping words to their index in the Reuters dataset.
Actual word indices starts from 3, with 3 indices reserved for: 0 (padding), 1 (start), 2 (oov).
E.g. word index of 'the' is 1, but the in the actual training data, the index of 'the' will be 1 + 3 = 4. Vice versa, to translate word indices in training data back to words using this mapping, indices need to substract 3.
The word index dictionary. Keys are word strings, values are their index.