MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / __init__

Method __init__

rq/models/layers.py:9–33  ·  view source on GitHub ↗
(
        self, layers, dropout=0.0, activation="relu", bn=False
    )

Source from the content-addressed store, hash-verified

7class MLPLayers(nn.Module):
8
9 def __init__(
10 self, layers, dropout=0.0, activation="relu", bn=False
11 ):
12 super(MLPLayers, self).__init__()
13 self.layers = layers
14 self.dropout = dropout
15 self.activation = activation
16 self.use_bn = bn
17
18 mlp_modules = []
19 for idx, (input_size, output_size) in enumerate(
20 zip(self.layers[:-1], self.layers[1:])
21 ):
22 mlp_modules.append(nn.Dropout(p=self.dropout))
23 mlp_modules.append(nn.Linear(input_size, output_size))
24
25 if self.use_bn and idx != (len(self.layers)-2):
26 mlp_modules.append(nn.BatchNorm1d(num_features=output_size))
27
28 activation_func = activation_layer(self.activation, output_size)
29 if activation_func is not None and idx != (len(self.layers)-2):
30 mlp_modules.append(activation_func)
31
32 self.mlp_layers = nn.Sequential(*mlp_modules)
33 self.apply(self.init_weights)
34
35 def init_weights(self, module):
36 # We just initialize the module with normal distribution as the paper said

Callers

nothing calls this directly

Calls 1

activation_layerFunction · 0.85

Tested by

no test coverage detected