Hi all,
I would like to initialize the weights of a 5 layer NN as follows:
Weights in first layer initialized from N(0, 0.1)
Weights in last layer initialized from N(0, 0.001)
Weights in other layers initialized from N(0, 1/sqrt(num_inputs))
(N stands for normal distribution)
I know that torch initializes the weights with a uniform distribution that takes into account the fanin/fanout of the model.
It looks like that the only option to perform a custom initialization is to assign the desired values to the weights.
For example in the following model
model = nn.Sequential()
model:add(nn.Linear(ninputs,nhiddens))
model:add(nn.Tanh())
we can change the weights like this
model.modules[1].weights = torch.rand(ninputs,nhiddens)
Although this approach works fine when we want to initialize from N(0,1), a slight modification is needed when we want to initialize from N(0,A).
In this case we can do:
model.modules[1].weights = torch.rand(ninputs,nhiddens):mul(A)
The results I obtained using this approach look correct, but I would like to know if there is a cleaner/smarter way to do the same thing or if I am missing something from the libraries.
Thanks in advance,
Alessandro