MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / indices_to_words

Function indices_to_words

sentiment/python/imdb.py:59–70  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

57
58
59def 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
73def get_imdb_data(vocabulary_size, max_len):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected