Sequences, streaming data, robotics, and scientific extensions · Entry index · SEQ005 · Model
Temporal Graph Networks (TGN)
A framework for graph learning from timed interactions using node memories, event messages, memory updates, and temporal embeddings.
In CodeSplash
Running this needs images, audio, video, graphs or another data type CodeSplash doesn't load yet.
- Availability
- Needs a data type CodeSplash doesn't load yet
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review, but on a different version of the code. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
A framework for graph learning from timed interactions using node memories, event messages, memory updates, and temporal embeddings. It models evolving relational state rather than treating a static graph snapshot as the entire training example.
Question / hypotheses
Can a model predict or represent a timed interaction using only graph history available before it occurs? There is no inherent null test; the critical comparison is chronological performance under realistic event availability and negative-sampling rules.
Architecture / computational structure
Interactions generate messages; node-specific memory is updated in time order; a temporal embedding module combines memory with neighborhood history; a task head predicts links or labels. The memory state is not itself a fixed learned parameter and must be reset or carried consistently across splits.
Assumptions
Event order and timestamps must be correct. Memory-update timing can leak the event being predicted if implemented incorrectly. Unobserved interactions are not necessarily true negatives, and performance can depend heavily on which nodes or edges appear during training.
Formula / computational definition
A schematic update is followed by . Temporal graph embeddings derived from memory/history feed task heads. The message, aggregation, and embedding choices define the specific TGN configuration.
Parameters and notation
Learned parameters: message functions, recurrent memory updater, temporal embeddings, and decoder. Stateful quantities: node memories and buffered messages. Hyperparameters: memory width, time encoding, neighbor sampling, update batching, and negative sampler; these affect both capacity and information flow.
Fitting, fine-tuning, and adaptation
Train on chronological events and specify when memory is detached/reset. For adaptation, update task/embedding components cautiously and rebuild memory from permitted history. Evaluate unseen-node and known-node settings separately; randomly splitting edges can permit future-history leakage.
How to use and calibrate
Report temporal link prediction or node-task metrics under fixed negatives, cold-start performance, update latency, and memory cost. Include ablations for timestamp-only shortcuts and tests with realistic delayed observations. A high random-edge-split score is not evidence of prospective utility.
Example application
Predict a synthetic communication stream’s next interactions while deliberately withholding future edges from memory.
Interpretation / pitfalls
Watch out
Python: the official TGN implementation or a documented compatible temporal-graph stack. R: reticulate for model/state handling and native analysis of outputs. The example illustrates a gated memory update only; it does not instantiate TGN message/neighbor modules.
Python and R code examples (dependencies/validation)
Python uses NumPy and the shared mse helper when called; base R uses the shared helper when called. Validation: Python component executed; R companion reviewed, not executed. Scope: the specific component described above, not the full model or its training.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — synthetic mathematical component, not a full-model implementation
Shared setup for this chapter
import numpy as np
def mse(a,b):
a,b=np.asarray(a),np.asarray(b)
if a.shape!=b.shape or a.size==0:
raise ValueError("MSE needs nonempty equal shapes")
return float(np.mean((a-b)**2))
old=np.array([.2,-.1]); candidate=np.array([.6,.3]); gate=1/(1+np.exp(-np.array([.4,-.2])))
result=(1-gate)*old+gate*candidate
print(result)
Component demo, not a trained model — synthetic mathematical component, not a full-model implementation
Shared setup for this chapter
mse <- function(a,b) {
stopifnot(length(a)>0L, identical(dim(a),dim(b)), length(a)==length(b))
mean((a-b)^2)
}
old <- c(.2,-.1); candidate <- c(.6,.3); gate <- 1/(1+exp(-c(.4,-.2)))
result <- (1-gate)*old+gate*candidate
print(result)
Sources
- Source 1arxiv.org
- Source 2github.com
From the CodeSplash reference, entry SEQ005.