如何使用numpy数组从单词映射中检索单词? [Tensorflow RNN]文本分类

时间:2016-06-30 04:35:11

标签: machine-learning tensorflow

以下是我所拥有的:

vocab_processor = skflow.preprocessing.VocabularyProcessor(MAX_DOCUMENT_LENGTH)
X_train = np.array(list(vocab_processor.fit_transform(X_train)))
X_test = np.array(list(vocab_processor.transform(X_test)))

现在,它在单词词典中创建了一组nidy单词。 如果我想从字典中找回这些单词,我该怎么办?

有一个名为reverese(document)的函数,但在这种情况下它不起作用。它返回包含标记的列表。

['What is most beautiful in <UNK> men is something feminine'
"The camera makes everyone a tourist in other people's reality"
'<UNK> in reality is the worst of all evils because' ...,
'<UNK> aware that no bank would do this as they'
'<UNK> keep sending you many details through the post like'
'<UNK> banking transactions should be conducted in a secure place']

1 个答案:

答案 0 :(得分:1)

这会为您提供 id:word

w_dict = {v:k for k,v in vocab_processor.vocabulary_._mapping.items()}

然后你可以得到这样的话:

words = w_dict.values()