Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Keras LSTM如何在每个时间步使用隐藏状态将输入更改为LSTM的下一个时间步?_Python_Tensorflow_Keras_Lstm_Recurrent Neural Network - Fatal编程技术网

Python Keras LSTM如何在每个时间步使用隐藏状态将输入更改为LSTM的下一个时间步?

Python Keras LSTM如何在每个时间步使用隐藏状态将输入更改为LSTM的下一个时间步?,python,tensorflow,keras,lstm,recurrent-neural-network,Python,Tensorflow,Keras,Lstm,Recurrent Neural Network,我正在使用keras构建LSTM模型。在将隐藏状态反馈回内存单元之前,我希望在每个时间步操作隐藏状态,就像正常的LSTM一样。我不确定我的实现是否正确。我发现在keras很难做到这一点 我所做的是在时间窗口的数量上循环,并独立地为特定的时间窗口提供每个输入,这样我只会在该特定输入处获得隐藏状态,并且在操纵后,将能够将其反馈给LSTM,以便下次时间窗口输入: # initialize hidden state (encoder_state_h, encoder_state_c) encoder =

我正在使用
keras
构建
LSTM
模型。在将隐藏状态反馈回内存单元之前,我希望在每个时间步操作隐藏状态,就像正常的LSTM一样。我不确定我的实现是否正确。我发现在keras很难做到这一点

我所做的是在时间窗口的数量上循环,并独立地为特定的时间窗口提供每个输入,这样我只会在该特定输入处获得隐藏状态,并且在操纵后,将能够将其反馈给LSTM,以便下次时间窗口输入:

# initialize hidden state (encoder_state_h, encoder_state_c)
encoder = LSTM(units=units, return_state=True)

for i in range(config.time_window):
    # get only the input at this time step
    current_input = inputs[:, i, :]
    # do some manipulations to the current input which involves the hidden states

    output, encoder_state_h, encoder_state_c = encoder(current_input)
    
    # Saving each hidden state
    encoder_hidden_states.append(encoder_state_h)

# Stacking them as if normal lstm with return_sequence=True
encoder_hidden_states = tf.stack(encoder_hidden_states, axis=-1)
对每个输入所做的操作包括一个注意机制,该机制对于当前问题来说并不重要

问题是我不确定实施是否正确。我没有在上一个隐藏状态下输入到下一个时间步骤(仅输入)。Keras看起来不支持将其作为输入

是Keras自动传播隐藏状态,还是每次调用
编码器时都会重置隐藏状态?

一、 本质上,我们希望在每个时间步对lstm有更多的控制,而这看起来不像是由Keras支持的

欢迎任何解决办法