Abstract
Modeling asynchronous event sequences is a critical task across diverse domains, from finance to healthcare. Traditional approaches like Hawkes processes and Recurrent Neural Networks (RNNs) often struggle with long-range dependencies or lack interpretability. We present the Self-Attentive Hawkes Process (SAHP), which leverages a modified Transformer architecture. By introducing a novel time-shifted positional encoding and a dynamic intensity function, SAHP effectively captures complex temporal dynamics and cross-event correlations, outperforming state-of-the-art models in both event type and timestamp prediction.
Introduction
Real-world data often arrives as asynchronous streams of multi-modal events. For instance, a patient's medical history consists of various diagnoses and treatments occurring at irregular intervals. Modeling these sequences requires capturing how past events influence the probability of future ones—a concept formalized by Hawkes processes. While RNN-based models have improved flexibility, they often act as "black boxes" and fail to handle very long sequences efficiently.
The Self-Attentive Hawkes Process (SAHP) addresses these issues by adapting the self-attention mechanism. Unlike standard Transformers that only consider event order, SAHP incorporates the actual time intervals between events, allowing for a more nuanced understanding of temporal influence.
Methodology
Model Architecture
The SAHP architecture follows the Transformer encoder structure but is tailored for continuous-time event sequences. As shown in Figure 1, the model takes a sequence of events $(v_i, t_i)$ as input, where $v_i$ is the event type and $t_i$ is the timestamp. These are passed through an embedding layer and a series of self-attention blocks.
The output of the attention layers, a hidden representation $h_{u, i+1}$, is then used to compute the parameters of a dynamic intensity function $\lambda_u(t)$. This function determines the likelihood of the next event occurring at time $t$.
Time-Shifted Positional Encoding
A core innovation of SAHP is the "time-shifted" positional encoding. In standard self-attention, positional encodings are functions of the discrete index $i$. SAHP modifies this by treating the timestamp $t_i$ as a phase shift: $$pe(v_i, t_i) = \sin(\omega \cdot i + w \cdot t_i)$$ This allows the model to distinguish between events that are sequentially adjacent but temporally distant. Figure 2 illustrates how the timestamp shifts the sinusoidal encoding, providing a continuous representation of time within the discrete attention framework.
Experimental Results
The researchers evaluated SAHP against several baselines, including RMTPP and CTLSTM, across synthetic and real-world datasets such as Retweet (social media), StackOverflow (user awards), and MIMIC-II (clinical records).
SAHP consistently achieved superior performance:
- Log-Likelihood: SAHP reached the lowest Negative Log-Likelihood (NLL) across all datasets. For the Retweet dataset, it achieved an NLL of 4.56, significantly better than the best baseline (5.32).
- Prediction Accuracy: In predicting the next event type, SAHP showed substantial gains, reaching an $F_1$ score of 58.50% on synthetic data compared to 45.21% for the best RNN-based model.
- Temporal Precision: The model also yielded the lowest Root Mean Square Error (RMSE) for predicting event timing, validating the effectiveness of the time-shifted encoding.
Discussion and Conclusion
Beyond performance, SAHP offers enhanced interpretability. The attention weights can be interpreted as an "infectivity matrix," revealing how different event types trigger or inhibit one another. Unlike traditional Hawkes processes, SAHP can model inhibitory effects, where a past event decreases the likelihood of a future one.
While the model introduces some computational overhead due to the Monte Carlo sampling required for training, its ability to handle long-range dependencies and provide physically meaningful attention weights makes it a powerful tool for asynchronous sequence modeling. Future work may explore more flexible, non-parametric intensity shapes and formal causal inference.
Summary updated