Tensorflowの次のコードGRUCell
には、以前の隠れ状態がシーケンスの現在の入力とともに提供されるときに、更新された隠れ状態を取得するための一般的な操作が示されています。TensorflowのGRUセルの説明?
def __call__(self, inputs, state, scope=None):
"""Gated recurrent unit (GRU) with nunits cells."""
with vs.variable_scope(scope or type(self).__name__): # "GRUCell"
with vs.variable_scope("Gates"): # Reset gate and update gate.
# We start with bias of 1.0 to not reset and not update.
r, u = array_ops.split(1, 2, _linear([inputs, state],
2 * self._num_units, True, 1.0))
r, u = sigmoid(r), sigmoid(u)
with vs.variable_scope("Candidate"):
c = self._activation(_linear([inputs, r * state],
self._num_units, True))
new_h = u * state + (1 - u) * c
return new_h, new_h
しかし、私はここにweights
とbiases
が表示されません。例: 私の理解は、r
とu
を得ることは、更新された隠れ状態を得るために、現在の入力および/または隠れた状態で重みとバイアスを乗算する必要があるということでした。
次のように私はGRUユニットを書かれている:ここで
def gru_unit(previous_hidden_state, x):
r = tf.sigmoid(tf.matmul(x, Wr) + br)
z = tf.sigmoid(tf.matmul(x, Wz) + bz)
h_ = tf.tanh(tf.matmul(x, Wx) + tf.matmul(previous_hidden_state, Wh) * r)
current_hidden_state = tf.mul((1 - z), h_) + tf.mul(previous_hidden_state, z)
return current_hidden_state
私は明示的などの重みWx, Wr, Wz, Wh
と偏見br, bh, bz
、の使用は隠された状態に更新されますすることにします。これらの重みと偏りは、学習後に学習/チューニングされるものです。
上記と同じ結果を得るには、TensorflowのビルトインGRUCell
をどうすれば使用できますか?
彼らは一度にすべてを行うには、 'r'と' z'ゲートを連結、計算を節約できます。 –