Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将Keras数据集转换为嵌入矩阵?_Python_Tensorflow_Machine Learning_Keras - Fatal编程技术网

Python 如何将Keras数据集转换为嵌入矩阵?

Python 如何将Keras数据集转换为嵌入矩阵?,python,tensorflow,machine-learning,keras,Python,Tensorflow,Machine Learning,Keras,我想使用Keras的IMDB数据集 这就是它的样子: An Input Vector Sample = [23022, 309, 6, 3, 1069, 209, 9, 2175, 30, 1, 169, 55, 14, 46, 82, 5869, 41, 393, 110, 138, 14, 5359, 58, 4477, 150, 8, 1, 5032, 5948, 482, 69, 5, 261, 12, 23022, 73935, 2003, 6, 73, 2436, 5, 63

我想使用Keras的IMDB数据集

这就是它的样子:

    An Input Vector Sample = [23022, 309, 6, 3, 1069, 209, 9, 2175, 30, 1, 169, 55, 14, 46, 82, 5869, 41, 393, 110, 138, 14, 5359, 58, 4477, 150, 8, 1, 5032, 5948, 482, 69, 5, 261, 12, 23022, 73935, 2003, 6, 73, 2436, 5, 632, 71, 6, 5359, 1, 25279, 5, 2004, 10471, 1, 5941, 1534, 34, 67, 64, 205, 140, 65, 1232, 63526, 21145, 1, 49265, 4, 1, 223, 901, 29, 3024, 69, 4, 1, 5863, 10, 694, 2, 65, 1534, 51, 10, 216, 1, 387, 8, 60, 3, 1472, 3724, 802, 5, 3521, 177, 1, 393, 10, 1238, 14030, 30, 309, 3, 353, 344, 2989, 143, 130, 5, 7804, 28, 4, 126, 5359, 1472, 2375, 5, 23022, 309, 10, 532, 12, 108, 1470, 4, 58, 556, 101, 12, 23022, 309, 6, 227, 4187, 48, 3, 2237, 12, 9, 215]

A Label Sample = 1
我就是这样得到的:

top_words = 5000
test_split = 0.30
from keras.datasets import imdb
(X, y), (X_test, y_test) = imdb.load_data()  # num_words=top_words
问题是这样的,我不知道输入句是什么样的

然后,我如何将预先训练好的单词向量之和作为该句子的特征

除了Keras还有什么办法?Scikit learn也没有imdb数据集


非常感谢你的帮助。非常感谢您的帮助。

数据集只将您发现的单词索引存储为整数序列。隐藏在
keras.datasets.imdb
中的是另一个函数,用于检索将单词索引映射回单词的词典;不幸的是,它没有明确的记录。您可以使用它将索引转换回单词,以找到句子的样子

关于如何在Keras中嵌入
层时使用预先训练好的词向量,已经有了一个很好的解决方案。由于索引可能不匹配,因此可以根据为IMDb数据集获得的字典映射加载向量