【发布时间】:2020-06-23 12:34:23
【问题描述】:
将 SimpleRNN 或 LSTM 用于经典情感分析算法时(此处适用于长度
model = Sequential()
model.add(Embedding(5000, 32, input_length=250)) # Output shape: (None, 250, 32)
model.add(SimpleRNN(100)) # Output shape: (None, 100)
model.add(Dense(1, activation='sigmoid')) # Output shape: (None, 1)
在哪里指定RNN输入的哪个轴作为“时间”轴?
更准确地说,在 Embedding 层之后,给定的输入句子,例如“the cat sat on the mat”被编码为形状为 (250, 32) 的矩阵 x,其中 250 是输入文本的最大长度(以字为单位),32 是嵌入的维度。然后,在 Keras 中的哪个位置指定是否使用它:
h[t] = activation( W_h * x[:, t] + U_h * h[t-1] + b_h )
或者这个:
h[t] = activation( W_h * x[t, :] + U_h * h[t-1] + b_h )
(在这两种情况下,y[t] = activation( W_y * h[t] + b_y ))
TL;DR:如果 RNN Keras 层的输入大小为 (250, 32),默认情况下它使用哪个轴作为时间轴? Keras 或 Tensorflow 文档中的哪个位置对此进行了详细说明?
【问题讨论】:
-
默认为第二轴。你可以查看keras documentation和tensorflow documentation。
标签: classification tensorflow keras model