SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2210.06722 · NeurIPS · 2022

Few-shot Relational Reasoning via Connection Subgraph Pretraining

Hongyu Ren, Jure Leskovec, Qian Huang

arXiv · PDF · Open in the Atlas

Code that ran

1 of 1 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2210.06722.json · badge: /api/ran/2210.06722.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
snap-stanford/csr canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
load_embed Ran
ran, honoured the contract we drafted
snap-stanford/csr/models.py
code served (permissive licence) · get_code("be97d6e924794bab")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned ndarray, ndim 2, dtype family float, shape (3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
import pickle
import json
import tempfile
import os

torch.manual_seed(0)

# Create temporary directory structure
tmpdir = tempfile.mkdtemp()
datadir = os.path.join(tmpdir, 'data')
embdir = os.path.join(tmpdir, 'emb')
os.makedirs(datadir)
os.makedirs(embdir)

# Create entity2id and relation2id files
entity2id = {'ent1': 0, 'ent2': 1, 'ent3': 2, 'OOV': 3}
relation2id = {'rel1': 0, 'rel2': 1, 'OOV': 2}

with open(os.path.join(datadir, 'entity2id.json'), 'w') as f:
    json.dump(entity2id, f)

with open(os.path.join(datadir, 'relation2id.json'), 'w') as f:
    json.dump(relation2id, f)

# Create inductive versions
with open(os.path.join(datadir, 'entity2id_inductive.json'), 'w') as f:
    json.dump(entity2id, f)

with open(os.path.join(datadir, 'relation2id_inductive.json'), 'w') as f:
    json.dump(relation2id, f)

inductive_nodes = {'ent1': True}
with open(os.path.join(datadir, 'inductive_nodes.json'), 'w') as f:
    json.dump(inductive_nodes, f)

# Create embedding checkpoint directory
emb_prefix_dir = os.path.join(embdir, 'NELL-fs')
os.makedirs(emb_prefix_dir)

# Create pickle files for entity and relation mappings
theirs_entity2id = {'ent1': 0, 'ent2': 1, 'ent3': 2}
theirs_relation2id = {'rel1': 0, 'rel2': 1}

with open(os.path.join(emb_prefix_dir, 'ent2id.pkl'), 'wb') as f:
    pickle.dump(theirs_entity2id, f)

with open(os.path.join(emb_prefix_dir, 'rel2id.pkl'), 'wb') as f:
    pickle.dump(theirs_relation2id, f)

# Create checkpoint with embeddings
embed_dim = 4
entity_embed = torch.randn(3, embed_dim)
relation_embed = torch.randn(2, embed_dim)

checkpoint = {
    'model_state_dict': {
        'entity_embedding.embedding': entity_embed,
        'relation_embedding.embedding': relation_embed
    }
}

torch.save(checkpoint, os.path.join(emb_prefix_dir, 'complex_checkpoint'))
torch.save(checkpoint, os.path.join(emb_prefix_dir, 'checkpoint'))

ARGS = {
    'datapath': datadir,
    'emb_path': embdir,
    'dataset': 'NELL',
    'embed_model': 'ComplEx',
    'use_ours': True,
    'load_ent': False,
    'bidir': False,
    'inductive': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (3, 4) — shape (3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 1 samples lifted from this paper's linked repositories, 1 carry a function identity and 0 do not. Of the 1 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Few-shot knowledge graph (KG) completion task aims to perform inductive reasoning over the KG: given only a few support triplets of a new relation (e.g., (chop, , kitchen), (read, , library)), the goal is to predict the query triplets of the same unseen relation , e.g., (sleep, , ?). Current approaches cast the problem in a meta-learning framework, where the model needs to be first jointly trained over many training few-shot tasks, each being defined by its own relation, so that learning/prediction on the target few-shot task can be effective. However, in real-world KGs, curating many training tasks is a challenging ad hoc process. Here we propose Connection Subgraph Reasoner (CSR), which can make predictions for the target few-shot task directly without the need for pre-training on the human curated set of training tasks. The key to CSR is that we explicitly model a shared connection subgraph between support and query triplets, as inspired by the principle of eliminative induction. To adapt to specific KG, we design a corresponding self-supervised pretraining scheme with the objective of reconstructing automatically sampled connection subgraphs. Our pretrained model can then be directly applied to target few-shot tasks on without the need for training few-shot tasks. Extensive experiments on real KGs, including NELL, FB15K-237, and ConceptNet, demonstrate the effectiveness of our framework: we show that even a learning-free implementation of CSR can already perform competitively to existing methods on target few-shot tasks; with pretraining, CSR can achieve significant gains of up to 52% on the more challenging inductive few-shot tasks where the entities are also unseen during (pre)training. * indicates equal contribution. 36th Conference on Neural Information Processing Systems (NeurIPS 2022).

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2210.06722")
get_code_for_paper("2210.06722")
have("2210.06722")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2210.06722.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2210.06722.svg)](https://syntology.ai/paper/2210.06722)

Connect an agent — have() is free.