MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / __init__

Method __init__

imperative/python/megengine/module/rnn.py:19–48  ·  view source on GitHub ↗
(
        self, input_size: int, hidden_size: int, bias: bool, num_chunks: int,
    )

Source from the content-addressed store, hash-verified

17
18class 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)

Callers

nothing calls this directly

Calls 5

reset_parametersMethod · 0.95
ParameterClass · 0.85
zerosFunction · 0.50
__init__Method · 0.45
zerosMethod · 0.45

Tested by

no test coverage detected