Created
January 2, 2018 15:26
-
-
Save bzamecnik/fe8fc0c3b779fb671e355b9811483bd6 to your computer and use it in GitHub Desktop.
Keras IMDB - words from indexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from keras.datasets imporrt imdb | |
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=20000) | |
x_train = sequence.pad_sequences(x_train, maxlen=80) | |
word_index = keras.datasets.imdb.get_word_index() | |
# or items() in Python 3 | |
inverted_word_index = {index:word for (word, index) in word_index.iteritems()} | |
print([inverted_word_index[i] for i in x_train[0]]) | |
# [u'for', | |
# u'anyone', | |
# u'of', | |
# u'and', | |
# u'br', | |
# u"show's", | |
# u'to', | |
# u'whether', | |
# u'from', | |
# u'than', | |
# u'out', | |
# u'themselves', | |
# u'history', | |
# u'he', | |
# u'name', | |
# u'half', | |
# u'some', | |
# u'br', | |
# u'of', | |
# u"'n", | |
# u'odd', | |
# u'was', | |
# u'two', | |
# u'most', | |
# u'of', | |
# u'mean', | |
# u'for', | |
# u'1', | |
# u'any', | |
# u'an', | |
# u'boat', | |
# u'she', | |
# u'he', | |
# u'should', | |
# u'is', | |
# u'thought', | |
# u'frog', | |
# u'but', | |
# u'of', | |
# u'script', | |
# u'you', | |
# u'not', | |
# u'while', | |
# u'history', | |
# u'he', | |
# u'heart', | |
# u'to', | |
# u'real', | |
# u'at', | |
# u'barrel', | |
# u'but', | |
# u'when', | |
# u'from', | |
# u'one', | |
# u'bit', | |
# u'then', | |
# u'have', | |
# u'two', | |
# u'of', | |
# u'script', | |
# u'their', | |
# u'with', | |
# u'her', | |
# u'nobody', | |
# u'most', | |
# u'that', | |
# u'with', | |
# u"wasn't", | |
# u'to', | |
# u'with', | |
# u'armed', | |
# u'acting', | |
# u'watch', | |
# u'an', | |
# u'for', | |
# u'with', | |
# u'heartfelt', | |
# u'film', | |
# u'want', | |
# u'an'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment