transformerlightpredictor
TransformerLightPredictor
¶
Bases: LightningModule
Source code in spotpython/light/transformer/transformerlightpredictor.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__(l1, d_mult, dim_feedforward, nhead, num_layers, epochs, batch_size, initialization, act_fn, optimizer, dropout_prob, lr_mult, patience, _L_in, _L_out, model_dim, num_heads, lr, warmup, max_iters, input_dropout, dropout, *args, **kwargs)
¶
Initializes the TransformerLightRegression object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1 |
int
|
The number of neurons in the first hidden layer. |
required |
epochs |
int
|
The number of epochs to train the model for. |
required |
batch_size |
int
|
The batch size to use during training. |
required |
initialization |
str
|
The initialization method to use for the weights. |
required |
act_fn |
Module
|
The activation function to use in the hidden layers. |
required |
optimizer |
str
|
The optimizer to use during training. |
required |
dropout_prob |
float
|
The probability of dropping out a neuron during training. |
required |
lr_mult |
float
|
The learning rate multiplier for the optimizer. |
required |
patience |
int
|
The number of epochs to wait before early stopping. |
required |
_L_in |
int
|
The number of input features. Not a hyperparameter, but needed to create the network. |
required |
_L_out |
int
|
The number of output classes. Not a hyperparameter, but needed to create the network. |
required |
model_dim |
int
|
Hidden dimensionality to use inside the Transformer |
required |
num_heads |
int
|
Number of heads to use in the Multi-Head Attention blocks |
required |
num_layers |
int
|
Number of encoder blocks to use. |
required |
lr |
float
|
Learning rate in the optimizer |
required |
warmup |
int
|
Number of warmup steps. Usually between 50 and 500 |
required |
max_iters |
int
|
Number of maximum iterations the model is trained for. This is needed for the CosineWarmup scheduler |
required |
input_dropout |
float
|
Dropout to apply on the input features |
required |
dropout |
float
|
Dropout to apply inside the Transformer |
required |
Source code in spotpython/light/transformer/transformerlightpredictor.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
forward(x, mask=None, add_positional_encoding=True)
¶
Inputs
x - Input features of shape [Batch, SeqLen, input_dim] mask - Mask to apply on the attention outputs (optional) add_positional_encoding - If True, we add the positional encoding to the input. Might not be desired for some tasks.
Source code in spotpython/light/transformer/transformerlightpredictor.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
get_attention_maps(x, mask=None, add_positional_encoding=True)
¶
Function for extracting the attention matrices of the whole Transformer for a single batch. Input arguments same as the forward pass.
Source code in spotpython/light/transformer/transformerlightpredictor.py
132 133 134 135 136 137 138 139 140 141 142 |
|