Designing Signal Conditioned Rotary Embeddings
Designing Signal-Conditioned Rotary Embeddings
Replace the fixed RoPE angle p_i * θ_j with a learned, signal-conditioned angle:
PythonΘ_j(T_i, p_i) = f_φ(T_i)_j * ω_j^s + p_i * θ_j * λ └── temporal (SIREN) ┘ └── ordinal (scaled) ┘
f_φ: dual-branch network (periodic SIREN + aperiodic ReLU DNN) mapping timestamp features → per-dimension anglesω_j^s: learnable per-dimension frequency scale (init toπ)θ_j = base^(-2j/d_k): standard RoPE inverse frequencies (kept fixed)λ: learnable scalar gate (init to1.0) balancing ordinal vs. temporal contribution
Apply the resulting Θ_j exactly like standard RoPE's rotation angle (real-valued 2D rotation, no complex ops needed—torch.compile compatible).
Progress:
- Step 1: Identify the "hidden dimension" — what non-ordinal signal is being discarded (timestamps, categorical metadata, cyclical patterns)?
- Step 2: Decompose the raw signal into model-friendly features (see below)
- Step 3: Design the dual-branch mapping network (periodic + aperiodic)
- Step 4: Fuse with the ordinal term via a learnable gate, don't replace it outright
- Step 5: Initialize near the original RoPE behavior for training stability
- Step 6: Build controlled baselines to isolate rotation-space vs. embedding-space signal
- Step 7: Validate on calibration + ranking metrics, inspect learned gate value as evidence
Step 2: Feature decomposition for continuous/cyclical signals
For any periodic raw signal (e.g., Unix timestamp), always encode each cycle as a (cos, sin) pair to avoid phase discontinuities at period boundaries:
t(T) = [cos(2πT/τ_d), sin(2πT/τ_d), # daily cycle
cos(2πT/τ_w), sin(2πT/τ_w), # weekly cycle
T_normalized] # long-range aperiodic trend
Generalize: one (cos, sin) pair per known periodicity, plus one normalized scalar for aperiodic/monotone trend (e.g., recency decay). This lets the downstream network recover cycles (e.g., time-of-day patterns) without needing side info like timezone.
Step 3: Dual-branch mapping network
f_φ(T) = f_sin(T) + f_DNN(T)
- Periodic branch (
f_sin): SIREN layers —sin(ω_0 · Wx + b)— to autonomously discover periodicities beyond the manually specified ones. - Aperiodic branch (
f_DNN): standard ReLU MLP for monotone trends (decay, drift). Still capable of periodic modeling if fed cyclical features, but primarily there for trend capture. - Combine additively; keep the network small (target <1% parameter overhead).
Step 4: Fusion and gating
Never fully discard the ordinal term — fuse it with a learnable scalar gate λ:
Θ_j = f_φ(T)_j · ω_j^s + p_i · θ_j · λ
This preserves translational equivariance / recency-decay properties of vanilla RoPE while letting gradient descent decide the balance. Track λ's trajectory during training — a large drop from init (e.g., 1.0 → 0.04) is strong empirical evidence the new signal dimension is doing the work.
Step 5: Initialization for stability
Initialize ω_j^s near the value that recovers something close to standard RoPE's frequency scale (e.g., π), and λ = 1.0. This ensures training starts near a known-good configuration rather than from scratch.
Step 6: Controlled baseline design (critical for proving the idea)
To isolate where a new signal helps, hold everything else fixed and vary only how the signal is injected:
- Ordinal-only baseline: no new signal at all (standard RoPE).
- Feature-injection baseline: inject the new signal as an appended embedding/feature (semantic space), keep rotation purely ordinal. This tests whether the signal helps at all regardless of mechanism.
- Fixed-schedule rotation baseline: inject the signal into rotation angle using the existing fixed inverse-frequency formula (no learned mapping).
- Full method: learned signal-conditioned rotation (your contribution).
Comparing baselines 2 vs. 4 isolates "does routing through rotation space beat routing through embedding space." Comparing 3 vs. 4 isolates "does the learned mapping beat a fixed schedule."
Step 7: Evaluation
Use both calibration metrics (e.g., normalized entropy/NE) and ranking metrics (e.g., AUC) across multiple related tasks. Report parameter overhead explicitly (aim for negligible, e.g., ~0.2%). Use production-scale data if available — real irregular-interval behavior is the whole motivation, and synthetic/academic benchmarks with uniform sampling won't expose the gap.
Example 1: Input: Sequential recommender using ordinal RoPE; user interactions have real Unix timestamps with clear diurnal/weekly patterns, but ordinal position ignores actual elapsed time. Output: Dual-branch SIREN-RoPE architecture as above; four-way baseline comparison (ordinal / timestamp-as-feature / fixed-schedule time-rotation / learned SIREN-rotation); report λ convergence and NE/AUC deltas across tasks.
Example 2:
Input: A new categorical signal (e.g., device type, geographic region) should modulate attention, and you want to know if it belongs in embeddings or in rotation.
Output: Replace f_φ(T) with an embedding lookup or small encoder over the categorical feature, feed it into the same fusion formula in place of/alongside the temporal branch, then run the same controlled-baseline protocol (feature-injection vs. rotation-injection) to measure which space captures more signal.
- Treat the rotation manifold as a first-class learnable space, not just a positional scaffold — but always keep a path back to standard RoPE behavior via initialization.
- Encode any cyclical raw signal as
(cos, sin)pairs, never as a raw scalar (avoids discontinuities). - Use additive periodic+aperiodic decomposition rather than a single monolithic network — makes the inductive bias explicit and improves sample efficiency.
- Keep the rotation-conditioning network small; the value proposition is signal quality, not capacity.
- Always include a gate/scaling parameter and monitor its learned value as an interpretability signal and ablation proof point.
- Design baselines that vary only the "where does the signal go" axis (embedding vs. rotation vs. fixed vs. learned) — this is the cleanest way to attribute gains correctly.
- Stay compatible with real-valued rotation math (avoid complex tensors) for compiler/kernel compatibility.
- Don't fully replace the ordinal term — sequences still carry order information the new signal may not fully subsume, especially early in training.
- Don't skip the fixed-schedule-rotation baseline (e.g., TO-RoPE-style) — without it you can't tell if gains come from "signal in rotation space" vs. "learned nonlinear mapping."
- Don't use a single scalar or raw timestamp as direct input to a rotation-conditioning network — raw magnitudes cause poor conditioning and destroy periodicity; always decompose first.
- Don't evaluate only on uniformly-sampled academic benchmarks — the entire motivation (irregular intervals) requires production-like, bursty, real-world event data to manifest.
- Don't ignore parameter/compute overhead reporting — a core selling point of this approach is that it's cheap; unsubstantiated claims of "negligible overhead" undermine credibility.
- Don't initialize the gate or frequency scales far from the standard-RoPE-equivalent point — poor initialization risks unstable early training since rotation angles directly affect every attention score.