MCPcopy Create free account
hub / github.com/apache/singa / step_forward

Method step_forward

python/singa/layer.py:1330–1368  ·  view source on GitHub ↗
(self, x, h, c)

Source from the content-addressed store, hash-verified

1328 return out, h, c
1329
1330 def step_forward(self, x, h, c):
1331 # input
1332 y1 = autograd.matmul(x, self.Wx_i)
1333 y1 = autograd.add_bias(y1, self.Bx_i, axis=0)
1334 y2 = autograd.matmul(h, self.Wh_i)
1335 y2 = autograd.add_bias(y2, self.Bh_i, axis=0)
1336 i = autograd.add(y1, y2)
1337 i = autograd.sigmoid(i)
1338
1339 # forget
1340 y1 = autograd.matmul(x, self.Wx_f)
1341 y1 = autograd.add_bias(y1, self.Bx_f, axis=0)
1342 y2 = autograd.matmul(h, self.Wh_f)
1343 y2 = autograd.add_bias(y2, self.Bh_f, axis=0)
1344 f = autograd.add(y1, y2)
1345 f = autograd.sigmoid(f)
1346
1347 # output
1348 y1 = autograd.matmul(x, self.Wx_o)
1349 y1 = autograd.add_bias(y1, self.Bx_o, axis=0)
1350 y2 = autograd.matmul(h, self.Wh_o)
1351 y2 = autograd.add_bias(y2, self.Bh_o, axis=0)
1352 o = autograd.add(y1, y2)
1353 o = autograd.sigmoid(o)
1354
1355 y1 = autograd.matmul(x, self.Wx_g)
1356 y1 = autograd.add_bias(y1, self.Bx_g, axis=0)
1357 y2 = autograd.matmul(h, self.Wh_g)
1358 y2 = autograd.add_bias(y2, self.Bh_g, axis=0)
1359 g = autograd.add(y1, y2)
1360 g = autograd.tanh(g)
1361
1362 cout1 = autograd.mul(f, c)
1363 cout2 = autograd.mul(i, g)
1364 cout = autograd.add(cout1, cout2)
1365
1366 hout = autograd.tanh(cout)
1367 hout = autograd.mul(o, hout)
1368 return hout, cout
1369
1370 def get_params(self):
1371 ret = {}

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected