Convert an iterable of word indices into words. Args: reverse_index: An `dict` mapping word index (as `int`) to word (as `str`). indices: An iterable of word indices. Returns: Mapped words as a `list` of `str`s.
(reverse_index, indices)
| 57 | |
| 58 | |
| 59 | def indices_to_words(reverse_index, indices): |
| 60 | """Convert an iterable of word indices into words. |
| 61 | |
| 62 | Args: |
| 63 | reverse_index: An `dict` mapping word index (as `int`) to word (as `str`). |
| 64 | indices: An iterable of word indices. |
| 65 | |
| 66 | Returns: |
| 67 | Mapped words as a `list` of `str`s. |
| 68 | """ |
| 69 | return [reverse_index[i - INDEX_FROM] if i >= INDEX_FROM else 'OOV' |
| 70 | for i in indices] |
| 71 | |
| 72 | |
| 73 | def get_imdb_data(vocabulary_size, max_len): |