勵志

勵志人生知識庫

lstm公式

LSTM(Long Short-Term Memory)的公式可以概括為以下幾個部分:

輸入門(Input Gate):

\(i_t = \sigma(W_{ix}x_t + W_{ih}h_{t-1} + b_i)\)

遺忘門(Forget Gate):

\(f_t = \sigma(W_{fx}x_t + W_{fh}h_{t-1} + b_f)\)

細胞狀態(Cell State)更新:

\(\tilde{C}_t = \text{tanh}(W_{cx}x_t + W_{ch}h_{t-1} + b_c)\)

\(C_t = f_t \odot C_{t-1} + i_t \odot \tilde{C}_t\)

輸出門(Output Gate):

\(o_t = \sigma(W_{ox}x_t + W_{oh}h_{t-1} + b_o)\)

隱狀態(Hidden State):

\(h_t = o_t \odot \text{tanh}(C_t)\)

這些公式描述了LSTM單元的基本運算,包括輸入門、遺忘門、細胞狀態更新、輸出門和隱狀態的計算。其中,\(W\) 表示權重,\(b\) 表示偏置,\(\sigma\) 表示 sigmoid 激活函式,\(\odot\) 表示逐元素乘法,而 \(x\) 和 \(h\) 分別代表輸入和隱藏狀態。