當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.keras.datasets.imdb.get_word_index用法及代碼示例

檢索將單詞映射到 IMDB 數據集中的索引的字典。

用法

tf.keras.datasets.imdb.get_word_index(
    path='imdb_word_index.json'
)

參數

  • path 在哪裏緩存數據(相對於 ~/.keras/dataset )。

返回

  • 詞索引詞典。鍵是字符串,值是它們的索引。

例子:

# Retrieve the training sequences.
(x_train, _), _ = keras.datasets.imdb.load_data()
# Retrieve the word index file mapping words to indices
word_index = keras.datasets.imdb.get_word_index()
# Reverse the word index to obtain a dict mapping indices to words
inverted_word_index = dict((i, word) for (word, i) in word_index.items())
# Decode the first sequence in the dataset
decoded_sequence = " ".join(inverted_word_index[i] for i in x_train[0])

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.datasets.imdb.get_word_index。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。