Papers
Topics
Authors
Recent
Search
2000 character limit reached

ReDRE: Relative Distance Rotating Encoding

Updated 3 July 2026
  • ReDRE is a geometric positional encoding that rotates query and key vectors based on pairwise timestamp differences.
  • It integrates into Transformer self-attention by replacing absolute position rotations with relative, event-driven rotations to capture irregular dependencies.
  • Empirical results show ReDRE improves AUC in fraud detection tasks, demonstrating enhanced modeling of time-series data.

Relative Distance Rotating Encoding (ReDRE) is an explicit geometric positional encoding mechanism designed to replace absolute-position-based rotation in Transformer self-attention with rotations derived from relative “event distance,” particularly temporal deltas. It extends the rotary position encoding (RoPE) formalism by introducing pairwise, timestamp-difference-dependent rotations of queries and keys, enabling Transformer models to capture fine-grained, irregularly-spaced dependencies in event sequences such as financial transactions or sensor logs. The method is directly integrated into the RoFormer model and empirically demonstrates improved discriminative capacity for time-series and fraud detection tasks (Reyes et al., 12 Jul 2025).

1. Formal Specification of Relative Distance Rotating Encoding

ReDRE operates on an input sequence of tokens, each with both a feature vector xiRdx_i \in \mathbb{R}^d and a timestamp tiRt_i \in \mathbb{R}. Standard Transformer projections yield query, key, and value vectors: qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v respectively. ReDRE modifies self-attention by rotating the query qiq_i and key kjk_j vectors for each token pair (i,j)(i,j) by an angle dependent on their relative timestamp Δtij=titj\Delta t_{ij} = t_i - t_j.

For each frequency index l=0,...,d/21l = 0, ..., d/2 - 1,

  • Base angular frequencies ωl=1/100002l/d\omega_l = 1/10000^{2l/d};
  • Rotation angle θij(l)=Δtijωl\theta_{ij}^{(l)} = \Delta t_{ij} \cdot \omega_l.

The rotation matrix per block:

tiRt_i \in \mathbb{R}0

Across all frequency bands, the full tiRt_i \in \mathbb{R}1 matrix tiRt_i \in \mathbb{R}2 is composed of tiRt_i \in \mathbb{R}3 such tiRt_i \in \mathbb{R}4 rotations on the diagonal. Rotations are applied:

  • tiRt_i \in \mathbb{R}5
  • tiRt_i \in \mathbb{R}6

The attention score is then:

tiRt_i \in \mathbb{R}7

The remainder of the attention module (softmax, value aggregation) remains unchanged.

2. Pseudocode and Implementation

A concise implementation for a single attention head:

kjk_j5 Efficient implementations vectorize the inner loops over tiRt_i \in \mathbb{R}8 and fuse rotation into the projection step.

3. Integration with RoFormer and Model Pipeline

In the RoFormer architecture, ReDRE specifically replaces the absolute Rotary Position Encoding (RoPE) applied to queries and keys. The only algorithmic difference is that the angle for each rotation is a function of the pairwise relative delta tiRt_i \in \mathbb{R}9, not the absolute sequence position. The attention kernel, therefore, encodes explicit dependence on temporal (or event-structural) gaps between all token pairs.

Step Standard Transformer RoFormer (RoPE) RoFormer + ReDRE
Q, K projection qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v0, qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v1 qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v2, qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v3 qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v4, qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v5
Angle definition sequence index qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v6 absolute position qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v7 relative time-difference qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v8
Attention qi,ki,vi=xiWq,xiWk,xiWvq_i, k_i, v_i = x_i W_q, x_i W_k, x_i W_v9 qiq_i0 qiq_i1

4. Hyperparameterization and Design Choices

Key hyperparameters and operational design components include:

  • Base frequencies qiq_i2: Inherited from RoFormer to preserve cross-dimensional scale invariance.
  • Distance metric qiq_i3: Commonly raw seconds; normalization (e.g., scaling to hours or clipping outliers) is essential for stable angular resolution.
  • Angle scaling qiq_i4: To prevent rotation angle wrap-around for large qiq_i5, a learnable temperature qiq_i6 can be introduced: qiq_i7.
  • Even-dimensionality requirement: ReDRE follows RoPE in requiring qiq_i8 divisible by 2, due to 2D subspace pairing.
  • Class-imbalance handling: For fraud detection, loss weighting according to the non-fraud/fraud sample ratio is essential when the class distribution is highly skewed.

5. Empirical Performance and Ablation

In the introduced credit card fraud detection task (IEEE-CIS dataset, qiq_i96 months, kjk_j03.5% fraud), three model variants were benchmarked (Reyes et al., 12 Jul 2025):

Model AUC-ROC (test)
Transformer + sinusoidal 0.7286
RoFormer + absolute RoPE 0.7288
RoFormer + ReDRE 0.7400

ReDRE demonstrates a kjk_j10.011 absolute improvement in AUC over RoFormer baselines. Pure feature injection of kjk_j2 without rotation only matches the RoFormer baseline, establishing that the gain is attributable to the geometric encoding of temporal relationships rather than the mere availability of time-delta information.

6. Applicability, Generalization, and Limitations

ReDRE is generally applicable wherever meaningful “distance” (temporal, spatial, structural) between sequence events can be defined:

  • Time series with irregular or heterogeneous event spacing
  • System logs, user action traces, network packet streams
  • Graph-structured data by substituting kjk_j3 with other distance metrics (e.g., graph-edit distances).

Recommended best practices include normalization of kjk_j4 or temperature scaling to prevent aliasing or angular wrap-around, and rigorous data preprocessing (imputation, normalization, and imbalance handling).

For very long sequences, ReDRE can be paired with sparsity-inducing attention mechanisms or segment-level aggregation to bound computational complexity. Its benefit is magnified in data regimes where the precise temporal (or event distance) geometry encodes critical dependencies; in generic natural language modeling tasks, further empirical study is required to establish consistent gains.

7. Summary and Theoretical Implications

Relative Distance Rotating Encoding provides an explicit, attention-level mechanism for token-by-token adaptation to arbitrary event distances by replacing absolute rotary encodings with relative ones. This design channels temporal geometry directly into the self-attention kernel, enabling enhanced discrimination of irregular or bursty sequences, particularly in domains such as fraud detection. Empirical results confirm that this explicit geometric modeling is nontrivially beneficial beyond simple feature augmentation. ReDRE is directly extensible to any Transformer-style model and can be adapted to non-temporal “distance” metrics as needed (Reyes et al., 12 Jul 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Relative Distance Rotating Encoding (ReDRE).