Encoding Continuous Time in Attention Networks

411 concepts335 papers11 proposals

Standard sequence models treat data like a metronome—each token arrives exactly one tick after the last. In natural language processing, this discrete assumption works well because words follow one another in a strict, uniform sequence. However, when applying attention-based architectures to real-world phenomena like user clickstreams, video frames, financial markets, or physical trajectories, this uniform assumption breaks down.

In these domains, events occur at irregular intervals. An event that happened five minutes ago has a fundamentally different relationship to the present than one that happened five months ago, even if both are exactly one step backward in the sequence history. To capture this, researchers have shifted from discrete token-index encodings to temporal positional encodings that treat time as a continuous, topologically structured dimension.

From Token Indices to Continuous Time

How do we feed a raw timestamp into an attention layer? If we simply use absolute integers (such as Unix timestamps), a neural network will struggle to generalize and will quickly encounter out-of-distribution values during inference as time marches forward.

To solve this, architectures often map continuous timestamps into periodic vector spaces using trigonometric transformations. As demonstrated by Francesco Giuliari et al. in Transformer Networks for Trajectory Forecasting, sinusoidal positional encodings can map coordinate data directly to specific timestamps. This allows non-sequential models to process entire trajectories in parallel while preserving the exact chronological relationships between observations.

By leveraging the mathematical properties of sine and cosine functions, models can also represent relative time differences rather than absolute dates. For instance, Pengyang Wang et al. show in Temporal Inductive Path Neural Network for Temporal Knowledge Graph Reasoning that periodic functions can effectively encode the temporal distance between a historical event and a target query time. Because the encoding depends on the delta ($\Delta t$) rather than an absolute calendar date, the model can recognize recurring temporal patterns across different eras.

Modeling Relative Intervals and Gaps

Often, the absolute time an event occurred matters less than the duration of the gap between events. A user buying a camera and immediately purchasing a lens indicates a single, continuous intent. If that same lens purchase happens three months later, it represents a disjointed event.

To capture these dynamics, Wei Zhang et al. introduce explicit temporal interval embeddings in Learning Long- and Short-Term User Literal-Preference with Multimodal Hierarchical Transformer Network for Personalized Image Caption. By integrating the elapsed time between historical events directly into the sequence encoder, the network can dynamically down-weight or up-weight past behaviors based on their recency and temporal proximity to the current task.

Discrete Encoding:   [Event A] -> (1 step) -> [Event B] -> (1 step) -> [Event C]

Temporal Encoding:   [Event A] ---- (3 Months) ----> [Event B] -- (5 Mins) --> [Event C]
                     (Distanced Context)             (Highly Relevant Context)

To scale this intuition across an entire sequence, Gaode Chen et al. develop a multi-interest framework in Exploring Periodicity and Interactivity in Multi-Interest Framework for Sequential Recommendation that computes a complete time interval matrix between all items in a sequence. This matrix is fed into a time-aware attention mechanism, allowing the system to distinguish between routine, tightly clustered behaviors and occasional, sparse interactions.

Preserving Chronological Topology

A major pitfall of treating timestamps as independent categorical identifiers or unconstrained continuous vectors is that the model can lose the concept of linear progression. It does not inherently know that the year 2025 succeeds 2024, or that an event "before" a query requires a different causal interpretation than an event "after" it.

To inject this directional inductive bias, recent frameworks enforce chronological topology directly within the embedding space. In Improving Time Sensitivity for Question Answering over Temporal Knowledge Graphs, Chao Shang et al. introduce an auxiliary loss function that penalizes the model if the geometric distance or direction between timestamp vectors does not reflect their actual chronological sequence.

This approach is mirrored by Yonghao Liu et al. in Local and Global: Temporal Question Answering via Information Fusion, where an auxiliary task forces the model to predict the relative order of timestamps. By constraining the embedding space such that the geometric trajectory of the vectors mirrors the arrow of time, the system learns a structured representation of history rather than treating dates as disconnected labels.

Disentangling Local and Global Timelines

When sequences span long operational periods, relying solely on global timestamps can introduce instability or out-of-distribution errors. For example, in robotics, a controller needs to know the precise sequence of joint positions within a brief movement window, but referencing a global system clock that has been running for hours can degrade performance.

To counter this, Xinyuan Wu et al. implement localized position encodings in Adaptive Control Strategy for Quadruped Robots in Actuator Degradation Scenarios. By limiting the temporal context to the length of the immediate input sequence rather than global timestamps, the model avoids encountering out-of-distribution time values during extended deployments.

Conversely, complex human behaviors often require multi-dimensional temporal structures that capture both local and global scales simultaneously. As noted by Yufei Feng et al. in Deep Session Interest Network for Click-Through Rate Prediction, standard positional encodings fail to capture hierarchical timelines, such as the relative position of an action within an active user session versus the macro-chronological order of the sessions themselves. By separating these temporal dimensions into distinct hierarchical encodings, architectures can maintain sharp local focus while preserving long-term historical awareness.

History & citationVersion 1 · 2026-10-04

Current · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_temporal_positional_encoding_cdc6b04b,
  title = {temporal positional encoding},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/temporal-positional-encoding/rdr_cdc6b04b8867487e946eae84c646667f},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-27},
}

This exact version (version 1, frozen text):

@misc{lacuna_temporal_positional_encoding_cdc6b04b_v1,
  title = {temporal positional encoding},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/temporal-positional-encoding/rdr_cdc6b04b8867487e946eae84c646667f/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-27},
}
About

These directions overlap with this one through shared papers.

See something wrong? Report a mistake