Args: x (CTensor): 1d or 2d tensor, the prediction data(output) of current network. t (CTensor): 1d or 2d tensor, the target data for training. Returns: loss (CTensor): scalar.
(self, x)
| 1220 | """ |
| 1221 | |
| 1222 | def forward(self, x): |
| 1223 | """ |
| 1224 | Args: |
| 1225 | x (CTensor): 1d or 2d tensor, the prediction data(output) |
| 1226 | of current network. |
| 1227 | t (CTensor): 1d or 2d tensor, the target data for training. |
| 1228 | Returns: |
| 1229 | loss (CTensor): scalar. |
| 1230 | """ |
| 1231 | loss = singa.SumAll(singa.__mul__(self.t, singa.Log(x))) |
| 1232 | loss /= -x.shape()[0] |
| 1233 | self.x = x |
| 1234 | return loss |
| 1235 | |
| 1236 | def backward(self, dy=1.0): |
| 1237 | """ |