Example #1
0
 def _oper_cpu(cls, lhs, rhs):
     N = len(lhs)
     z = softmax(lhs)
     loss = -np.sum(rhs * np.log(z + 1e-8)) / N
     ret = cls._create_node(loss)
     ret.attrs._z = z
     ret.attrs._lhs = lhs
     ret.attrs._rhs = rhs
     return ret
Example #2
0
 def _oper_gpu(cls, lhs, rhs):
     N = lhs.shape[0]
     z = softmax(lhs)
     tmp1 = get_gpu(lhs).empty_like_me()
     cu.cucross_entropy(get_gpu(z), get_gpu(rhs), get_gpu(tmp1))
     loss = -cu.cusum(get_gpu(tmp1)) / N
     ret = cls._create_node(loss)
     ret.attrs._z = z
     ret.attrs._lhs = lhs
     ret.attrs._rhs = rhs
     return ret