Inferensys

Glossary

Transformer

A neural network architecture that relies entirely on a self-attention mechanism to process sequential data in parallel, capturing global dependencies without recurrent or convolutional layers.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
NEURAL NETWORK ARCHITECTURE

What is a Transformer?

A Transformer is a deep learning model that processes sequential data entirely through a self-attention mechanism, enabling parallel computation and capturing long-range dependencies without recurrence or convolution.

A Transformer is a neural network architecture that relies exclusively on a self-attention mechanism to process sequential data, dispensing with recurrent and convolutional layers entirely. Introduced in the 2017 paper "Attention Is All You Need," it computes representations of input sequences by weighing the relevance of every element to every other element simultaneously, allowing the model to capture global dependencies regardless of distance within the sequence.

The architecture consists of an encoder-decoder structure built from stacked layers of multi-head self-attention and position-wise feed-forward networks, augmented with residual connections and layer normalization. Because the model processes all positions in parallel, it requires positional encodings to inject information about token order. This design enables significantly faster training than recurrent models and has become the foundation for state-of-the-art systems in natural language processing, time-series forecasting, and beyond.

ARCHITECTURAL COMPONENTS

Key Features of the Transformer Architecture

The Transformer eschews recurrence and convolution, relying entirely on a self-attention mechanism to model global dependencies in sequential data. The following cards break down its core innovations.

01

Scaled Dot-Product Self-Attention

The core computational unit that allows the model to weigh the importance of every element in a sequence when encoding a specific element. It computes attention scores by taking the dot product of a Query vector with all Key vectors, scaling the result by the square root of the dimension (√d_k) to prevent vanishing gradients in the softmax. This operation is executed in parallel across the entire sequence, enabling the capture of long-range dependencies without the sequential bottleneck of recurrent neural networks. The final output is a weighted sum of the Value vectors.

O(n²·d)
Compute Complexity
√d_k
Scaling Factor
02

Multi-Head Attention Mechanism

Instead of performing a single attention function, the model linearly projects the Queries, Keys, and Values h times with different, learned linear projections. This allows the model to jointly attend to information from different representation subspaces at different positions. For example, one head might focus on syntactic dependencies while another tracks long-range semantic relationships. The outputs of all heads are concatenated and projected once more, yielding a richer representation than a single attention head could provide.

8
Heads in Base Model
64
Dimension per Head (d_v)
03

Positional Encoding

Since the Transformer contains no recurrence or convolution, it has no inherent sense of token order. Positional encodings are injected at the bottom of the encoder and decoder stacks to inject information about the relative or absolute position of tokens. The original architecture uses sinusoidal functions of varying frequencies: PE(pos, 2i) = sin(pos / 10000^(2i/d_model)) and PE(pos, 2i+1) = cos(pos / 10000^(2i/d_model)). This allows the model to easily learn to attend by relative position and extrapolate to sequence lengths unseen during training.

d_model
Encoding Dimension
Sinusoidal
Original Method
04

Point-Wise Feed-Forward Networks

Each encoder and decoder layer contains a fully connected feed-forward network applied identically to each position. This consists of two linear transformations with a ReLU activation in between: FFN(x) = max(0, xW₁ + b₁)W₂ + b₂. While the attention layers mix information across positions, the feed-forward layers process the representation at each position independently, adding a non-linear transformation that increases the model's capacity. The inner dimension is typically four times the model dimension (d_ff = 2048).

4x
Inner Dimension Multiplier
ReLU
Activation Function
05

Residual Connections & Layer Normalization

Each sub-layer (self-attention and feed-forward) is wrapped with a residual connection, where the input is added to the sub-layer's output: LayerNorm(x + Sublayer(x)). This mitigates the vanishing gradient problem in deep architectures, allowing the model to be stacked 6 or more layers deep. Layer normalization is applied after the addition, stabilizing the hidden state dynamics by normalizing across the feature dimension for each individual token, rather than across the batch dimension as in batch normalization.

6
Encoder/Decoder Layers
Post-LN
Original Norm Position
06

Masked Self-Attention in the Decoder

To preserve the auto-regressive property during generation, the decoder's self-attention sub-layer is modified with a causal mask. This mask sets all attention scores for illegal future connections to negative infinity before the softmax, ensuring that the prediction for position i can depend only on known outputs at positions less than i. This is implemented by masking out (setting to -∞) the upper triangular portion of the attention score matrix, preventing leftward information flow and enforcing the sequential generation constraint.

Upper Triangular
Mask Shape
-∞
Mask Value
TRANSFORMER ARCHITECTURE

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the Transformer architecture and its application to high-frequency financial time-series forecasting.

A Transformer is a neural network architecture that processes sequential data entirely through a self-attention mechanism, dispensing with recurrent or convolutional layers. It works by computing a weighted representation of every element in an input sequence simultaneously, allowing the model to capture long-range dependencies in parallel. The core operation involves projecting the input into three matrices—queries (Q), keys (K), and values (V)—and calculating attention scores as softmax(QK^T / √d_k)V. This scaled dot-product attention determines how much each element should attend to every other element. Multi-head attention runs this process in parallel across multiple learned projection subspaces, enabling the model to capture different types of relationships. Positional encodings are added to the input embeddings to inject sequence order information, since the architecture itself is permutation-invariant. The encoder-decoder structure, originally proposed for machine translation, has evolved into encoder-only (BERT), decoder-only (GPT), and full encoder-decoder variants, each suited to different tasks.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.