在用于建模IMDB序列数据(https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py)的LSTM上的keras示例中,在输入到LSTM层之前有一个嵌入层:
model.add(Embedding(max_features,128)) #max_features=20000
model.add(LSTM(128))
嵌入层真正做了什么?在这种情况下,这是否意味着进入LSTM层的输入序列的长度是128?如果是这样,我可以将LSTM层写为:
model.add(LSTM(128,input_shape=(128,1))
但是也注意到输入X_train已经过pad_sequences处理:
print('Pad sequences (samples x time)')
X_train = sequence.pad_sequences(X_train, maxlen=maxlen) #maxlen=80
X_test = sequence.pad_sequences(X_test, maxlen=maxlen) #maxlen=80
看来输入序列长度是80?
1 回答
To quote the documentation:
基本上,这会将索引(表示您的IMDB评论包含的单词)转换为具有给定大小的向量(在您的情况下为128) .
如果你不知道嵌入是什么,here is the wikipedia definition:
回到你提出的另一个问题:
不完全的 . 对于经常性网络,您将拥有时间维度和要素维度 . 128是您的要素维度,因为每个嵌入向量应具有多少维度 . 示例中的时间维度是
maxlen
中存储的内容,用于生成训练序列 .无论你提供什么128到LSTM layer is the actual number of output units of the LSTM .