## 3 Methodology
This design enables the model to process the ECG signal as a sequence, capturing both local features within each segment and global dependencies across the entire signal. To preserve temporal structure and order information--which are essential in physiological signals--learnable positional encodings are added to the input representation. While tokenization introduces discrete segment boundaries, the model's use of cross-token self-attention and positional embeddings mitigates potential degradation due to signal shifts, ensuring robustness in the presence of phase variations or waveform misalignment. Figure 3: Hierarchical Architecture of ECGDnet: End-to-End Transformer Pipeline with Cross-Layer Self-Attention and Dynamic Residual Pathways for Advanced ECG Signal Processing. Figure 2: Training and inference schemes of the proposed approach for ECG denoising. Within the attention mechanism, the query (Q), key (K), and value (V) matrices are generated from the same input tensor but via separate learned projections. This is implemented through a single linear transformation layer that maps the input into a concatenated tensor, which is then split into Q, K, and V. These matrices are not identical copies but distinct, parameterized projections that allow the model to learn asymmetric interactions among different time segments. This formulation supports the model's ability to dynamically attend to relevant temporal regions, thereby enhancing denoising performance across a range of physiological noise conditions. While Table 2 and Figure 3 represent the same overall architecture, they serve complementary purposes and operate at different levels of abstraction. Figure 3 provides a high-level schematic of ECGDnet's transformer encoder pipeline, highlighting the hierarchical organization of self-attention and feedforward layers within residual blocks. It illustrates the general structure of a single encoder block, repeated four times in our model, along with the flow of information and residual connections. Table 2, on the other hand, provides a detailed, layer-by-layer breakdown of each of the four Transformer blocks shown in Figure 3. Each Transformer block in Table 2 includes a normalization layer, a multi-head self-attention module (implemented via linear projections for Q, K, and V), a projection layer for the attention output, a second normalization layer, and a feedforward network composed of two fully connected layers. Although the layer configuration remains consistent across all four blocks, _parameter weights are not shared_;  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Network Part** & **Layer** & **Output Shape** & **Kernel Size** & **Parameters** \\ \hline
**Input** & Position Embedding & [1; 20; 18] & - & 360 \\ \hline \multirow{5}{*}{Transformer Block 1} & Layer Norm 1 & [20; 18] & \(1\times 1\) & 36 \\  & Self-Attention QKV & [20; 3; 18] & \(1\times 1\) (3 linear proj.) & 972 \\  & Self-Attention Proj & [20; 18] & \(1\times 1\) & 342 \\  & Layer Norm 2 & [20; 18] & \(1\times 1\) & 36 \\  & MLP Linear 1 & [20; 576] & \(1\times 1\) & 10,944 \\  & MLP Linear 2 & [20; 18] & \(1\times 1\) & 10,386 \\ \hline \multirow{5}{*}{Transformer Block 2} & Layer Norm 1 & [20; 18] & \(1\times 1\) & 36 \\  & Self-Attention QKV & [20; 3; 18] & \(1\times 1\) (3 linear proj.) & 972 \\  & Self-Attention Proj & [20; 18] & \(1\times 1\) & 342 \\  & Layer Norm 2 & [20; 18] & \(1\times 1\) & 36 \\  & MLP Linear 1 & [20; 576] & \(1\times 1\) & 10,944 \\  & MLP Linear 2 & [20; 18] & \(1\times 1\) & 10,386 \\ \hline \multirow{5}{*}{Transformer Block 3} & Layer Norm 1 & [20; 18] & \(1\times 1\) & 36 \\  & Self-Attention QKV & [20; 3; 18] & \(1\times 1\) (3 linear proj.)