Between Linear and Sinusoidal: Rethinking the Time Encoder in Dynamic Graph Learning

Hsing-Huan Chung, Shravan S Chaudhari, Xing Han, Yoav Wald, Suchi Saria, Joydeep Ghosh

Abstract

Dynamic graph learning is essential for applications involving temporal networks and requires effective modeling of temporal relationships. Seminal attention-based models like TGAT and DyGFormer rely on sinusoidal time encoders to capture temporal relationships between edge events. In this paper, we study a simpler alternative: the linear time encoder, which avoids temporal information loss caused by sinusoidal functions and reduces the need for high dimensional time encoders. We show that the self-attention mechanism can effectively learn to compute time spans from linear time encodings and extract relevant temporal patterns. Through extensive experiments on six dynamic graph datasets, we demonstrate that the linear time encoder improves the performance of TGAT and DyGFormer in most cases. Moreover, the linear time encoder can lead to significant savings in model parameters with minimal performance loss. For example, compared to a 100-dimensional sinusoidal time encoder, TGAT with a 2-dimensional linear time encoder saves 43% of parameters and achieves higher average precision on five datasets. These results can be readily used to positively impact the design choices of a wide variety of dynamic graph learning architectures.

The Problem: Temporal Information Loss

Dynamic graphs—networks where connections between nodes appear and disappear over time—require models to understand temporal context. State-of-the-art models like TGAT and DyGFormer typically use sinusoidal time encoders to map timestamps into high-dimensional vectors. This approach was inspired by the belief that the inner products of sinusoids naturally represent time spans.

However, this paper identifies a critical flaw: sinusoidal functions are many-to-one. Due to their periodic nature, different time intervals can result in identical encodings, leading to "temporal information loss." To mitigate this ambiguity, researchers have traditionally relied on very high-dimensional encodings (e.g., 100 dimensions), which significantly inflates model size without addressing the root cause.

Methods: The Case for Linear Encoders

The authors propose a simpler Linear Time Encoder. Instead of complex oscillations, they use a linear transformation of the standardized time difference: $$\Phi(\Delta t') = [w_1 \Delta t' + b_1, \dots, w_{d_T} \Delta t' + b_{d_T}]^\top$$

The core theoretical contribution (Proposition 3.1) proves that the self-attention mechanism is mathematically capable of "factoring out" the time span between events from these linear encodings. This suggests that the model does not require the encoder to provide pre-computed time-span logic; it can learn the necessary temporal relationships directly from linear features.

Key Insights: Why Simplicity Wins

  • Periodicity as a Bug: In most dynamic graphs, time progresses linearly. Sinusoidal encoders introduce artificial cycles that can confuse models, particularly when time gaps exceed the encoding's period.
  • Self-Attention as a Calculator: The paper demonstrates that self-attention is powerful enough to compute temporal relationships from raw linear features. This shifts the burden of understanding time from feature engineering to the learning mechanism itself.
Learned vs. true attention scores for linear time encoders with $d_T=2$ and $d_T=8$.
  • Extreme Parameter Efficiency: Because linear encodings are non-ambiguous, they do not require high dimensionality. A 2-dimensional linear encoder often outperforms a 100-dimensional sinusoidal one.
  • Robustness to Distribution Shift: On datasets like UCI, where waiting times increase during the test phase, linear encoders adapt more gracefully than sinusoidal models, which are often tuned to training set statistics.

Key Results: Performance and Efficiency

Across 24 model-dataset combinations, the linear time encoder outperformed sinusoidal variants in 19 cases under random negative sampling. The gains were particularly pronounced on the UCI and Wikipedia datasets, with Average Precision (AP) increases of up to 22.48 points.

Test accuracy of different time encoders across various model architectures and dimensions $d_T$.

Beyond performance, the efficiency gains are substantial. For the TGAT model, switching to a 2D linear encoder reduced total parameters by 43% while improving AP on five out of six datasets.

Discussion and Future Directions

The authors note one exception: the US Legis dataset. With only 12 unique, discrete time steps, the many-to-one nature of sinusoids is not a hindrance, and their periodic bias may even be beneficial. Future work will explore hybrid encoders that combine linear and periodic features, as well as adapting relative positional encodings from NLP to continuous-time dynamic graphs.

Summary updated

BibTeX
@inproceedings{chung2025between,
  author = {Hsing-Huan Chung and Shravan S Chaudhari and Xing Han and Yoav Wald and Suchi Saria and Joydeep Ghosh},
  title = {{Between Linear and Sinusoidal: Rethinking the Time Encoder in Dynamic Graph Learning}},
  booktitle = {TGL @ KDD},
  year = {2025},
  url = {https://openreview.net/forum?id=JQUN43u0lC},
}
Figure