Get word index. Args: reverse: Reverse the index, so that the returned index is from index values to words. Returns: The word index as a `dict`.
(reverse=False)
| 41 | |
| 42 | |
| 43 | def get_word_index(reverse=False): |
| 44 | """Get word index. |
| 45 | |
| 46 | Args: |
| 47 | reverse: Reverse the index, so that the returned index is from index values |
| 48 | to words. |
| 49 | |
| 50 | Returns: |
| 51 | The word index as a `dict`. |
| 52 | """ |
| 53 | word_index = tf.keras.datasets.imdb.get_word_index() |
| 54 | if reverse: |
| 55 | word_index = dict((word_index[key], key) for key in word_index) |
| 56 | return word_index |
| 57 | |
| 58 | |
| 59 | def indices_to_words(reverse_index, indices): |