【发布时间】:2020-06-19 15:41:11
【问题描述】:
将SimpleRNN 或LSTM 用于经典sentiment analysis 算法时(此处适用于长度
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 层之后,给定的输入句子,例如“坐在垫子上的猫”,被编码为形状为 (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 文档中的哪些地方对此进行了详细说明?
PS:参数个数(model.summary()给出)是13300怎么解释? W_h 有 100x32 的系数,U_h 有 100x100 的系数,b_h 有 100x1 的系数,即我们已经有 13300! W_y 和 b_y 没有剩余系数了!这怎么解释?
【问题讨论】:
标签: python tensorflow keras recurrent-neural-network