Temporal Graph Networks (TGN)

A framework for deep learning on graphs that change over time, developed at Twitter. Cited over 2,000 times, with 1,200+ stars on GitHub.

A dynamic social graph: users follow, tweet and retweet over time, and the task is to predict a future edge
A dynamic graph is a stream of timestamped events (follows, tweets, retweets). TGN learns from this stream to predict, for example, which edges will appear next.

Emanuele Rossi, Ben Chamberlain, Fabrizio Frasca, Davide Eynard, Federico Monti, Michael Bronstein
ICML 2020 Workshop on Graph Representation Learning

In short

Most graph neural networks assume a graph that does not change. Many real systems are not like that: nodes and edges keep appearing over time in social networks, financial transactions and recommender systems, but also across science, from the contact networks through which epidemics spread, to interactions between proteins or brain regions, to the social structure of animal groups. Temporal Graph Networks (TGN) learn directly from such a graph seen as a continuous stream of timestamped events.

The key idea is a memory for every node: a compact summary of everything that node has been involved in so far, updated each time a new event touches it. When the model needs a representation of a node, it combines this memory with information from the node’s recent neighbours through a graph attention layer. This makes TGN both more accurate and more efficient than previous approaches to dynamic graphs.

How it works

TGN is a framework made of a few interchangeable modules:

  • Memory: a state vector per node, storing its history in compressed form.
  • Message function: when an event (e.g. an interaction between two nodes) happens, it computes a message for each node involved.
  • Memory updater: a recurrent network (such as a GRU) that updates each node’s memory with its new messages.
  • Embedding module: computes up-to-date node embeddings by aggregating memories of temporal neighbours with graph attention. This also handles nodes whose memory is stale because they have not been active recently.
TGN training flow: a batch of timestamped interactions produces node embeddings, edge probabilities and a loss, then messages that update each node's memory
How TGN processes a batch of interactions during training: (1) compute node embeddings from the current memory, (2) decode them into edge probabilities and (3) compute the loss; then (4) build messages from the batch and (5) use them to update the memory of the nodes involved.

Several earlier models for dynamic graphs, such as JODIE, DyRep and TGAT, can be expressed as particular choices of these modules. The paper includes an ablation study of the different components and identifies the best-performing configuration.

Code

The official PyTorch implementation is available at twitter-research/tgn. TGN is also implemented in PyTorch Geometric, which makes it easy to use as a building block in other models.

Talks

Jun 2021 Machine Learning on Dynamic Graphs: Temporal Graph Networks
MLOps World 2021
Apr 2021 Machine Learning on Dynamic Graphs: Temporal Graph Networks
Intel ML Seminar
Apr 2021 Machine Learning on Dynamic Graphs: Temporal Graph Networks
GNNSys'21 Workshop
Jan 2021 Dynamic Graphs and Temporal Graph Networks
University of Liverpool Networks and Distributed Computing Series
Jul 2020 TGN: Temporal Graph Networks
AISC

Writing

Follow-up work

Later work on temporal graphs that I contributed to, including benchmarks that have become standard for evaluating models like TGN.

2024

  1. NeurIPS
    tgb2.png
    Conference
    TGB 2.0: A Benchmark for Learning on Temporal Knowledge Graphs and Heterogeneous Graphs
    Julia Gastinger, Shenyang Huang, …, Emanuele Rossi, …, Guillaume Rabusseau
    Advances in Neural Information Processing Systems, 2024
  2. LoG
    utg.png
    Conference
    UTG: Towards a Unified View of Snapshot and Event Based Models for Temporal Graphs
    Shenyang Huang, Farimah Poursafaei, …, Emanuele Rossi
    Learning on Graphs Conference (LoG), 2024

2023

  1. NeurIPS
    tgb.png
    Conference
    Temporal Graph Benchmark for Machine Learning on Temporal Graphs
    Shenyang Huang, Farimah Poursafaei, …, Emanuele Rossi, …, Reihaneh Rabbany
    Advances in Neural Information Processing Systems, 2023

Citation

@article{rossi2020tgn,
  title   = {Temporal Graph Networks for Deep Learning on Dynamic Graphs},
  author  = {Emanuele Rossi and Ben Chamberlain and Fabrizio Frasca and Davide Eynard and Federico Monti and Michael Bronstein},
  journal = {ICML Workshop on Graph Representation Learning},
  year    = {2020}
}