|View source on GitHub|
Loads the Reuters newswire classification dataset.
Compat aliases for migration
See Migration guide for more details.
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 )
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.
| || where to cache the data (relative to |
| || integer or None. Words are ranked by how often they occur (in the training set) and only the |
| || skip the top N most frequently occurring words (which may not be informative). These words will appear as |
| ||int or None. Maximum sequence length. Any longer sequence will be truncated. Defaults to None, which means no truncation.|
| ||Float between 0 and 1. Fraction of the dataset to be used as test data. Defaults to 0.2, meaning 20% of the dataset is used as test data.|
| ||int. Seed for reproducible data shuffling.|
| ||int. The start of a sequence will be marked with this character. Defaults to 1 because 0 is usually the padding character.|
| || int. The out-of-vocabulary character. Words that were cut out because of the |
| ||int. Index actual words with this index and higher.|
| ||Used for backwards compatibility.|
| Tuple of Numpy arrays: |
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
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_wordscut here. Words that were not seen in the training set but are in the test set have simply been skipped.
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.