轉碼_將數字解碼爲英文單詞

轉碼_將數字解碼爲英文單詞

# word_index is a dictionary mapping words to an integer index
# word_index 是一個將單詞映射爲整數索引的字典
word_index = imdb.get_word_index()

# We reverse it, mapping integer indices to words
reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])

# We decode the review; note that our indices were offset by 3
# because 0, 1 and 2 are reserved indices for "padding", "start of sequence", and "unknown".
decoded_review = ' '.join([reverse_word_index.get(i - 3, '?') for i in train_data[0]])

# 將評論解碼。注意,索引減去了 3,因爲 0、 1、 2
# 是爲“padding”(填充)、“start of sequence”(序
# 列開始)、“unknown”(未知詞)分別保留的索引
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章