def forward(self, x): u = self.wxh_ @ x + self.whh_ @ self.h_ + self.bh_ i = F.sigmoid(F.slice(u, 0, 0, self.out_size_)) f = F.sigmoid(F.slice(u, 0, self.out_size_, 2 * self.out_size_)) o = F.sigmoid(F.slice(u, 0, 2 * self.out_size_, 3 * self.out_size_)) j = F.tanh(F.slice(u, 0, 3 * self.out_size_, 4 * self.out_size_)) self.c_ = i * j + f * self.c_ self.h_ = o * F.tanh(self.c_) return self.h_
def forward(self, x): u = self.wxh @ x + self.whh @ self.h + self.bh i = F.sigmoid(F.slice(u, 0, 0, self.out_size)) f = F.sigmoid(F.slice(u, 0, self.out_size, 2 * self.out_size)) o = F.sigmoid(F.slice(u, 0, 2 * self.out_size, 3 * self.out_size)) j = F.tanh(F.slice(u, 0, 3 * self.out_size, 4 * self.out_size)) self.c = i * j + f * self.c self.h = o * F.tanh(self.c) return self.h
def forward(self, x): """One step forwarding.""" out_size = self.pwhh.shape()[1] u = self.wxh @ x + self.whh @ self.h + self.bh i = F.sigmoid(F.slice(u, 0, 0, out_size)) f = F.sigmoid(F.slice(u, 0, out_size, 2 * out_size)) o = F.sigmoid(F.slice(u, 0, 2 * out_size, 3 * out_size)) j = F.tanh(F.slice(u, 0, 3 * out_size, 4 * out_size)) self.c = i * j + f * self.c self.h = o * F.tanh(self.c) return self.h
def forward(self, xs): x = F.concat(xs, 1) u = self.w_ @ x j = F.slice(u, 0, 0, self.out_size_) f = F.sigmoid( F.slice(u, 0, self.out_size_, 2 * self.out_size_) + F.broadcast(self.bf_, 1, len(xs))) r = F.sigmoid( F.slice(u, 0, 2 * self.out_size_, 3 * self.out_size_) + F.broadcast(self.bf_, 1, len(xs))) c = F.zeros([self.out_size_]) hs = [] for i in range(len(xs)): ji = F.slice(j, 1, i, i + 1) fi = F.slice(f, 1, i, i + 1) ri = F.slice(r, 1, i, i + 1) c = fi * c + (1 - fi) * ji hs.append(ri * F.tanh(c) + (1 - ri) * xs[i]) return hs
def forward(self, inputs): batch_size = len(inputs[0]) wlookup = F.parameter(self.pwlookup) wxs = F.parameter(self.pwxs) wsy = F.parameter(self.pwsy) s = F.zeros(Shape([NUM_HIDDEN_UNITS], batch_size)) outputs = [] for i in range(len(inputs) - 1): w = F.pick(wlookup, inputs[i], 1) x = w + s s = F.sigmoid(wxs @ x) outputs.append(wsy @ s) return outputs