CS224W

Lecture 14 · Tue 11/10 · slides PDF · lecture notes

Advanced Topics in GNNs — In-Context Learning and Relational Foundation Models

Can one pretrained graph model solve a new task on a new graph from a few examples, with no gradient updates? PRODIGY does it with "prompt graphs"; the Relational Transformer does it for any database by tokenising cells.

26
sectionstick "got it" as you go
27
figuresredrawn from the slides
interactive figuresplay with the ideas
5
self-check questionsplus flashcards
18′
reading time3,885 words, walkthrough aside

Before you start: review of the earlier sessions

The thread so far. Sessions 12–13 showed a foundation model for databases; session 14 asks the general question: how do we get in-context learning on any graph, and how do we trust the predictions?

What this session takes from earlier ones

  • Lecture 5: self-supervised pretraining tasks, generalised here into prompt graphs
  • Lecture 3: the computation graph: a prompt graph is a data graph plus a task graph on top of it
  • Lecture 13: the relational foundation model of Lecture 13 as a database example of in-context learning

Those sessions in one minute each

Lecture 13 · Advanced Architectures in Relational Deep Learning

Architect for how relational data is actually stored: send messages along schema-derived atomic routes so junction tables don't dilute or echo information (RelGNN), or encode each context node with type, hop, time and structure for a transformer (RelGT) — the backbone for relational foundation models.

\[ \text{token}_v=\phi_{feat}(\mathbf x_v)+\phi_{type}(\tau(v))+\phi_{hop}(d(v,\text{seed}))+\phi_{time}(t_v-t_{seed})+\phi_{PE}(\text{GNN}(v)) \]

One natural way to combine RelGT's five element-wise encodings (sum or concatenation + projection).

Lecture 5 · GNN Augmentation and Training

Choose the computation graph deliberately (features, virtual nodes, sampling), pick the head that matches the task level, and split so that information from validation/test can never leak into training through message passing.

\[ \hat y_v=\mathbf{W}^{(H)}\mathbf{h}_v^{(L)},\qquad \hat y_{uv}=\mathbf{h}_u^{(L)\top}\mathbf{h}_v^{(L)},\qquad \hat y_G=\text{Pool}\big(\{\mathbf{h}_v^{(L)}:v\in G\}\big) \]

Lecture 3 · Graph Neural Networks

A GNN layer = for every node, combine its own vector with an order-free aggregate of its neighbours' vectors, using weights shared across all nodes; stacking K layers lets information travel K hops.

\[ H^{(k+1)}=\sigma\big(D^{-1}A\,H^{(k)}W_k^\top + H^{(k)}B_k^\top\big) \]

Rows of \(H\) are node embeddings; \(D^{-1}A\) averages over neighbours; \(W_k\) transforms the neighbourhood message; \(B_k\) transforms the node itself.

Warm-up: answer these before you read on

What makes a model a foundation model here? from Lecture 13

It is pretrained once and solves new tasks on new databases from in-context examples, without gradient updates.

What is the difference between a transductive and an inductive split? from Lecture 5

Transductive: one graph, all nodes visible, only labels are split. Inductive: separate graphs (or subgraphs) for training and test, so test nodes are never seen.

What does the self-loop (or the B matrix) do in the GCN layer? from Lecture 3

It keeps the node's own previous vector in the update, so a node does not forget its own features while absorbing its neighbours'.

What is an atomic route? from Lecture 13

A short path (e.g. customer → transaction → product) treated as one message, so the informative node two hops away reaches the target in one step.

More questions from every session you have reached, with spaced repetition: the cumulative review.

In short

LLMs changed ML by doing in-context learning (ICL): show a few examples in the prompt ("thanks → merci, wall → mur, hello → ?") and the model performs the task without any gradient update. This lecture asks how to get the same ability on graphs and databases.

PRODIGY (NeurIPS 2023) solves two problems. (1) Format: represent any few-shot graph task — node, edge or graph classification — as a prompt graph: each example's local subgraph (data graph) plus a task graph that links example "data nodes" to "label nodes". Then classification becomes link prediction between queries and labels. (2) Pretraining: train a hierarchical GNN on self-supervised tasks written in that same format (neighbour matching + multi-task). Result: in-context learning on unseen graphs and tasks, up to 48% better than contrastive pretraining.

The Relational Transformer (RT) generalises Lecture 13's foundation-model goal: tokenise each database cell as (value, column, table) so any schema maps into one input space; cast any task as masked token prediction; restrict attention with relational masks (column, feature, neighbour, full). Pretrained leave-one-database-out, a 22M-parameter RT beats a 27B-parameter LLM by 13% zero-shot AUROC.

The assigned readings also include conformalised GNNs (uncertainty quantification), covered in the readings section.

The picture: a PRODIGY prompt graph

Prompt graph = data graphs + task graph prompt examples S (data graphs) queries Q 1 label Tlabel F examples ↔ all labels 2 label → query (one way) ? 3 logit = cos(h_label, h_query) 4

How to read it (hover a step)

  1. Data graphs: each input \(x\) (a node, an edge, or a whole graph) is contextualised by extracting its local subgraph from the source graph; a GNN encodes each into a data node.
  2. Task graph: one label node per class. Each prompt example connects bidirectionally to all label nodes (edge features say T/F: is this its label?) — that's how the examples "teach" the task.
  3. Queries receive single directed edges from each label node (so label information flows to them, not back). Different numbers of classes/shots just mean different numbers of label/data nodes.
  4. After message passing over the task graph, the prediction is the label node with the highest cosine similarity to the query — classification becomes link prediction in the prompt graph.

1 · Paradigms: training, fine-tuning, in-context learning

  • Training: one model per task.
  • Training vs fine-tuning vs in-context learning. slide 7 ↗
  • Fine-tuning: pretrain once, update weights for each new task.
  • In-context learning: perform a new task by "learning" from examples in the input context, without gradient updates — predicting sums, unscrambling words, translating, all from one foundation model.

For graphs, an in-context learner should solve novel tasks on novel graphs without gradient updates — e.g. given a few labelled edges (link classification) in an unseen knowledge graph, classify new edges. Two challenges: (1) a unified input format so one model can consume prompts for any graph task; (2) a way to pretrain a model that can solve any task in that format.

ICL over graphs: novel tasks on novel graphs. slide 14 ↗

2 · PRODIGY's prompt graph

Step 1 — data graph. Contextualise each input in graph \(G\) by subgraph extraction (around the edge's two endpoints for link prediction, around the node for node classification, the graph itself for graph classification). Different input node sets handle different task levels; text features from a pretrained language model (e.g. BERT) unify feature spaces across datasets.

Step 2 — task graph. Interconnect inputs and labels across examples to form context for the queries: prompt examples ↔ all label nodes (bidirectional, with T/F edge attributes), label nodes → queries (single directed edges). Flexible: 2-shot 2-class or 1-shot 3-class prompts just change the node counts.

Task graph over data graphs. slide 24 ↗

Inference — in-context prediction GNN. Hierarchical message passing: (1) a data-graph encoder GNN embeds each data graph; (2) an attention GNN passes messages over the task graph; (3) logits = cosine similarity between label and query embeddings.

Hierarchical message passing over the prompt graph. slide 41 ↗

3 · Pretraining for in-context learning

Generate pretraining tasks in prompt-graph format and optimise the same model on them. Two data-generation streams:

  • Neighbour matching (self-supervised): sample a few local neighbourhoods; each neighbourhood is a "class" defined by the nodes in it; the task is to classify which neighbourhood a query node belongs to. No labels needed.
  • Neighbour matching: classify which neighbourhood a node is in. slide 48 ↗
  • Multi-task (supervised): select multiple real tasks available in the pretraining graph.

Prompt graphs are then augmented (e.g. feature corruption). Objectives: classification loss over the generated tasks + an attribute-prediction loss reconstructing corrupted features. Mixing pipelines yields more diverse data and better results.

Results

ICL results on arXiv (pretrained on MAG). slide 55 ↗

Pretrain on MAG240M (citation) or Wiki (KG); evaluate ICL on arXiv paper categories and KG link prediction (FB15K-237, NELL, ConceptNet). Baselines: no pretraining, contrastive pretraining + nearest-neighbour, contrastive + fine-tuned linear head. PRODIGY improves in all cases — up to 48% over contrastive and 3× over fine-tuning — even when pretrained only with neighbour matching, which knows nothing about paper categories. Pretrained with 3-shot prompts, it keeps improving with many more shots at test time, and scales with more pretraining data.

More shots at test time keep helping. slide 58 ↗

4 · Relational Transformer: zero-shot over any database

End-to-end RDL models (RDL-GNN, RelGNN, RelGT, RelLLM) are schema- and task-specific, and they tokenise at the row level, which ties the architecture to a schema. RT's promise: zero-shot forecasting on new databases and unseen tasks; few-shot / fine-tuning with limited supervision; democratising AI for structured data.

Three core innovations

  1. Cell-level tokenisation: each token = (value, column, table). Value through a per-datatype encoder (numerical, text, boolean, time); column and table names through a frozen language model (MiniLMv2) describing "<column> of <table>". Any schema maps into one consistent input space, and cell-to-cell dependencies are explicit.
  2. Cell-level tokenisation: (value, column, table). slide 72 ↗
  3. Task-table integration: the task (e.g. User-Churn) is a table whose label cell is masked; any node-level task becomes masked token prediction. Earlier task rows provide in-context labels.
  4. Relational attention: attention restricted by relational masks — column attention (cells in the same column), feature attention (cells of the same row and its linked parent rows), neighbour attention (cells of FK-linked rows), and full attention.
  5. Relational attention masks. slide 81 ↗

Context sampling (no leakage)

  1. Sample the seed row and hide the target value.
  2. Always include parent rows (F→P keys).
  3. Subsample child rows (P→F keys) by breadth-first search.
  4. Only sample rows with earlier timestamps.

Setup and results

Zero-shot transfer results (RT vs Gemma, Griffin, EntityMean). slide 92 ↗

12 layers, 22M parameters; masked-token pretraining on RelBench, 50K steps on 8×A100; Huber loss for regression, BCE for classification; leave-one-database-out pretraining, tested on the unseen schema. Baselines: Griffin (universal feature encoder + GNN), Gemma-3 LLMs on text-serialised subgraphs, RDL-GNN. RT has 1000× fewer parameters, needs a 100× smaller context and gets 13% better zero-shot AUROC than Gemma3-27B; it is the only neural method to beat the non-neural "entity mean" baseline on zero-shot regression; and it fine-tunes quickly when labels exist.

Limitations: no link prediction / recommendation yet; limited pretraining data; room to improve cell encoders and positional biases.

5 · Reading-only topic: conformal prediction for GNNs

One assigned reading (CF-GNN, Huang et al., NeurIPS 2023) isn't in the slides but completes the "advanced topics" picture: how confident should we be in a GNN's prediction?

Conformal prediction wraps any model to output a prediction set \(C(x)\) with a guarantee: \(P(y\in C(x))\ge1-\alpha\) (e.g. 90%), assuming exchangeability between calibration and test points. Recipe: compute non-conformity scores (e.g. \(1-\hat p_y\)) on a held-out calibration set, take the \(\lceil(n+1)(1-\alpha)\rceil/n\) quantile \(\hat q\), and include every label with score ≤ \(\hat q\).

The graph twist: in transductive node classification, calibration and test nodes are connected — CF-GNN shows exchangeability still holds under permutation-invariant training, then trains a second "topology-aware" GNN to make the sets smaller (more efficient) while keeping coverage, exploiting that neighbouring nodes have correlated uncertainty.

The mathematics, step by step

Two ideas with different mathematics. In-context learning needs one formula: classify by the nearest label vector. The second half is about trusting a prediction, and its central result, conformal prediction, is a counting argument that needs no assumption on the model. Each step of that argument is spelled out below.

Symbols used in this session

symbolmeaningwhat kind of object
\(\mathbf h_q,\ \mathbf h_{\text{label }c}\)embeddings of the query node and of the label node for class \(c\) in the prompt graphvectors
\(\cos(\mathbf a,\mathbf b)\)cosine similarity \(\mathbf a^\top\mathbf b/(\lVert\mathbf a\rVert\lVert\mathbf b\rVert)\)number in \([-1,1]\)
\(k,\ m\)shots (labelled examples per class) and ways (number of classes) of a few-shot taskwhole numbers
\(\phi_{\text{dtype}}\)encoder chosen by the data type of a cell (number, text, date, …)function
\(\alpha\)allowed error rate; \(1-\alpha\) is the coverage aimed fornumber in \((0,1)\), e.g. 0.1
\(n\)number of calibration examples (labelled, not used for training)whole number
\(s_i\)conformity score of calibration example \(i\): how badly the model fits the true label, e.g. \(1-\hat p(y_i\mid x_i)\)real number; small = good fit
\(\hat q\)threshold: the \(\lceil(n+1)(1-\alpha)\rceil\)-th smallest calibration scorereal number
\(C(x)\)prediction set: all labels whose score is at most \(\hat q\)set of labels

1Classifying by the nearest label node

\[ \hat y_q=\arg\max_{c}\ \cos\big(\mathbf h_{\text{label }c},\ \mathbf h_{q}\big) \]

In words. The prompt graph contains one node per class. After message passing, the query is assigned to the class whose label node has the embedding most similar in direction to the query's.

Why it has this form. PRODIGY links each example's node to the label node of its class and each query's node to all label nodes; a GNN on this small graph lets the label nodes absorb what their examples look like. Predicting the class is then predicting which query–label edge exists: link prediction. No output layer has a fixed number of classes, so the same pretrained network handles a 3-class task and a 40-class task. Cosine is used because only the direction should matter, not the length of the vectors.

With numbers. \(\mathbf h_q=(1,1)\). Label A: \((10,0)\), dot product \(10\), cosine \(10/(\sqrt2\cdot10)=0.71\). Label B: \((1,3)\), dot product \(4\), cosine \(4/(\sqrt2\cdot\sqrt{10})=0.89\). The dot product would choose A only because its vector is long; the cosine chooses B, whose direction is closer to the query's.

Watch out. A \(k\)-shot, \(m\)-way task supplies \(k\cdot m\) examples in total. With \(k=3\), \(m=5\) the model sees 15 labelled examples and nothing else about the task.

2A database cell as a token; masked-cell prediction

\[ \text{token}_{cell}=\phi_{\text{dtype}}(\text{value})+\text{LM}(\text{column name, table name}),\qquad \mathcal L=\sum_{\text{masked cells}}\ell\big(\hat v_{cell},\,v_{cell}\big) \]

In words. Every cell of the database becomes one token: an encoding of its value, chosen by its data type, plus a language-model embedding of the names of its column and table. Training hides some cells and asks the model to fill them in.

Why it has this form. A new database has new tables and columns, so nothing may be tied to a particular schema. A cell is the unit every database shares, and a column's name carries its meaning ('price', 'signup date') in a form a language model already understands. Any predictive task can then be written as one more cell: append a column for the label, mask it for the query row, and predict it. Attention is restricted by the structure: same row, same column, and rows linked by foreign keys. The loss \(\ell\) is cross-entropy for categories and a regression loss for numbers.

With numbers. The cell '19.99' in column 'price' of table 'products': \(\phi_{\text{number}}(19.99)+\text{LM}(\text{'price of products'})\). The churn task adds a column 'churned' to 'customers'; the query customer's cell in that column is masked, and the model's output for it is the prediction.

Watch out. The number of tokens grows with rows × columns of the sampled context, so the context must be sampled carefully, as in Lecture 13.

3Conformal prediction: the threshold

\[ \hat q=\text{the } \lceil(n+1)(1-\alpha)\rceil\text{-th smallest of } s_1,\dots,s_n,\qquad C(x)=\{y:\ s(x,y)\le\hat q\} \]

In words. Compute the score of the true label on \(n\) held-out examples and sort the scores. Take the one at position \(\lceil(n+1)(1-\alpha)\rceil\) as the threshold. For a new input, output every label whose score is no larger than the threshold.

Why it has this form. The score measures how strange a label looks to the model. The calibration scores show how strange true labels typically look. Choosing the threshold near the \((1-\alpha)\) quantile means: accept every label that is no stranger than \(1-\alpha\) of the true labels were. The model's probabilities are never assumed to be correct; a bad model simply produces larger sets.

With numbers. \(n=9\), \(\alpha=0.2\). Sorted scores: \(0.05,0.10,0.12,0.20,0.25,0.30,0.45,0.60,0.90\). Position \(\lceil10\cdot0.8\rceil=8\), so \(\hat q=0.60\). A test node with class probabilities \((0.55,0.42,0.03)\) has scores \(1-p=(0.45,0.58,0.97)\): the set is the first two classes. A confident node with \((0.95,0.04,0.01)\) gets the set \(\{1\}\).

Watch out. It is \((n+1)\), not \(n\): the test point counts as one more draw. If \(\lceil(n+1)(1-\alpha)\rceil>n\) (too few calibration points for the requested coverage), the set must contain every label.

4Why the guarantee holds, and how much the coverage varies

\[ \Pr\big(y_{\text{test}}\in C(x_{\text{test}})\big)\ \ge\ 1-\alpha,\qquad \text{coverage given the calibration set}\ \sim\ \mathrm{Beta}(n+1-l,\ l),\quad l=\lfloor(n+1)\alpha\rfloor \]

In words. Averaged over calibration sets, the true label is in the set at least \(1-\alpha\) of the time. For one particular calibration set, the actual coverage is a random number that follows a Beta distribution centred near \(1-\alpha\) and tighter for larger \(n\).

Why it has this form. Assume the calibration examples and the test example are exchangeable (any order is equally likely). Then the rank of the test score among the \(n+1\) scores is equally likely to be \(1,2,\dots,n+1\). The true label is covered exactly when that rank is at most \(\lceil(n+1)(1-\alpha)\rceil\), which has probability \(\lceil(n+1)(1-\alpha)\rceil/(n+1)\ge1-\alpha\). That is the whole proof: counting ranks. The Beta law describes the spread of this coverage from one calibration set to another.

With numbers. \(n=9\), \(\alpha=0.2\): \(l=2\), coverage \(\sim\mathrm{Beta}(8,2)\) with mean \(0.80\) and standard deviation \(0.12\): one unlucky calibration set can easily give 65%. \(n=999\), \(\alpha=0.1\): \(l=100\), \(\mathrm{Beta}(900,100)\) with mean \(0.90\) and standard deviation \(0.009\).

Watch out. Exchangeability is the assumption that fails on graphs: nodes are linked, and a test set from a later time or a different region is not exchangeable with the calibration nodes. The guarantee is also only on average over all nodes, not for each class or each degree group.

Check yourself

Questions from the lecture, in order. Answer each one in your head (or on paper) before you open it. If one stumps you, follow the link to the walkthrough block it comes from.

Check yourself: why is ICL harder on graphs than on text? show answer

Text tasks all share one format, a token sequence. Graph tasks differ in what the input is: a node, a pair of nodes, or a whole graph, and in what the classes are.

from In-context learning over graphs: the goal and two challenges

Check yourself: in PRODIGY, where does the "knowledge of the task" live at test time? show answer

In the T/F edges of the task graph and the embeddings of the label nodes, not in any weights.

from Scaling with shots and data; PRODIGY conclusion

Check yourself: which Lecture 13 idea does rule 4 repeat? show answer

Temporal neighbour sampling in RDL, where only events before the prediction time are used.

from Context sampling

Check yourself: why is EntityMean a strong baseline? show answer

Many forecasting targets are very persistent: a user's past churn or a product's past sales predicts the next value well.

from RT results, discussion and limitations

Lecture walkthrough reference · slide by slide · opens on demand

The whole lecture in order, grouped by topic. Every drawing on the slides is redrawn here as a clean figure (click the step buttons where a figure has them), the heading of each block links to the matching pages of the official PDF, and the Review section after the walkthrough ties this session to the earlier ones. Read this and you do not need the deck.

  1. Today's plan and three ML paradigms
  2. In-context learning over graphs: the goal and two challenges
  3. Prompt Graph step 1: data graphs
  4. Prompt Graph step 2: the task graph
  5. Prompt Graph inference: the in-context prediction GNN
  6. PRODIGY pretraining: generating tasks
  7. Experiments and in-context learning results
  8. Scaling with shots and data; PRODIGY conclusion
  9. Recap: relational deep learning and its limits
  10. The goal: a relational foundation model; RT overview
  11. Cell-level tokenization and task-table integration
  12. Context sampling
  13. Relational attention
  14. Experimental setup and pretraining
  15. RT results, discussion and limitations

Today's plan and three ML paradigms slides 3,5-10 ↗

Slides 5–10: three ways to use a model. In-context learning solves a new task from examples in the prompt with no weight updates. slides 5-10 ↗

Slide 3 names the two papers of this lecture. PRODIGY: Enabling In-context Learning Over Graphs (Huang, Ren, Chen, Krvzmanc, Zeng, Liang, Leskovec; NeurIPS 2023) and the Relational Transformer (Ranjan, Hudovernik, Znidar, Kanatsoulis): "Toward Zero-Shot Foundation Models for Relational Data". Both ask the same question: can one pretrained model solve a new task on new data without being retrained?

Slides 5–7 build one figure that compares three ways to do machine learning. Each column is a network (a trapezoid) with an input at the bottom and an output at the top.

  • Training (slide 5): three separate networks for three tasks. The same input "hello" gives "5" (count letters), "h" (first letter) or "bonjour" (translate), each from its own model.
  • Fine-tuning (slide 6): one big shared network (blue) at the bottom, with a small task-specific head on top for each task. You pretrain once, then update weights for each task.
  • In-context learning (slide 7): one big network with no task heads. The input itself carries the task: "Thanks → merci, Wall → mur, hello → ?". The model answers "bonjour". This is few-shot prompting.

Slide 8 defines in-context learning (ICL): performing a new task by "learning" from the input context, without any gradient update. The slide calls it very powerful, because now one foundation model can directly answer all tasks. The three small panels show GPT-style prompts for predicting a sum ("3 + 8 = 11, …"), unscrambling words and translating; in each, a few examples come first and the model completes the last line.

Slide 9 asks the lecture's question: what is in-context learning over graphs? Slide 10 gives the plan. PRODIGY is an in-context learner for graphs that solves novel tasks on novel graphs. It has three parts:

  1. Prompt Graph representation: put the few-shot prompt for any graph task into one input format that a single shared model can read.
  2. Prompt Graph inference: an "in-context prediction GNN" that reads this format.
  3. Pretraining: generate many diverse pretraining tasks in the Prompt Graph format (Neighbor Matching and MultiTask).

In-context learning over graphs: the goal and two challenges slides 12,14-16 ↗

Slide 14: in-context link classification on a never-seen graph: a few labelled pairs as examples, then a query. slides 12-16 ↗

Slide 12 recalls the three classic graph learning tasks: node classification, link prediction and graph classification. The pictures are a social network, a knowledge graph and a set of small molecules.

Slide 14 shows what ICL means on a graph, using link classification. On the left is text prompting again (different tasks, same model). On the right:

  • A graph \(\mathcal{G}\) (a new graph the model has never seen). Some nodes are drawn as coloured circles (head input nodes) and coloured triangles (tail input nodes).
  • Prompt examples \(\mathcal{S}\): four pairs (circle, triangle) as input \(x\), each with a label \(y\) drawn as an orange or blue diamond (for example, the relation type of the edge).
  • Queries \(\mathcal{Q}\): a new pair (blue circle, blue triangle) whose label is "orange or blue?".

The yellow box states the requirement: an in-context learner for graphs should solve novel tasks on novel graphs without gradient updates. "Different graphs" and "different tasks" are both marked in red: both can change between pretraining and use.

Slides 15–16 state the two challenges and their answers:

  1. Format. How do we represent the few-shot prompt for different graph tasks in the same input format, so one shared model can consume it? Answer: the Prompt Graph, which represents each few-shot prompt as a meta hierarchical graph.
  2. Pretraining. How do we pretrain a model that can solve any task in this format? Answer: PG pretraining: pretrain a message-passing model on self-supervised tasks written in the Prompt Graph format, over diverse underlying graphs.
Check yourself: why is ICL harder on graphs than on text? show answer

Text tasks all share one format, a token sequence. Graph tasks differ in what the input is: a node, a pair of nodes, or a whole graph, and in what the classes are.

Prompt Graph step 1: data graphs slides 18-23 ↗

Slides 18–23, the Prompt Graph. Step through: data graphs (one subgraph per example or query), data nodes above them, label nodes, T/F edges from examples, and one-way edges into the query. slides 18-23 ↗

Slide 18 shows the full Prompt Graph, "a unified representation of few-shot prompts over graphs for diverse tasks". It has two layers:

  • Bottom (orange band), data graphs \(\mathcal{G}^d\): one small circled subgraph per prompt example (four of them, the prompt examples \(\mathcal{S}\)) and one per query (\(\mathcal{Q}\)).
  • Top (blue band), the task graph: one square data node \(v_x\) above each data graph, and two diamond label nodes \(v_y\). Edges between them are marked T (green) or F (red), and edges to the query are marked "?".

Slides 19–22 explain step 1, the data graph: it contextualizes each input \(x\) in the graph \(\mathcal{G}\), for example by subgraph extraction. A single node or edge means little on its own; its neighbourhood carries the information.

  • Link prediction (slides 19–20): for each input pair (head, tail), extract the subgraph around both endpoints. The figure shows each prompt example and query of slide 14 turned into one circled subgraph containing its circle and triangle.
  • Node classification (slide 21): the input is a single node; extract the subgraph around it.
  • Graph classification (slide 22): the input is already a small graph, so the data graph is that graph itself.

Slide 23 sums up how the data graph unifies the input format:

  • Use a different input node set for classification at different levels: one node for node classification, two nodes for edge classification, all nodes for graph classification. The rest of the pipeline stays the same.
  • Use text features to unify node features across datasets (each node's text is embedded by a language model, so all graphs share one feature space).
Lecture notes figure, page 77
Notes Figure 14.4: a Prompt Graph for link prediction. Data graphs (bottom) for four prompt examples and one query; the task graph (top) links data nodes to the two label nodes with T/F edges, and labels to the query with "?" edges. notes p.77 ↗

Prompt Graph step 2: the task graph slides 24-35 ↗

Slides 24–35, the task graph: examples connect to every label node with T or F edges; queries only receive edges from the labels. Any number of classes and shots fits this format. slides 24-35 ↗

Slide 24 introduces step 2, the task graph: it interconnects inputs and labels across examples to form context for the queries. Slides 25–31 build it for link prediction, one piece at a time:

  1. Slide 26: put one data node \(v_x\) above each data graph (it will hold the embedding of that subgraph), and one label node \(v_y\) for each class (two diamonds here).
  2. Slides 27–28, prompt examples: add bidirectional edges between each example's data node and all label nodes. The edge to the true label carries the feature T; the edges to the other labels carry F. So each example tells the label nodes "I am an instance of you" or "I am not".
  3. Slides 29–30, queries: add single directed edges from each label node to each query data node (the "?" edges). Information flows from labels to the query, but the query cannot change the label nodes.

Slide 31 shows the finished task graph above the data graphs. Slides 32 and 33 show that the same construction works for node classification (input = single node) and graph classification (input = small graph): only the data graphs change.

Slide 34, flexibility of the task graph. It unifies the classification format:

  • A different number of classes just means a different number of label nodes.
  • A different number of prompt examples (shots) and queries just means a different number of data nodes and different connections to the label nodes.

The two small pictures are a 2-shot prompt for 2-class classification and a 1-shot prompt for 3-class classification.

Slide 35 explains why this works. On the left, ICL over a graph (graph, prompt examples, query). On the right, the Prompt Graph. The task graph reflects what the task is through the examples (their commonalities and differences), and the data graphs capture all relevant information about each input. The key reframing: ICL over a graph becomes inductive link prediction over a hierarchical graph: predict which label node the query's data node should link to.

Prompt Graph inference: the in-context prediction GNN slides 37-41 ↗

Slides 37–41, the in-context prediction GNN: a shared GNN encodes each data graph into its data node, attention-based message passing runs over the task graph, and the query's logit is the cosine similarity between its data node and each label node. slides 37-41 ↗

Slide 37 shows the inference picture: the whole Prompt Graph goes into a model, which outputs scores for the queries. Slides 38–41 open the model. It does hierarchical message passing over the Prompt Graph, in three stages:

  1. Data graph encoder (slide 39). A GNN (the same weights for all, drawn as five blue "GNN" boxes) runs on each data graph and pools the embeddings of the input nodes into the embedding of the data node \(v_x\). This turns "a subgraph around an input" into one vector.
  2. Message passing over the task graph (slide 40). A second GNN, a GNN with attention, runs on the task graph. Label nodes collect messages from the example data nodes (with T/F edge features), so each label node becomes a summary of "what my examples look like". Query data nodes receive messages from the label nodes.
  3. Compute logits (slide 41). For each query and each label, \[ \text{logit} = \text{cosine\_similarity}(h_{\text{label}},\, h_{\text{data}}). \] The predicted class is the label node with the highest score.

Intuition: the label node embeddings play the role of class prototypes, but they are not fixed. They are built at inference time from the examples in the prompt, so a new set of classes needs no new weights. Check yourself: if you give a 5-way prompt to a model pretrained only on 3-way prompts, what changes in the computation? (Only the number of label nodes; the GNN weights are reused.)

Lecture notes figure, page 77
Notes Figure 14.5: message passing over hierarchical edges. One GNN encodes each data graph into its data node; the task graph is processed on top. notes p.77 ↗

PRODIGY pretraining: generating tasks slides 43-50 ↗

Slides 43–50: pretraining generates tasks in the Prompt Graph format from the pretraining graph itself. slides 43-50 ↗
Slide 48, neighbour matching: sample a few local neighbourhoods and ask which one a node belongs to; a self-supervised classification task with the prompt-graph shape. slide 48 ↗

Slide 43: to pretrain, we generate pretraining tasks in the Prompt Graph format and pretrain the model over them. The pipeline is: pretraining data/graph → data generation → Prompt Graph → model → optimize loss. Slide 44 points at the "data gen" step.

Slides 45–47 split data generation into two stages:

  1. Few-shot prompt generation from the pretraining graph, by one of two routes:
    • MultiTask (slide 46): simply select several labelled tasks that exist on the pretraining graph and sample few-shot prompts from them. This is supervised pretraining.
    • Neighbor Matching (slide 47): a self-supervised task that needs no labels.
  2. Convert to Prompt Graph, with augmentation (for example, dropping nodes or corrupting features in the data graphs).

Slide 48, Neighbor Matching. Idea: classify which neighbourhood a node is in, where each neighbourhood is defined by other nodes in it. The figure shows one large graph with four sampled local neighbourhoods \(\mathcal{G}^d_1, \dots, \mathcal{G}^d_4\) (dotted circles, each around a coloured centre node). Each neighbourhood becomes a class. Prompt examples: four coloured centre nodes, each labelled with its neighbourhood's diamond (two orange, two blue). Queries: two yellow nodes; the "?" arrows ask whether a yellow node lies in the orange or the blue neighbourhood (the dashed circles show 2-hop neighbourhoods). The labels come for free from the graph structure, so we can make unlimited tasks of any number of ways.

Slide 49: mixing different data generation pipelines (Neighbor Matching + MultiTask) gives more diverse pretraining data and better results.

Slide 50, the pretraining objectives:

  • a classification loss over the generated tasks (pick the right label node for each query);
  • an attribute prediction loss: reconstruct the features that were corrupted during data-graph augmentation.

Why this works: the model never sees the downstream task, but it practises the skill of reading a prompt and matching a query to the examples. That skill is what transfers.

Lecture notes figure, page 78
Notes Figure 14.6: Neighbor Matching. Four sampled neighbourhoods act as classes; the question is which neighbourhood a query node belongs to. notes p.78 ↗

Experiments and in-context learning results slides 51-57 ↗

Slides 54–57: in-context accuracy on arXiv against the number of classes. Green PRODIGY, gold PG-NM, navy Contrastive, red Finetune, grey NoPretrain. slides 54-57 ↗

Slide 51, evaluation and datasets. Two pretraining graphs: MAG240M, a large-scale citation network, and Wiki, a knowledge graph built from Wikipedia (Xiong et al., 2018b). After pretraining, in-context performance is measured on different downstream graphs: paper category prediction on arXiv, and KG link prediction on FB15K-237, NELL and ConceptNet.

Slide 52, baselines:

  • NoPretrain: same architecture, random initialization.
  • Contrastive: standard contrastive pretraining with the same augmentation, then a hard-coded nearest-neighbour rule to fit the in-context setting.
  • Finetune: a linear classification head trained on top of the contrastively pretrained encoder (so it does use gradient updates).

And three variants of PRODIGY: PG-NM (Neighbor Matching only), PG-MT (MultiTask only), and PG-ALL (both; shown as "PRODIGY" in the table).

Slide 53: graphs have different features. PRODIGY handles this with text embeddings from a pretrained language model (for example BERT).

Slides 54–57 show one table: pretrain on MAG, then in-context classification of arXiv paper categories. Accuracy (%) by number of classes (ways):

ClassesNoPretrainContrastivePG-NMPG-MTPRODIGYFinetune
333.1665.0872.5065.6473.0965.42
518.3351.6361.2151.9761.5253.49
109.1936.7846.1237.2346.7430.22
204.7225.1833.7125.9134.4117.68
402.6217.0223.6917.1925.138.04
  • Result 1 (slide 55): PRODIGY improves performance in all cases, up to 48% over Contrastive and 3× over Finetune (40 ways: 25.13 vs 17.02 and 8.04). Notice that NoPretrain is at chance level (about 100/ways).
  • Result 2 (slide 56): PG-NM alone is already strong. Its pretraining had no idea about classifying paper categories, yet it induces strong in-context learning: very different self-supervised tasks are enough.
  • Result 3 (slide 57): mixing pipelines (PRODIGY = PG-ALL) gives the best numbers.

Why does Finetune lose so badly with many classes? With 40 classes and only a few shots per class, a newly trained linear head overfits; PRODIGY builds class prototypes from the prompt and needs no training.

Scaling with shots and data; PRODIGY conclusion slides 58-60 ↗

Slides 58–59: more shots at test time keep helping (curve values read from the slide), and performance keeps scaling with pretraining data. slides 58-59 ↗

Slide 58, scaling with more shots. The plot is ConceptNet, 4-way, accuracy against the number of shots (1 to 20). PG-ALL (orange) rises from about 0.43 to about 0.63; Contrastive (blue) rises from about 0.38 to about 0.51 and flattens early. The message: the model was pretrained with only 3 shots, but it can learn from much more than 3 shots in the context. It generalizes to longer prompts than it saw.

Slide 59, data scaling. Accuracy against the number of training steps (log scale, \(10^3\) to about \(2\times10^4\)). PG-ALL climbs steadily from about 0.455 to about 0.60; Contrastive is noisy and stays around 0.50–0.53. The message: hard and diverse pretraining-task generation lets the model keep scaling with more training data.

Slide 60, conclusion. PRODIGY enables in-context learning over graphs with a new task representation, the Prompt Graph, plus a matching pretraining architecture and objectives:

  • The Prompt Graph is a unified representation of few-shot prompts over graphs for diverse tasks.
  • Pretraining a hierarchical message-passing model over Prompt Graphs enables in-context learning on unseen tasks on unseen graphs.
  • Hard and diverse pretraining tasks let the model keep improving with more training data.
Check yourself: in PRODIGY, where does the "knowledge of the task" live at test time? show answer

In the T/F edges of the task graph and the embeddings of the label nodes, not in any weights.

Recap: relational deep learning and its limits slides 62-66 ↗

Slides 62–66, recap of relational deep learning and its central limitation. slides 62-66 ↗

The second part (by Charilaos Kanatsoulis) is about transformers for relational data, towards foundation models for forecasting over relational databases. It builds on Lecture 13.

Slide 62 recalls Relational Deep Learning (RDL; Fey et al. 2023) as a four-step pipeline: relational DB → graph problem → graph ML → solutions.

Slide 63, the key insight: a relational database is an entity-level graph. Every entity (row) is a node, and edges are defined by foreign-key–primary-key links. The figure turns three tables (Users, Sales, Products) into a graph: user icons on the left, sales amounts in the middle, product icons on the right, with coloured bands showing which user bought which product.

Slide 64: predictive tasks become graph ML problems.

  • Node-level: churn, lifetime value.
  • Link-level: product affinity, recommendation.
  • Graph-level: fraud detection.

Slide 65 lists RDL architectures: RDL-GNN (Robinson et al. 2024), RelGNN (Cheng, Kanatsoulis, Leskovec 2025), the Relational Graph Transformer RelGT (Dwivedi et al. 2025) and RelLLM (Wu et al. 2025).

Slide 66, the disadvantages of end-to-end RDL. The figure adds churn labels ("Churn"/"Active" per month) to the users. Two problems:

  1. Schema- and task-specific: the model is built and trained for one database and one task.
  2. Limited transfer: it cannot generalize to new databases or new tasks.

The goal: a relational foundation model; RT overview slides 67-69 ↗

Slides 67–69: the foundation-model goal and the three ideas of the Relational Transformer. slides 67-69 ↗

Slide 67, the goal: bring the success of foundation models (LLMs, ViT) to relational data. The pictures are an LLM and the Vision Transformer, which splits an image into patches and feeds them as tokens to a transformer encoder.

Slide 68, the promise of a relational foundation model:

  • Zero-shot forecasting on new databases and unseen tasks.
  • Few-shot / fine-tuning with limited supervision.
  • Broader impact: democratize AI for structured data. Non-experts get accessible predictive tools; experts get a strong pretrained initialization.

Slide 69, the Relational Transformer (RT). Key idea: treat each database cell as a token and model the relationships between cells with Relational Attention. Three core innovations: (1) cell-level tokenization, (2) task-table integration, (3) relational attention. The slide's figure has three panels:

  • (a) Schema: tables User (UserID (P), Gender), Sale (Time, UserID (F), ItemID (F), Stars), Item (ItemID (P), Price, Details), plus a Task table (Time, ItemID (F), Label) for the task "predict total sales over next week". (P) = primary key, (F) = foreign key.
  • (b) Context window: a set of cells taken from these tables. Task rows from the past provide in-context labels; the target row has its label cell masked ("?").
  • (c) Architecture: for all cells, a per-datatype encoder (num | text | bool | time) plus a frozen language-model embedding of "<column> of <table>"; then \(N\) Relational Transformer blocks, each with Column, Feature and Neighbor attention, then Full attention, then an MLP; then a per-datatype decoder that outputs the predicted cell value.

Cell-level tokenization and task-table integration slides 70-73 ↗

Slides 70–73: every cell becomes a token tagged with its column and table, so any schema maps to one input space; the task table is just another table whose value is masked. slides 70-73 ↗

Slide 70 shows the running example: three linked tables, Transactions, Products and Users; lines show foreign-key links from transaction rows to product rows and user rows.

Slide 71: prior work (RDL-GNN, RelGNN, RelGT, RelLLM) tokenizes at the row level: one row = one node/token, with a table-specific encoder for its columns. This leads to schema-specific architectures: a new database with different columns needs new encoders.

Slide 72, RT's cell-level tokenization. Each token is a triple \[ \text{token} = (\text{value},\ \text{column},\ \text{table}). \] The table and column are given as text descriptions embedded with MiniLMv2 (a small language model). Benefits:

  • It unifies relational databases of any schema into one consistent input space: every database is just a set of (value, column-name, table-name) tokens.
  • It leverages cell-to-cell dependencies: attention can relate single cells, not only whole rows.

Slide 73, task label integration. The task itself becomes a table, here User-Churn with columns Fkey (the user), Val (the label) and Time. Its rows link to Users like any other table. Benefits:

  • Any node-level task becomes masked token prediction (MTP): hide the Val cell of the target row and predict it.
  • It adds autoregressive labels as task tokens: past rows of the task table, with their labels visible, sit in the context as in-context examples.

Compare with PRODIGY: there, labels were label nodes in a task graph; here, labels are ordinary cells in a task table. Both put the examples into the input instead of into the weights.

Context sampling slides 74-80 ↗

Slides 74–80: the context window around a prediction: parents always, children sampled, nothing from the future. slides 74-80 ↗

A database is too big for one transformer context, so RT samples a context window around each prediction. Slide 74 lists the sampling rules:

  1. Sample a seed node (a row of the task table) and hide its value.
  2. Always include parent nodes (follow F → P keys: from a foreign key to the row it points to).
  3. Subsample child rows (follow P → F keys: rows that point to this row). Slide 74 calls this a breadth-first search over children.
  4. Only sample from previous timestamps.

Slides 75–80 animate this on the example:

  • Slide 75: the seed is a User-Churn row; its Val cell is hidden (the smiley).
  • Slide 76: its Fkey is user 1, so the parent row of user 1 in Users is included.
  • Slide 77: from user 1, child rows in Transactions (Fkey = 1) are sampled; one has product Fkey 100.
  • Slide 78: that transaction's parent, product 100, is included.
  • Slide 79: a second transaction of user 1 (product 98) and its parent product 98 are added.
  • Slide 80: another User-Churn row of user 1 with time \(t_1 \lt t_0\) is included; its label is visible, so it acts as an in-context example. Rows after \(t_0\) are never sampled.

Why rule 2 is "always" and rule 3 is "subsample": a row has few parents (one per foreign key) but may have thousands of children (a user's transactions). Rule 4 avoids temporal leakage: the model must not see information from the future of the moment it predicts.

Check yourself: which Lecture 13 idea does rule 4 repeat? show answer

Temporal neighbour sampling in RDL, where only events before the prediction time are used.

Relational attention slides 81-85 ↗

Slides 81–85, relational attention: four masks that put columns, rows and keys into the attention pattern, so the same model works on any schema. slides 81-85 ↗

Plain full attention over a set of cell tokens would ignore the structure of the database. RT therefore uses four attention types in each block (slide 81 shows the sampled context with all included cells outlined). The slides highlight, for one query cell (the face emoji), which cells it may attend to:

  1. Column attention (slide 82): a cell attends to the cells in the same column of the same table. The query is the hidden Val cell of the target User-Churn row; it sees the Val cells of the other User-Churn rows, that is, the in-context labels. This is how RT learns "what values this column usually takes".
  2. Feature attention (slide 83): a cell attends to the other cells of its own row and of its parent rows (F → P). The target User-Churn row sees its own cells and the whole Users row of user 1. This mixes the features of an entity.
  3. Neighbor attention (slide 84): a cell attends to the cells of its child rows (rows that point to it through a foreign key). A cell of the Users row sees the user's Transactions rows and User-Churn rows. This is the message-passing step of a GNN, written as masked attention.
  4. Full attention (slide 85): every cell attends to all cells in the context, with no mask.

Intuition: column, feature and neighbor attention are relational masks. They put the schema's structure (columns, rows, keys) into the attention pattern as an inductive bias, while full attention keeps the flexibility of a transformer. Since the masks depend only on "same column", "same row" and "key links", they work for any schema.

Experimental setup and pretraining slides 86-89 ↗

Slides 86–89: the zero-shot protocol and the pretraining recipe. slides 86-89 ↗

Slide 86: RelBench, 7 diverse datasets in four areas: e-commerce (rel-amazon, rel-avito, rel-hm), social (rel-event, rel-stack), sports (rel-f1) and medical (rel-trial).

Slides 87–88, the setup:

  • Tasks: binary classification and regression.
  • Pretraining: leave-one-database-out. Pretrain on the other databases, then test on the unseen schema. This is a true zero-shot test: the model has never seen these tables or columns.
  • Baselines: Griffin (Wang et al. 2025), a universal feature encoder followed by a GNN; Gemma LLMs, prompting Gemma3 with a text-serialized database subgraph; RDL-GNN (Robinson et al. 2024), the schema-specific GNN.

Slide 89, RT pretraining:

  • Backbone: 12 layers, 22M parameters.
  • Pretraining task: masked token prediction on RelBench.
  • Training: 50k steps on 8×A100 GPUs.
  • A linear decoder.
  • Objective: Huber loss for regression, binary cross-entropy (BCE) for classification.

The Huber loss is quadratic for small errors and linear for large ones, so a few extreme target values (common in sales or counts) do not dominate training.

RT results, discussion and limitations slides 91-96 ↗

Slides 92–94: zero-shot transfer to unseen databases; RT is the only neural method above the EntityMean baseline on regression. slides 92-94 ↗
Slide 91, fine-tuning curves (shape read from the slide): pretraining gives a head start that persists. slide 91 ↗

Slide 91, fine-tuning tests: test-set learning curves up to 32k fine-tuning steps (batch size 256), x-axis on a log scale.

  • Left, binary classification (mean of 5 tasks, AUROC %): pretrained RT starts at 70.8 zero-shot, pretrained Griffin at 68.5. Untrained models (RT, RDL-GNN, Griffin) start near 55 or lower. Pretrained RT stays on top and reaches about 80.
  • Right, regression (mean of 4 tasks, \(R^2\) %): pretrained RT starts at 29.0 zero-shot, pretrained Griffin at 17.7. Untrained models start below zero and need about \(10^3\) steps to catch up.

Slide 92, zero-shot classification (AUROC, 10 tasks). Mean AUROC: Gemma 4B 63.3, Gemma 12B 62.4, Gemma 27B 64.6, EntityMean (0 parameters) 66.7, Griffin 64.0, RT 70.1 when the target database is not in pretraining. When it is (but the task label is still unseen), Griffin 67.3 and RT 72.9. Note that bigger Gemma models are not reliably better.

Slide 93, zero-shot regression (\(R^2\) %, 8 tasks; the global-mean baseline scores 0.0). Mean \(R^2\): EntityMean 19.3, Griffin 8.9, RT 22.8 (unseen database); Griffin 10.1, RT 26.4 (seen database). RT is the only neural method to beat EntityMean, the non-neural baseline that predicts an entity's own historical average. LLM baselines are poor here.

Slide 94: RT has 1000× fewer parameters and needs a 100× smaller context, yet gives 13% better zero-shot AUROC than Gemma3-27B.

Slide 95, discussion: RT is capable of robust zero-shot transfer in relational settings and allows rapid fine-tuning when supervision exists; there is strong evidence that relational databases, despite diverse applications, share transferable patterns; it is a step toward foundation models for structured enterprise data.

Slide 96, limitations: no link prediction or recommendation tasks yet; trained on limited data; possible improvements in cell encoders and positional biases.

Check yourself: why is EntityMean a strong baseline? show answer

Many forecasting targets are very persistent: a user's past churn or a product's past sales predicts the next value well.

Not shown (no new content): slides 1,2,4,11,13,17,36,42,61,90 — title slides, announcements, section dividers, and slide 13 (exact duplicate of slide 9).

Review: what to keep from this session

Carried forward. Lecture 15 builds the knowledge-graph foundation model with the same "represent the task as a graph" trick; Lecture 21 continues the trust theme with explainability.

Quick self-check

How does PRODIGY turn classification into link prediction?

Label nodes are added to the task graph; a query node is classified by predicting which label node it should be linked to.

Why pretrain in the prompt-graph format rather than with ordinary supervised tasks?

So that the model learns to read examples from the prompt; a model pretrained on fixed labels has no mechanism for using in-context examples.

What does conformal prediction guarantee?

That the prediction set contains the true label with probability at least 1 − α, under exchangeability of calibration and test data.

Key idea

Foundation models for graphs need a universal input format: PRODIGY turns any few-shot graph task into link prediction on a prompt graph; the Relational Transformer turns any database task into masked-cell prediction over (value, column, table) tokens — and both are pretrained on self-generated tasks in that same format.

\[ \hat y_q=\arg\max_{c}\ \cos\big(\mathbf h_{\text{label }c},\ \mathbf h_{q}\big)\qquad\qquad \text{token}_{cell}=\phi_{\text{dtype}}(\text{value})+\text{LM}(\text{column of table}) \]

Worked example: one in-context prediction

A 3-way, 2-shot prompt on a new KG: relations "bornIn", "worksAt", "marriedTo"; 2 labelled edges each; one query edge (Ali, ?, Tehran).

  1. Build 7 data graphs (6 examples + 1 query) by extracting the 1–2-hop subgraph around each edge's endpoints; encode → 7 data nodes.
  2. Task graph: 3 label nodes; each example ↔ all 3 labels (edge attribute T only for its own label); labels → query.
  3. After message passing, label embeddings absorb their examples; cosines with the query: bornIn 0.81, worksAt 0.42, marriedTo 0.05 → predict bornIn.
  4. No weights changed. A new task = a new prompt graph.

Strictly speaking: PRODIGY's ICL covers classification tasks expressible as "which label?"; regression and generation need other formats. RT handles regression via masked numeric cells but not yet link prediction.

Proof workshop: Why split conformal prediction covers

One problem in olympiad style. Give it fifteen minutes on paper before you open the first hint; the hints are graded, so open them one at a time.

Problem. Let \(s_1,\dots,s_n,s_{n+1}\) be exchangeable non-conformity scores (calibration plus test, ties have probability 0). Let \(\hat q\) be the \(\lceil(n+1)(1-\alpha)\rceil\)-th smallest of \(s_1,\dots,s_n\). Prove \(\Pr(s_{n+1}\le\hat q)\ge1-\alpha\), and show the upper bound \(\Pr(s_{n+1}\le\hat q)<1-\alpha+\frac1{n+1}\).

Hint 1
By exchangeability, the rank of \(s_{n+1}\) among all \(n+1\) scores is uniform on \(\{1,\dots,n+1\}\).
Hint 2
Assume \(\alpha\ge\frac1{n+1}\) so that \(k=\lceil(n+1)(1-\alpha)\rceil\le n\), \(s_{n+1}\le\hat q\) exactly when the rank of \(s_{n+1}\) among the \(n+1\) scores is at most \(k\).
Solution
Let \(R\) be the rank of \(s_{n+1}\) among the \(n+1\) scores; \(R\) is uniform on \(\{1,\dots,n+1\}\). If \(R\le k\), at most \(k-1\) calibration scores are below \(s_{n+1}\), so the \(k\)-th smallest calibration score is \(\ge s_{n+1}\). If \(R>k\), at least \(k\) calibration scores are below \(s_{n+1}\), so \(\hat q\lt s_{n+1}\). Hence \(\Pr(s_{n+1}\le\hat q)=\Pr(R\le k)=\frac{k}{n+1}\ge1-\alpha\), and \(k<(n+1)(1-\alpha)+1\) gives the upper bound. \(\square\)

Why it matters. The guarantee needs only exchangeability, not a good model; a good model only makes the sets small (the notebook: 1.5 labels with a GCN against 3.6 with an MLP, at the same 90%). On graphs the hypothesis is the whole question: transductive node classification with random splits is exchangeable, while temporal or community-based splits are not. That is when you need the graph-aware variants.

Sharper lens: what the guarantees are averages over

Not on the slides. Three or four points where the lecture rounds something off: the exact statement, a second way to see it, and where it stops being true. Each is short and has a pointer for going further.

precise statement

The coverage you actually get is random: a Beta distribution

The theorem in the proof workshop averages over the draw of the calibration set. Fix one calibration set of size \(n\) and the coverage on future points is a random number with distribution

\[ \mathrm{Beta}(n+1-l,\ l),\qquad l=\lfloor(n+1)\alpha\rfloor \]

(Vovk 2012). For \(\alpha=0.1\): with \(n=100\) calibration nodes its standard deviation is 0.030, so "90%" is anywhere from about 84% to 95%; with \(n=1000\) it is 0.0095. This is the first thing to compute when choosing how many labelled nodes to hold out, and the reason a plot of empirical coverage that sits at 88% on one split is not a bug.

where it breaks

Marginal, not conditional: 90% overall can be 60% for one community

The guarantee is \(\Pr(y\in C(x))\ge1-\alpha\) over a random test node. It allows 99% coverage on the easy majority and far less on a minority class, a peripheral community or low-degree nodes. It cannot be strengthened for free: distribution-free coverage conditional on \(x\) is impossible with finite sets (Vovk 2012; Barber, Candès, Ramdas and Tibshirani 2021). Three useful repairs:

  • Group-conditional ("Mondrian") calibration: a separate quantile per class, community or degree bucket. Exact within each group, at the price of fewer calibration points per group (see the Beta distribution above).
  • Weighted conformal prediction under covariate shift: reweight calibration scores by the likelihood ratio between test and calibration distributions (Tibshirani et al., NeurIPS 2019).
  • A bound when exchangeability fails: with weights \(w_i\), coverage is at least \(1-\alpha-\sum_i\tilde w_i\,d_{\mathrm{TV}}(Z,Z^{i})\), where \(Z^i\) swaps calibration point \(i\) with the test point (Barber et al. 2023). Temporal and community splits on a graph are this case; the repository's conformal-shift experiment measures the gap.
second viewpoint

Why "prior-fitted" models work: in-context learning as Bayesian prediction

Train a transformer on many small datasets sampled from a prior over tasks, to predict a held-out label from the rest of the dataset in its context. The expected log-loss is minimised by exactly one function: the posterior predictive distribution \(p(y\mid x,D)\) under that prior (Müller et al., ICLR 2022). The network is then an amortised Bayesian reasoner, and a forward pass does the work of inference.

This gives the lecture one frame. PRODIGY's prior is the empirical distribution of tasks that neighbour matching produces on MAG240M or Wikidata. GraphPFN's and TabPFN's priors are synthetic generators. The Frontier section's finding, that only prior-fitted models beat a tuned GNN, then reads: the quality of an in-context learner is the fit between its prior and your data, and the prior is something you can inspect and criticise. PRODIGY's last step, classifying a query by cosine similarity to label nodes, is a prototypical network (Snell et al. 2017) in graph form.

Lab: hands-on and practical tips

Try it live. In the Graph Explorer: check a GCN's calibration and build conformal prediction sets on Cora, then calibrate on the high-degree nodes only and watch the coverage of the others. Each lesson has predict-then-check questions.

notebook · L14 advanced topics builds a PRODIGY-style in-context prompt graph, implements Relational Transformer attention masks on cell tokens, and runs conformal prediction on a GNN.

Conformal guarantees are about the split, not the modelThe coverage guarantee needs exchangeable calibration and test scores: a random split of nodes on one graph works; a split by time or by community (the honest split for social data) breaks it. CF-GNN's diffusion of scores along edges also assumes neighbours have similar uncertainty, a homophily prior.
Play with α and noise aboveCoverage lands at 1−α for any model; a worse model pays with larger prediction sets. Report average set size next to coverage, or the guarantee is meaningless (a set containing every class has 100% coverage).
Few-shot graphs need a formatPRODIGY's trick is that node, edge and graph tasks all become link prediction between query nodes and label nodes in a prompt graph. If you want few-shot bot or stance labelling on a new platform, build the prompt graph first and the pre-training objective second.
Relational masks are the inductive biasIn the Relational Transformer, attention restricted to same-column, same-row, neighbouring rows, or everything, is what carries the schema. Ablate the masks; "full attention" on cell tokens is just a table-blind transformer.

Readings & lookup guide

lecture notes CS224W course notes (Leni Aniva, Autumn 2024 — in your course folder)

Concise written version of the lectures; the walkthrough above cites it page by page.

read first Huang et al. — PRODIGY: Enabling In-context Learning Over Graphs (NeurIPS 2023)

  • Read: §3 (prompt graph: data graph + task graph; Fig. 2), §4 (pretraining: neighbour matching, multi-task, augmentation; loss), §5.2 results tables.
  • Think: why does making the task graph's examples→labels edges bidirectional but labels→queries one-way matter?

core Ranjan, Hudovernik, Znidar, Kanatsoulis, et al. — Relational Transformer: Toward Zero-Shot Foundation Models for Relational Data (2025)

  • Read: the architecture figure (cell tokenisation, task table, relational attention), the context-sampling rules, and the zero-shot tables vs Gemma/Griffin.
  • Compare: with RelGT (Lecture 13): row tokens vs cell tokens — what does each make easier?

uncertainty Huang, Jin, Candès, Leskovec — Uncertainty Quantification over Graph with Conformalized Graph Neural Networks (NeurIPS 2023)

arXiv:2305.14535 · ~2 h · for statistics background: Angelopoulos & Bates, "A Gentle Introduction to Conformal Prediction" (2021)
  • Read: §3 (exchangeability in transductive graph settings — the key theorem), §4 (topology-aware correction to shrink prediction sets), coverage/efficiency plots.

Homework & deadlines

Colab 5 out Thu 11/12 · due Thu 12/3

The last Colab; open it from the course website and save it into the course folder.

Homework 3 due Thu 11/12 · Exam Wed 11/18, 6–8 pm

A practice exam with solutions is posted on Ed. Exam coverage: Lectures 1–16, focus 1–13.

Self-check

In-context learning means …

  1. fine-tuning on the prompt
  2. solving a new task from examples in the input, without gradient updates
  3. training from scratch
  4. retrieval augmentation

The model's weights don't change.

In PRODIGY's task graph, classification is turned into …

  1. regression
  2. graph generation
  3. link prediction between query data nodes and label nodes
  4. clustering

Logit = cosine similarity between label and query embeddings.

Neighbour matching pretraining needs …

  1. no labels — classes are sampled neighbourhoods
  2. paper categories
  3. KG relations
  4. human annotation

It's self-supervised.

RT's token is …

  1. a row
  2. a table
  3. a node embedding
  4. a cell: (value, column, table)

Cell-level tokenisation makes any schema fit one input space.

Conformal prediction guarantees …

  1. the most likely label is correct
  2. the prediction set contains the true label with probability ≥ 1 − α (under exchangeability)
  3. calibrated probabilities for each class
  4. the smallest possible sets

Coverage, not accuracy; CF-GNN then improves set size.

Flashcards (click to flip)

Prompt graph
Data graphs (subgraph per input) + task graph (data nodes ↔ label nodes).
PRODIGY pretraining
Neighbour matching + multi-task, in prompt-graph format; + attribute reconstruction.
RT's 3 innovations
Cell tokens · task as masked token prediction · relational attention masks.
RT context sampling
Hide seed value; include parents; subsample children; only past timestamps.
RT headline result
22M params, 1000× smaller than Gemma3-27B, +13% zero-shot AUROC.
Conformal quantile
\(\hat q\) = ⌈(n+1)(1−α)⌉/n quantile of calibration scores.

History & the bigger picture

  • 2020 — GPT-3 ("Language models are few-shot learners") makes ICL famous.
  • 2022–2023 — graph prompting: GPPT, All-in-One, PRODIGY; 2023 — CF-GNN brings conformal guarantees to graphs.
  • 2024–2025 — graph and relational foundation models: ULTRA (KGs, Lecture 15), Griffin, KumoRFM, Relational Transformer.
  • 1990s–2005 — conformal prediction (Vovk, Gammerman, Shafer) — an old statistical idea that became central once ML systems needed honest uncertainty.
Philosophy · what is "learning" if weights don't change?

ICL blurs the line between a learner and an inference engine: the "learning" happens in activations, not parameters. Philosophers of mind would recognise the debate between knowledge as stored representation and knowledge as a capacity to reason from given evidence. For structured enterprise data, the social question is concentration: a single pretrained relational model serving every company's database is enormous leverage — and an enormous dependency.

Classic SNA bridge

In this lectureClassic SNA counterpartWhat carried over, what changed
In-context learning from a few labelled examplesSeed-based coding and snowball labelling in qualitative network studies; semi-supervised label spreadingAnalysts have always labelled a few accounts by hand and extended by structure (label propagation, Lecture 20). PRODIGY makes the "extension rule" a learned model instead of neighbourhood averaging.
Prompt graph: data nodes, task nodes, label nodesTwo-mode network of actors × categories; the "affiliation to a label" trick of correspondence analysisTreating a label as a node in the same graph as the data is Breiger's duality once more: people and categories in one structure.
Conformal prediction setsConfidence intervals for network statistics by bootstrap or permutation (Snijders & Borgatti 1999)SNA had resampling intervals for whole-network statistics; conformal sets are per-node intervals for predictions. Both break when the sampling design is not what the method assumes.
Exchangeability assumptionRandom sampling of nodes vs snowball / time-ordered samplingA community-based or time-based split (how you would evaluate on X data) is not exchangeable. The social sampling design decides whether the guarantee holds.
Relational Transformer: schema tokensCodebooks and variable dictionaries in comparative survey researchPutting the column name next to the value is what a codebook does for a survey analyst. Transfer across schemas is transfer across codebooks.
Bridge idea

Report conformal sets for a claim like "between 4% and 9% of accounts in this hashtag are coordinated". Then redo the calibration under a time split and a community split and show how coverage degrades. Computational social science reviewers expect honest uncertainty; a paper that quantifies how the sampling design breaks the guarantee is more useful than one that reports the guarantee.

Go deeper in the SNA course. The twelve-unit course on social network analysis in this repository gives the classic side of this lecture in full, with labs and real-data analyses: Unit 10 · Causality, interference & graph ML (calibration and conformal prediction: what a model's confidence is worth after a shift); Unit 11 · Polarization, algorithms & misinformation (conformal prediction: honest uncertainty for a detector).

Connecting to your research

Running project. Section L14 · conformal sets of notebooks/project/retweet_thread.py applies this lecture to one synthetic X world with coordinated rings, the same graph across the whole course.

Research extension. experiments/conformal-shift (hypotheses written before running): when rings change tactics or are caught early, marginal coverage still reads 0.94–0.96 while coverage of bots drops to 0.13–0.23; recalibrating on 20 labelled bots restores it with honest, uninformative sets.

For SNA and neuro-symbolic work
  • Few-shot social labelling: annotating bots, propaganda accounts or stances is expensive. A PRODIGY-style prompt graph lets you classify accounts on a new platform/dataset from a handful of labelled examples — a natural Iranian-Twitter use case with scarce labels.
  • Prompt graphs are symbolic structures: examples, labels and queries are explicit nodes with typed edges — the "program" is a graph. That's a promising neuro-symbolic interface.
  • Uncertainty for social science: conformal sets give honest uncertainty for downstream claims ("between 4% and 9% of accounts are coordinated") — the kind of rigour reviewers in computational social science expect.

From the experiments: results and datasets

Generated by scripts/sync_guides.py from the experiments' committed results and the dataset catalogue; rerun it (make sync-guides) after an experiment changes.

conformal-shift

Question. Do conformal guarantees hold when bots change tactics, or when a platform changes country? experiment folder ↗

Verdicts (hypotheses written before running): H1 supported, H2 supported, H3 supported, H4 supported; H8 supported, H9 supported, H10 refuted, H11 supported.

Synthetic tactic shifts, α = 0.05. Marginal coverage of all accounts stays 0.94–0.96 while bot coverage collapses under co-amplification and early detection; recalibrating on 20 labelled bots restores it.
Real shift (gl.datasets.twitch): calibrated on England, tested on other countries. Worst class under Mondrian: DE 0.87, ES 0.89, FR 0.79, PTBR 0.91, RU 0.91. 200 labelled local accounts restore it.

Datasets for this session

From the repo's catalogue (gl.datasets; the full list with sources and licences is in data/README.md). Load one with gl.datasets.graph(name), temporal(name) or node_data(name).

namedatasetnodesground truthgood for
twitch-enTwitch users, England (mature content)7,126streams mature content (2)a heterophilous social task; also DE, ES, FR, PTBR, RU for shift
ellipticElliptic Bitcoin transactions203,769illicit / licit / unknown, 49 time stepsfraud detection under temporal shift

Frontier 2025–26: what changed since the slides

ICML 2026 workshopOnly prior-fitted models beat a tuned GNN — 3 of 9 foundation models beat well-tuned GNNs on ten GraphLand datasets, all three prior-fitted (G2T-FM, TAG, GraphPFN), at much higher inference cost; the rest "consistently underperform tuned GNNs, often by a wide margin". The same group built GraphPFN: independent replication needed.sources: arXiv:2509.21489 · arXiv:2606.24509 · arXiv:2409.14500
ICML 2026GraphPFN: in-context learning from a synthetic prior — A tabular prior-fitted network with neighbourhood attention, trained on millions of SBM, preferential-attachment and causal-model graphs, infers by a single forward pass. In-context learning on graphs (PRODIGY's goal) achieved by prior design rather than by pre-training on real graphs.sources: arXiv:2509.21489
ICLR 2026 oralsGraphGlue and MF-GIA — GraphGlue glues text-free domains into one Riemannian manifold and reports a logarithmic scaling law in the number of domains; MF-GIA aligns pre-vectorised features with gradient fingerprints for few-shot transfer on unseen domains without parameter updates. Two orals on the alignment problem the lecture calls the "format" challenge.sources: arXiv:2603.00618 · arXiv:2603.13434
ICLR 2026Relational Transformer, zero-shot — The 22M-parameter model of this lecture now has a venue and a comparison: 93% of supervised AUROC zero-shot vs 84% for a 27B LLM. Part of the "generality comes from priors, not scale" shift the Frontiers deck identifies.sources: arXiv:2510.06377
Atlas · xaiConformal and calibrated UQ with a homophily caveat — HeAD-CP (heterophily-aware conformal prediction) exists because DAPS diffuses conformal scores along edges assuming neighbours share uncertainty. GNNs tend to be under-confident (the opposite of CNNs); calibration (CaGCN, GATS) and conformal sets are both active.sources: arXiv:2607.25273
Open question to carryIs there a single universal pre-training task for graphs, the way next-token prediction is for text? Neighbour matching, masked cells and link prediction are candidates; GraphPFN's answer is that the prior over graphs matters more than the task.
Frontiers · where does a shared vocabulary come from? · only prior-fitted models beat a tuned GNN · guarantees that assume neighbours are alike

Words & phrases

TermSimple meaningPersianIn context
zero-shotadj.working on a new task or dataset with no task-specific training examplesبدون نمونه (صفر-نمونه‌ای)"beats a 27B-parameter LLM by 13% zero-shot AUROC"
exchangeabilityn.(statistics) the joint distribution doesn't change if you reorder the data pointsتعویض‌پذیری"assuming exchangeability between calibration and test points"
in-context learningn.solving a new task from examples given in the input, without updating weightsیادگیری درون‌متنی"PRODIGY does in-context learning on graphs"
promptn.the examples and query given to a model at inference timeپرامپت (درخواست)"a prompt graph with labelled examples"
coveragen.how often a prediction set contains the true answerپوشش"90% coverage, guaranteed"
quantilen.the value below which a given fraction of the data fallsچندک"the 90% quantile of calibration scores"

Go deeper

  • Next: Lecture 15 — foundation models for knowledge graphs: how ULTRA generalises to new relation types via double equivariance.
  • Survey: Liu et al. (2023), "Towards Graph Foundation Models: A Survey and Beyond".
  • Open question: is there a single "universal" pretraining task for graphs, the way next-token prediction is for text? Neighbour matching, masked cells, link prediction are candidates.