Reality is a stream, not a static snapshot. Temporal Graph Networks (TGNs) are designed to capture the evolving dynamics of networks that change in continuous time, powering modern fraud detection and real-time recommendation engines.
1Persistent Node Memory
Standard GNNs suffer from severe temporal amnesia. They only see the graph as it exists right now. If a fraudster transfers money rapidly through 5 accounts and then deletes their account, a static GNN processing the graph an hour later sees nothing.
The core innovation of a Temporal Graph Network (TGN) is the Node Memory. A TGN maintains a persistent hidden state vector for every node in the graph. Every time a node is involved in an interaction (an 'Event' like a tweet, purchase, or transfer), its memory is updated using an RNN-like memory cell (usually a GRU). This allows the model to compress a user's long-term historical behavior into a dense vector, while still being able to react instantly to their most recent action.
// TGN Memory Update Step
function updateMemory(node_id, event, time_delta) {
const current_mem = MemoryStore.get(node_id);
// 1. Create message from the new event
const msg = concat(event.features,
timeEncode(time_delta),
event.counterpart_mem);
// 2. Update memory using GRU cell
const new_mem = GRU_Cell(msg, current_mem);
// 3. Save state
MemoryStore.set(node_id, new_mem);
}2The Geometry of Time
How do you teach a neural network the concept of 'Last Week' versus 'Just Now'? We use Continuous-Time Encodings. Instead of treating time as discrete steps (Epoch 1, Epoch 2), TGNs look at the exact continuous time difference between events (Δt = Current_Time - Last_Event_Time).
By mapping this time difference into a high-dimensional vector space using trainable sinusoidal functions (similar to Positional Encodings in Transformers), the model learns complex temporal geometries. It can learn that a 'burst' of five interactions in ten seconds is highly suspicious bot behavior, while five interactions spaced out over five days is normal human behavior. During inference, a node's embedding is generated by combining its persistent memory, the time encoding of the current query, and a graph convolution over its temporal neighbors.
// Continuous-Time Encoding (Fourier Features)
function timeEncode(delta_t, dim = 64) {
const encoding = new Array(dim);
// w_i are learnable frequencies
for (let i = 0; i < dim; i++) {
const w = learned_frequencies[i];
// Map scalar time to high-dim vector
encoding[i] = Math.cos(w * delta_t);
}
return encoding;
}