| 312 | self.bias = bias |
| 313 | |
| 314 | def initialize(self, x): |
| 315 | self.in_features = x.shape[1] |
| 316 | w_shape = (self.in_features, self.out_features) |
| 317 | b_shape = (self.out_features,) |
| 318 | |
| 319 | self.W = Tensor(shape=w_shape, |
| 320 | dtype=x.dtype, |
| 321 | requires_grad=True, |
| 322 | stores_grad=True) |
| 323 | std = math.sqrt(2.0 / (self.in_features + self.out_features)) |
| 324 | self.W.gaussian(0.0, std) |
| 325 | |
| 326 | if self.bias: |
| 327 | self.b = Tensor(shape=b_shape, |
| 328 | dtype=x.dtype, |
| 329 | requires_grad=True, |
| 330 | stores_grad=True) |
| 331 | self.b.set_value(0.0) |
| 332 | else: |
| 333 | self.b = None |
| 334 | |
| 335 | def forward(self, x): |
| 336 | if self.b: |