残差 LSTM 层

residual LSTM layers

我无法理解 keras 中 LSTM 层中的张量行为。

我已经预处理了看起来像 [样本、时间步长、特征] 的数字数据。所以 10 000 个样本、24 个时间步长和 10 个预测变量。

我想堆叠剩余连接,但我不确定我做对了:

x <- layer_input(shape = c(24,10))

x <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)

现在张量 x 的形状是 [?,?,32]。我期待 [?,32,10]。我应该将数据重塑为 [样本、特征、时间步长] 吗?然后我形成 res:

y <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)

res <- layer_add(c(x, y))

现在我不确定这是否正确,或者我应该改用它

x <- layer_input(shape = c(24,10))

y <- layer_lstm(x,units=24,activation="tanh",return_sequences=T) # same as time_steps

res <- layer_add(c(x,y)) ## perhaps here data reshaping is neccesary?

非常感谢任何见解。

JJ

LSTM 层将 return 你变暗为 (?,seq_length,out_dims),其中 out_dims 在你的情况下是 units。所以整体暗淡将是

x <- layer_input(shape = c(24,10))
# dims of x (?,24,10)
x <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)
# dims of x after lstm_layer (?,24,32)

y <- layer_lstm(x,units=32,activation="tanh",return_sequences=T)
# dims of y (?,24,32)
res <- layer_add(c(x, y))
# dims of res will be (?,24,32), it is addion of output of both lstm_layer.

更多信息,您可以