quantlab.model.predefined.master.AttentionBlock#
- class quantlab.model.predefined.master.AttentionBlock(d_model, nhead, dropout, across_symbols)[source]#
Bases:
ModuleMASTER’s pre-LayerNorm multi-head attention block with a feed-forward layer.
xis[S_t, N, D]. Withacross_symbols=False(MASTER’sTAttention) each symbol attends over its own N steps and the scores are not scaled; withacross_symbols=True(SAttention) the symbols attend to each other at every step and the scores are divided bysqrt(D / nhead). Both returnnorm2(LN(x) + MHA(LN(x)))plus the feed-forward layer of that sum.Examples
>>> block = AttentionBlock(d_model=8, nhead=2, dropout=0.0, across_symbols=True) >>> block(torch.randn(5, 3, 8)).shape torch.Size([5, 3, 8])