如何在keras中打印LSTM的bïi、Wïi和Uïi属性

2024-06-02 07:26:21 发布

您现在位置:Python中文网/ 问答频道 /正文

如何重写keras/layers/recurrent.py,使LSTM的bđi属性可以使用和打印

def step(self, x, states):
    assert len(states) == 2
    h_tm1 = states[0]
    c_tm1 = states[1]

    x_i = K.dot(x, self.W_i) + self.b_i
    x_f = K.dot(x, self.W_f) + self.b_f
    x_c = K.dot(x, self.W_c) + self.b_c
    x_o = K.dot(x, self.W_o) + self.b_o

    i = self.inner_activation(x_i + K.dot(h_tm1, self.U_i))
    f = self.inner_activation(x_f + K.dot(h_tm1, self.U_f))
    c = f * c_tm1 + i * self.activation(x_c + K.dot(h_tm1, self.U_c))
    o = self.inner_activation(x_o + K.dot(h_tm1, self.U_o))
    h = o * self.activation(c)
    return h, [h, c]

Tags: pyself属性layersdefstepassertactivation