Which slice is the forget gate?
shape▲△△A PyTorch nn.LSTM has hidden width . You want the forget bias to start
at one. Which entries of bias_ih_l0 hold the forget gate? What effective
bias results if you set that slice to one in both bias_ih_l0 and
bias_hh_l0, and what horizons do the intended and the actual
settings give? What range does PyTorch’s default leave each bias in?
Hint
PyTorch stacks the gates as input, forget, candidate, output. The two bias vectors are added inside every gate.
Solution
Each bias vector has entries in four blocks of five. The forget block is the second: entries to , counting from zero. Entries to are the input gate, so setting them would raise the input gate instead.
The gate computes . Setting both slices to one gives an effective bias of two: instead of . By (I.10.5) the horizons are and steps. Set one slice to one and the other to zero, or split the target between them.
By default PyTorch draws every bias from , that is, within . The effective forget bias is the sum of two such draws, so it lies within , centred on zero: starts near one half. Keras, by contrast, adds one to the forget bias by default.