quantlab.model.predefined.rnn.ALSTMNet#
- class quantlab.model.predefined.rnn.ALSTMNet(num_features, num_labels, hidden_size=64, num_layers=2, dropout=0.0, rnn_type='GRU')[source]#
Bases:
ModuleQlib’s
ALSTMModel: a recurrent network with attention over its time steps.Each bar goes through
Tanh(Linear(F, H))and the recurrent network. A two-layer scorer (Linear(H, H/2), dropout,Tanh,Linear(H/2, 1), softmax over the N bars) weights the hidden states, andLinear(2H, L)maps the last hidden state concatenated with the weighted sum to the output. The parameter names are Qlib’s, so a Qlib state dict loads into a one-label net.- Parameters:
- num_featuresint
Features per bar,
F.- num_labelsint
Outputs per sample,
L; Qlib’s model has one.- hidden_sizeint, default 64
H.- num_layersint, default 2
Recurrent layers.
- dropoutfloat, default 0.0
Dropout between recurrent layers and in the scorer.
- rnn_type{“GRU”, “LSTM”}, default “GRU”
The recurrent network.
- Raises:
- ValueError
If
rnn_typeis neither"LSTM"nor"GRU".
Examples
>>> net = ALSTMNet(num_features=4, num_labels=2, hidden_size=8) >>> net(torch.randn(5, 3, 4)).shape torch.Size([5, 2])