tf.keras.datasets.imdb.load_data
Stay organized with collections
Save and categorize content based on your preferences.
Loads the IMDB dataset.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
`tf.compat.v1.keras.datasets.imdb.load_data`
tf.keras.datasets.imdb.load_data(
path='imdb.npz',
num_words=None,
skip_top=0,
maxlen=None,
seed=113,
start_char=1,
oov_char=2,
index_from=3,
**kwargs
)
This is a dataset of 25,000 movies reviews from IMDB, labeled by sentiment
(positive/negative). Reviews have been preprocessed, and each review 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 the pad token.
Args |
path
|
where to cache the data (relative to ~/.keras/dataset ).
|
num_words
|
integer or None. Words are
ranked by how often they occur (in the training set) and only
the num_words most frequent words are kept. Any less frequent word
will appear as oov_char value in the sequence data. If None,
all words are kept. Defaults to None .
|
skip_top
|
skip the top N most frequently occurring words
(which may not be informative). These words will appear as
oov_char value in the dataset. When 0, no words are
skipped. Defaults to 0 .
|
maxlen
|
int or None. Maximum sequence length.
Any longer sequence will be truncated. None, means no truncation.
Defaults to None .
|
seed
|
int. Seed for reproducible data shuffling.
|
start_char
|
int. The start of a sequence will be marked with this
character. 0 is usually the padding character. Defaults to 1 .
|
oov_char
|
int. The out-of-vocabulary character.
Words that were cut out because of the num_words or
skip_top limits will be replaced with this character.
|
index_from
|
int. Index actual words with this index and higher.
|
**kwargs
|
Used for backwards compatibility.
|
Returns |
Tuple of Numpy arrays: (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 maxlen
.
y_train, y_test: lists of integer labels (1 or 0).
Raises |
ValueError
|
in case maxlen is so low
that no input sequence could be kept.
|
Note that 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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[],null,["# tf.keras.datasets.imdb.load_data\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/datasets/imdb.py#L29-L169) |\n\nLoads the [IMDB dataset](https://ai.stanford.edu/%7Eamaas/data/sentiment/).\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n\\`tf.compat.v1.keras.datasets.imdb.load_data\\`\n\n\u003cbr /\u003e\n\n tf.keras.datasets.imdb.load_data(\n path='imdb.npz',\n num_words=None,\n skip_top=0,\n maxlen=None,\n seed=113,\n start_char=1,\n oov_char=2,\n index_from=3,\n **kwargs\n )\n\nThis is a dataset of 25,000 movies reviews from IMDB, labeled by sentiment\n(positive/negative). Reviews have been preprocessed, and each review is\nencoded as a list of word indexes (integers).\nFor convenience, words are indexed by overall frequency in the dataset,\nso that for instance the integer \"3\" encodes the 3rd most frequent word in\nthe data. This allows for quick filtering operations such as:\n\"only consider the top 10,000 most\ncommon words, but eliminate the top 20 most common words\".\n\nAs a convention, \"0\" does not stand for a specific word, but instead is used\nto encode the pad token.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `path` | where to cache the data (relative to `~/.keras/dataset`). |\n| `num_words` | integer or None. Words are ranked by how often they occur (in the training set) and only the `num_words` most frequent words are kept. Any less frequent word will appear as `oov_char` value in the sequence data. If None, all words are kept. Defaults to `None`. |\n| `skip_top` | skip the top N most frequently occurring words (which may not be informative). These words will appear as `oov_char` value in the dataset. When 0, no words are skipped. Defaults to `0`. |\n| `maxlen` | int or None. Maximum sequence length. Any longer sequence will be truncated. None, means no truncation. Defaults to `None`. |\n| `seed` | int. Seed for reproducible data shuffling. |\n| `start_char` | int. The start of a sequence will be marked with this character. 0 is usually the padding character. Defaults to `1`. |\n| `oov_char` | int. The out-of-vocabulary character. Words that were cut out because of the `num_words` or `skip_top` limits will be replaced with this character. |\n| `index_from` | int. Index actual words with this index and higher. |\n| `**kwargs` | Used for backwards compatibility. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`. ||\n\n\u003cbr /\u003e\n\n**x_train, x_test** : lists of sequences, which are lists of indexes\n(integers). If the num_words argument was specific, the maximum\npossible index value is `num_words - 1`. If the `maxlen` argument was\nspecified, the largest possible sequence length is `maxlen`.\n\n**y_train, y_test**: lists of integer labels (1 or 0).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------|\n| `ValueError` | in case `maxlen` is so low that no input sequence could be kept. |\n\n\u003cbr /\u003e\n\nNote that the 'out of vocabulary' character is only used for\nwords that were present in the training set but are not included\nbecause they're not making the `num_words` cut here.\nWords that were not seen in the training set but are in the test set\nhave simply been skipped."]]