This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Neuron: | |
| def __init__(self, dims): | |
| self.w = [he_init(dims[idx], dims[idx+1]) for idx in range(len(dims-1))] | |
| self.b = [np.zeros(dims[idx+1], ) for idx in range(len(dims-1))] | |
| def forward(self, x): | |
| Z, A = [], [x] | |
| a = x | |
| for _ in range(len(self.w)): | |
| z = a @ self.w[idx] + self.b[idx] # [B, D_in] @ [D_in, D_out] + [1, D_out] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| import numpy as np | |
| class Linear: | |
| def __init__(self, in_features, out_features): | |
| self.w = np.random.randn(in_features, out_features) * (1 / math.sqrt(in_features)) | |
| self.b = np.random.randn(1, out_features) | |
| def forward(self, x): | |
| """ |