# 从分词器中获取词索引数组(word,int)
word_index = tokenizer.word_index
# 将词索引键值颠倒(int word)
reverse_word_index = dict([(value,word) for (word,value) in word_index.items()])
# 将train_data的第一条数据解码
# 索引减去3,因为0、1、2是为“padding”(填充)、“start of sequence”(序列开始)、“unknown”(未知词)分别保留的索引
decoded_review = ' '.join([reverse_word_index.get(i-3,'?') for i in train_data[0]])
NLP解码
最新推荐文章于 2023-03-12 18:50:43 发布