def forward(self, x): caches = [] h_prev = np.zeros((self.hidden_size, 1)) h = h_prev for t in range(x.shape[0]): x_t = x[t].reshape(-1, 1) combined = np.vstack((h_prev, x_t)) z = self.sigmoid(np.dot(self.wz, combined) + self.bz) r = self.sigmoid(np.dot(self.wr, combined) + self.br) combined_r = np.vstack((r * h_prev, x_t)) h_ = np.tanh(np.dot(self.wh, combined_r) + self.bh) h = (1 - z) * h_prev + z * h_ cache = (h_prev, z, r, h_, x_t, combined, combined_r, h) caches.append(cache) h_prev = h y = np.dot(self.why, h) + self.by return y, caches