Keras 的默认 LSTM 是展开的还是有状态的?
Is the Keras's default LSTM unrolled or stateful?
在 Keras 文档中,stateful
和 unroll
都设置为 False
。那么,如果两者都不是,那么在 Keras 中如何进行循环呢?
Keras RNN documentaion
我查看了Keras中RNN的源代码,似乎默认操作是在每个时间步初始化LSTM。我穿了吗?
if initial_state is not None:
pass
elif self.stateful:
initial_state = self.states
else:
initial_state = self.get_initial_state(inputs)
如果我是正确的,是否意味着对于时间序列分析,设置 unroll=True
会更好?
既不是展开的也不是有状态的。
请记住,Keras 中的 "stateful" 仅表示 "two consecutive batches will be interpreted as two parts of the same sequences"。没有其他的。 (第 2 批是第 1 批的 sequel)
当然,所有 LSTM 都有状态(不可能没有)。
注意表达式 "initialize the LSTM"。每个批次 stateful=False
层将 "reset states"。实际结果是:"each batch is a group of individual sequences from start to end"。 (第 2 批不是第 1 批的 sequel)
"States"是关于"history of a sequence up to the current step"的信息。它们与 "weights" 完全不同,后者是层实际上从所有序列中学到的东西。
"Unroll" 是一种将循环计算转换为单个图形而无需循环的方法。它仅适用于短序列,它以使用更多内存为代价获得更快的处理速度。
在 Keras 文档中,stateful
和 unroll
都设置为 False
。那么,如果两者都不是,那么在 Keras 中如何进行循环呢?
Keras RNN documentaion
我查看了Keras中RNN的源代码,似乎默认操作是在每个时间步初始化LSTM。我穿了吗?
if initial_state is not None:
pass
elif self.stateful:
initial_state = self.states
else:
initial_state = self.get_initial_state(inputs)
如果我是正确的,是否意味着对于时间序列分析,设置 unroll=True
会更好?
既不是展开的也不是有状态的。
请记住,Keras 中的 "stateful" 仅表示 "two consecutive batches will be interpreted as two parts of the same sequences"。没有其他的。 (第 2 批是第 1 批的 sequel)
当然,所有 LSTM 都有状态(不可能没有)。
注意表达式 "initialize the LSTM"。每个批次 stateful=False
层将 "reset states"。实际结果是:"each batch is a group of individual sequences from start to end"。 (第 2 批不是第 1 批的 sequel)
"States"是关于"history of a sequence up to the current step"的信息。它们与 "weights" 完全不同,后者是层实际上从所有序列中学到的东西。
"Unroll" 是一种将循环计算转换为单个图形而无需循环的方法。它仅适用于短序列,它以使用更多内存为代价获得更快的处理速度。