Vision Transformer #
Patch embedding is an arbitrary-dimensional convolution. The spatial output is flattened into a token axis before the Transformer block, so the construction applies equally to one-dimensional signals, images, volumes, and higher-dimensional grids.
Configuration for a Transformer encoder over patches from a d-dimensional spatial domain.
- inputChannels : ℕ
Number of channels in each input sample.
Extent of each spatial axis.
- patchEmbedding : Convolution.Config d
Convolution that extracts and embeds patches.
- headCount : ℕ
Number of attention heads. Must be positive.
- headWidth : ℕ
Width of each attention head. Must be positive.
- feedForwardWidth : ℕ
Width of the feed-forward sublayer.
- layerCount : ℕ
Number of Transformer encoder blocks.
Dropout probability for attention and feed-forward outputs.
Drop attention probabilities before value aggregation; independent of residual dropout.
Drop activated FFN hidden units before their output projection.
- attentionInputBias : Bool
Enable trainable query, key, and value biases while preserving the legacy default layout.
- pooling : Pooling
Classifier readout;
.clsalso prepends a learned class token.
Instances For
Configuration for a vision Transformer classifier.
- layerCount : ℕ
- classCount : ℕ
Number of classifier outputs per sample.
Instances For
Attach a classifier output width to reusable encoder settings.
Instances For
Encoder settings embedded in a classifier configuration.
Instances For
Validate patch extraction and the complete Transformer template before allocating parameters.
Instances For
Grid produced by patch embedding.
Instances For
Number of patch tokens.
Instances For
Number of slots inserted before the patch sequence.
Instances For
Number of tokens passed through the Transformer encoder.
Instances For
Number of scalar features in the complete encoded token sequence.
Instances For
Input shape for any caller-supplied batch shape.
Instances For
Patch tensor produced by the embedding convolution.
Instances For
Patch tokens after moving the embedding width to the final axis.
Instances For
Tokens consumed and produced by the Transformer stack.
Instances For
Implementation layer that turns a patch grid into a token sequence.
Instances For
Prepend one shared, trainable class token to every independently mapped sequence.
Instances For
Implementation layer that moves the embedding width before the token axis.
Instances For
Implementation layer for mean-pool classification.
Instances For
Implementation layer for class-token classification.
Instances For
Build the patch and Transformer portion of a vision transformer.
Mean readout leaves the patch sequence unchanged. Class-token readout prepends one learned token before the Transformer. Classification, reconstruction, and other tasks can attach their own heads without rebuilding the patch pipeline.
Instances For
Build a vision Transformer encoder followed by a linear classifier.