當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.raw_ops.LSTMBlockCell用法及代碼示例

計算 1 個時間步長的 LSTM 單元前向傳播。

用法

tf.raw_ops.LSTMBlockCell(
    x, cs_prev, h_prev, w, wci, wcf, wco, b, forget_bias=1, cell_clip=3,
    use_peephole=False, name=None
)

參數

  • x 一個Tensor。必須是以下類型之一:half , float32。 LSTM 單元的輸入,形狀(batch_size,num_inputs)。
  • cs_prev 一個Tensor。必須與 x 具有相同的類型。上一個時間步的細胞狀態值。
  • h_prev 一個Tensor。必須與 x 具有相同的類型。上一個時間步的上一個單元格的輸出。
  • w 一個Tensor。必須與 x 具有相同的類型。權重矩陣。
  • wci 一個Tensor。必須與 x 具有相同的類型。輸入門窺孔連接的權重矩陣。
  • wcf 一個Tensor。必須與 x 具有相同的類型。遺忘門窺視孔連接的權重矩陣。
  • wco 一個Tensor。必須與 x 具有相同的類型。輸出門窺視孔連接的權重矩陣。
  • b 一個Tensor。必須與 x 具有相同的類型。偏置向量。
  • forget_bias 可選的 float 。默認為 1 。遺忘門偏差。
  • cell_clip 可選的 float 。默認為 3 。將 'cs' 值剪切到的值。
  • use_peephole 可選的 bool 。默認為 False 。是否使用窺視孔砝碼。
  • name 操作的名稱(可選)。

返回

  • Tensor 對象的元組(i、cs、f、o、ci、co、h)。
  • i 一個Tensor。具有與 x 相同的類型。
  • cs 一個Tensor。具有與 x 相同的類型。
  • f 一個Tensor。具有與 x 相同的類型。
  • o 一個Tensor。具有與 x 相同的類型。
  • ci 一個Tensor。具有與 x 相同的類型。
  • co 一個Tensor。具有與 x 相同的類型。
  • h 一個Tensor。具有與 x 相同的類型。

此實現使用 1 個權重矩陣和 1 個偏置向量,並且有一個可選的窺視孔連接。

這個內核操作實現了以下數學方程:

xh = [x, h_prev]
[i, f, ci, o] = xh * w + b
f = f + forget_bias

if not use_peephole:
  wci = wcf = wco = 0

i = sigmoid(cs_prev * wci + i)
f = sigmoid(cs_prev * wcf + f)
ci = tanh(ci)

cs = ci .* i + cs_prev .* f
cs = clip(cs, cell_clip)

o = sigmoid(cs * wco + o)
co = tanh(cs)
h = co .* o

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.raw_ops.LSTMBlockCell。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。