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' 문을 연결, 계산을 절약 할 수 있습니다. –