Skip to content

Instantly share code, notes, and snippets.

@adamoudad
Created March 20, 2021 21:11
Show Gist options
  • Save adamoudad/721922b0841794fa64e7f67521e9e5f3 to your computer and use it in GitHub Desktop.
Save adamoudad/721922b0841794fa64e7f67521e9e5f3 to your computer and use it in GitHub Desktop.
index_offset = 3
word_index = imdb.get_word_index(path="imdb_word_index.json")
word_index = {k: (v + index_offset) for k,v in word_index.items()}
word_index["<PAD>"] = 0
word_index["<START>"] = 1
word_index["<UNK>"] = 2
word_index["<UNUSED>"] = 3
index_to_word = { v: k for k, v in word_index.items()}
def recover_text(sample, index_to_word):
return ' '.join([index_to_word[i] for i in sample])
recover_text(x_train[50], index_to_word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment