Simulai models transformer
Transformer #
Bases: NetworkTemplate
Source code in simulai/models/_pytorch_models/_transformer.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
__init__(num_heads_encoder=1, num_heads_decoder=1, embed_dim_encoder=None, embed_dim_decoder=None, output_dim=None, encoder_activation='relu', decoder_activation='relu', encoder_mlp_layer_config=None, decoder_mlp_layer_config=None, number_of_encoders=1, number_of_decoders=1, devices='cpu')
#
A classical encoder-decoder transformer:
Graphical example:
Example::
U -> ( Encoder_1 -> Encoder_2 -> ... -> Encoder_N ) -> u_e
(u_e, U) -> ( Decoder_1 -> Decoder_2 -> ... Decoder_N ) -> V
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_heads_encoder |
int
|
The number of heads for the self-attention layer of the encoder. (Default value = 1) |
1
|
num_heads_decoder |
int
|
The number of heads for the self-attention layer of the decoder. (Default value = 1) |
1
|
embed_dim_encoder |
int
|
The dimension of the embedding for the encoder. (Default value = Union[int, Tuple]) |
None
|
embed_dim_decoder |
int
|
The dimension of the embedding for the decoder. (Default value = Union[int, Tuple]) |
None
|
output_dim |
int
|
The dimension of the final output. (Default value = Union[int, Tuple]) |
None
|
encoder_activation |
Union[str, Module]
|
The activation to be used in all the encoder layers. (Default value = 'relu') |
'relu'
|
decoder_activation |
Union[str, Module]
|
The activation to be used in all the decoder layers. (Default value = 'relu') |
'relu'
|
encoder_mlp_layer_config |
dict
|
A configuration dictionary to instantiate the encoder MLP layer.weights (Default value = None) |
None
|
decoder_mlp_layer_config |
dict
|
A configuration dictionary to instantiate the encoder MLP layer.weights (Default value = None) |
None
|
number_of_encoders |
int
|
The number of encoders to be used. (Default value = 1) |
1
|
number_of_decoders |
int
|
The number of decoders to be used. (Default value = 1) |
1
|
Source code in simulai/models/_pytorch_models/_transformer.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
forward(input_data=None)
#
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
Union[Tensor, ndarray]
|
The input dataset. (Default value = None) |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The transformer output. |
Source code in simulai/models/_pytorch_models/_transformer.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
summary()
#
It prints a general view of the architecture.
Source code in simulai/models/_pytorch_models/_transformer.py
326 327 328 329 |
|