(
self, input_size: int, hidden_size: int, bias: bool, num_chunks: int,
)
| 17 | |
| 18 | class RNNCellBase(Module): |
| 19 | def __init__( |
| 20 | self, input_size: int, hidden_size: int, bias: bool, num_chunks: int, |
| 21 | ) -> None: |
| 22 | # num_chunks indicates the number of gates |
| 23 | super(RNNCellBase, self).__init__() |
| 24 | |
| 25 | self.input_size = input_size |
| 26 | self.hidden_size = hidden_size |
| 27 | self.bias = bias |
| 28 | |
| 29 | # initialize weights |
| 30 | self.gate_hidden_size = num_chunks * hidden_size |
| 31 | self.weight_ih = Parameter( |
| 32 | np.zeros((self.gate_hidden_size, input_size), dtype=np.float32) |
| 33 | ) |
| 34 | self.weight_hh = Parameter( |
| 35 | np.zeros((self.gate_hidden_size, hidden_size), dtype=np.float32) |
| 36 | ) |
| 37 | if bias: |
| 38 | self.bias_ih = Parameter( |
| 39 | np.zeros((self.gate_hidden_size), dtype=np.float32) |
| 40 | ) |
| 41 | self.bias_hh = Parameter( |
| 42 | np.zeros((self.gate_hidden_size), dtype=np.float32) |
| 43 | ) |
| 44 | else: |
| 45 | self.bias_ih = zeros(shape=(self.gate_hidden_size)) |
| 46 | self.bias_hh = zeros(shape=(self.gate_hidden_size)) |
| 47 | self.reset_parameters() |
| 48 | # if bias is False self.bias will remain zero |
| 49 | |
| 50 | def reset_parameters(self) -> None: |
| 51 | stdv = 1.0 / math.sqrt(self.hidden_size) |
nothing calls this directly
no test coverage detected