Gated recurrent unit (GRU) with nunits cells.
(self, inputs, state, att_score=None)
| 170 | def __call__(self, inputs, state, att_score): |
| 171 | return self.call(inputs, state, att_score) |
| 172 | def call(self, inputs, state, att_score=None): |
| 173 | """Gated recurrent unit (GRU) with nunits cells.""" |
| 174 | if self._gate_linear is None: |
| 175 | bias_ones = self._bias_initializer |
| 176 | if self._bias_initializer is None: |
| 177 | bias_ones = init_ops.constant_initializer(1.0, dtype=inputs.dtype) |
| 178 | with vs.variable_scope("gates"): # Reset gate and update gate. |
| 179 | self._gate_linear = _Linear( |
| 180 | [inputs, state], |
| 181 | 2 * self._num_units, |
| 182 | True, |
| 183 | bias_initializer=bias_ones, |
| 184 | kernel_initializer=self._kernel_initializer) |
| 185 | |
| 186 | value = math_ops.sigmoid(self._gate_linear([inputs, state])) |
| 187 | r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1) |
| 188 | |
| 189 | r_state = r * state |
| 190 | if self._candidate_linear is None: |
| 191 | with vs.variable_scope("candidate"): |
| 192 | self._candidate_linear = _Linear( |
| 193 | [inputs, r_state], |
| 194 | self._num_units, |
| 195 | True, |
| 196 | bias_initializer=self._bias_initializer, |
| 197 | kernel_initializer=self._kernel_initializer) |
| 198 | c = self._activation(self._candidate_linear([inputs, r_state])) |
| 199 | u = (1.0 - att_score) * u |
| 200 | new_h = u * state + (1 - u) * c |
| 201 | return new_h, new_h |
| 202 | |
| 203 | def prelu(_x, scope=''): |
| 204 | """parametric ReLU activation""" |