SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2208.07638 · 2022

Mask and Reason: Pre-Training Knowledge Graph Transformers for Complex Logical Queries

arXiv · PDF · Open in the Atlas

Code that ran

7 of 10 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; 0 honoured the contract we drafted, 0 violated it and 7 have no contract verdict; 0 failures of our instrument; 3 no recorded run), measured 2026-11-23; 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/2208.07638.json · badge: /api/ran/2208.07638.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
thudm/kgtransformer canonical (classifier label)
classifier basis not recorded on the link
7 ran · 3 no recorded run
FunctionStatusWhere it lives
get_adj_np Ran
ran on a synthesized input
thudm/kgtransformer/graph_util.py
code served (permissive licence) · get_code("116134e273b34b63")
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, through the batch API) and returned csr_matrix. The image it ran in was not recorded. If your copy returns the same type 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

torch.manual_seed(0)

# edge_index: a 2D tensor where edge_index[0] contains source node indices
# and edge_index[1] contains target node indices
edge_index = torch.tensor([
    [0, 1, 2, 0],  # source nodes
    [1, 2, 0, 3]   # target nodes
], dtype=torch.long)

# edge_attr: edge weights/attributes as a 1D tensor
edge_attr = torch.tensor([0.5, 1.0, 1.5, 2.0], dtype=torch.float32)

# num_nodes: total number of nodes in the graph
num_nodes = 4

ARGS = {
    "edge_index": edge_index,
    "edge_attr": edge_attr,
    "num_nodes": num_nodes
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type csr_matrix — a csr_matrix output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a csr_matrix output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
get_directed_lap_matrix_np Ran
ran on a synthesized input
thudm/kgtransformer/graph_util.py
code served (permissive licence) · get_code("314fee3dec4f4876")
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, through the batch API) and returned csr_matrix. The image it ran in was not recorded. If your copy returns the same type 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 scipy.sparse as sp

torch.manual_seed(0)

# Create a small edge_index tensor
# edge_index shape: [2, num_edges]
# Let's create 5 edges between 4 nodes
edge_index = torch.tensor([
    [0, 1, 2, 3, 1],  # source nodes
    [1, 2, 3, 0, 0]   # target nodes
], dtype=torch.long)

num_nodes = 4

ARGS = {
    "edge_index": edge_index,
    "num_nodes": num_nodes
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type csr_matrix — a csr_matrix output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a csr_matrix output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
ladies_sampler_np Ran
ran on a synthesized input
thudm/kgtransformer/sampler.py
code served (permissive licence) · get_code("0f476445cb4e78aa")
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, through the batch API) and returned ndarray, ndim 1, dtype family int, shape (7,) 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 numpy as np
from scipy import sparse

np.random.seed(0)

# Create a small sparse Laplacian matrix
# The function accesses lap_matrix[node_list, :] and uses .multiply() method
# which indicates scipy sparse matrix
num_nodes = 10
lap_matrix = sparse.csr_matrix(
    np.array([
        [4, -1, -1, -1, 0, 0, 0, 0, 0, 0],
        [-1, 3, -1, 0, -1, 0, 0, 0, 0, 0],
        [-1, -1, 3, 0, 0, -1, 0, 0, 0, 0],
        [-1, 0, 0, 3, -1, 0, -1, 0, 0, 0],
        [0, -1, 0, -1, 3, 0, 0, -1, 0, 0],
        [0, 0, -1, 0, 0, 2, 0, 0, -1, 0],
        [0, 0, 0, -1, 0, 0, 2, 0, 0, -1],
        [0, 0, 0, 0, -1, 0, 0, 2, 0, -1],
        [0, 0, 0, 0, 0, -1, 0, 0, 2, -1],
        [0, 0, 0, 0, 0, 0, -1, -1, -1, 3],
    ], dtype=np.float32)
)

# Initial node list (starting from a few nodes)
node_list = np.array([0, 1], dtype=np.int64)

# Number of nodes to sample per layer
samp_num_list = [3, 2]

ARGS = {
    "node_list": node_list,
    "samp_num_list": samp_num_list,
    "num_nodes": num_nodes,
    "lap_matrix": lap_matrix,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family int, shape (7,) — shape (7,) 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
loss_label_smoothing_multi_ans Ran
ran on a synthesized input
thudm/kgtransformer/metric.py
code served (permissive licence) · get_code("70f267c347fddaaa")
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, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 torch.nn as nn

torch.manual_seed(0)

# Mock deter_util module since it's imported in the function
class MockDeterUtil:
    @staticmethod
    def deter_scatter_add_(indices, src, dst):
        """Mock scatter_add_ that accumulates src values into dst at positions indices"""
        for i, idx in enumerate(indices):
            dst[idx] += src[i]

import sys
from types import ModuleType
deter_util = ModuleType('deter_util')
deter_util.deter_scatter_add_ = MockDeterUtil.deter_scatter_add_
sys.modules['deter_util'] = deter_util

# Create test tensors
num_nodes = 5
num_queries = 2
num_answers = 4
score_dim = 4

# score: shape (num_nodes, num_answers) - log probabilities
score = torch.randn(num_nodes, num_answers, dtype=torch.float32)

# query: indices of query nodes, shape (num_queries,)
query = torch.tensor([0, 1], dtype=torch.long)

# ans: answer indices for each query, shape (num_queries,)
ans = torch.tensor([0, 2], dtype=torch.long)

# posi_x: indices into nodes for positive examples, shape (num_positive,)
# Must have len(posi_x) >= len(query)
posi_x = torch.tensor([0, 1, 2], dtype=torch.long)

# posi_ans: answer indices for positive examples, shape (num_positive,)
posi_ans = torch.tensor([1, 0, 3], dtype=torch.long)

# smoothing: label smoothing parameter, float in [0, 1]
smoothing = 0.1

# query_w: optional weights for queries, shape (num_queries,)
query_w = torch.tensor([1.0, 1.0], dtype=torch.float32)

ARGS = {
    'score': score,
    'query': query,
    'ans': ans,
    'posi_x': posi_x,
    'posi_ans': posi_ans,
    'smoothing': smoothing,
    'query_w': query_w,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
deter_util, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
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
read_pkl Ran
ran on a synthesized input
thudm/kgtransformer/tasks/base.py
code served (permissive licence) · get_code("8b0d003d9e5f8311")
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, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type 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 pickle
import tempfile
from pathlib import Path

# Create a temporary pickle file with some test data
test_data = {"key": "value", "number": 42, "list": [1, 2, 3]}

with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.pkl') as f:
    temp_path = Path(f.name)
    pickle.dump(test_data, f)

ARGS = {
    "path": temp_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
read_txt_triples Ran
ran on a synthesized input
thudm/kgtransformer/tasks/base.py
code served (permissive licence) · get_code("98b43295d1265f8f")
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, through the batch API) and returned list, ndim 2, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 tempfile
from pathlib import Path

# Create a temporary file with tab-separated integer triples
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("1\t2\t3\n")
temp_file.write("4\t5\t6\n")
temp_file.write("7\t8\t9\n")
temp_file.close()

ARGS = {
    "path": Path(temp_file.name)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family int — a list output has no array shape of its own; none is stated
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
row_normalize_np Ran
ran on a synthesized input
thudm/kgtransformer/graph_util.py
code served (permissive licence) · get_code("b7a726a8d5be145b")
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, through the batch API) and returned csr_matrix. The image it ran in was not recorded. If your copy returns the same type 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 numpy as np
import scipy.sparse as sp

# Create a small sparse matrix for testing
# 4 rows x 3 columns with some non-zero values
data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
row = np.array([0, 0, 1, 2, 3])
col = np.array([0, 1, 2, 0, 1])
mx = sp.csr_matrix((data, (row, col)), shape=(4, 3))

ARGS = {
    'mx': mx
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type csr_matrix — a csr_matrix output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a csr_matrix output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
det_softmax Not yet run
unverified (harvested, no recorded run)
thudm/kgtransformer/deter_util.py
code served (permissive licence) · get_code("b5dc748a91e5e704")
How it ran

no invocation recorded.

deter_scatter_add_ Not yet run
unverified (harvested, no recorded run)
thudm/kgtransformer/deter_util.py
code served (permissive licence) · get_code("acf50f7fc9d5fea7")
How it ran

no invocation recorded.

loss_cross_entropy_multi_ans Not yet run
unverified (harvested, no recorded run)
thudm/kgtransformer/metric.py
code served (permissive licence) · get_code("dd1cd67c9cfc143f")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 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 10 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-23.

Repositories linked to this paper

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

Abstract

Knowledge graph (KG) embeddings have been a mainstream approach for reasoning over incomplete KGs. However, limited by their inherently shallow and static architectures, they can hardly deal with the rising focus on complex logical queries, which comprise logical operators, imputed edges, multiple source entities, and unknown intermediate entities. In this work, we present the Knowledge Graph Transformer (kgTransformer) with masked pre-training and fine-tuning strategies. We design a KG triple transformation method to enable Transformer to handle KGs, which is further strengthened by the Mixture-of-Experts (MoE) sparse activation. We then formulate the complex logical queries as masked prediction and introduce a two-stage masked pre-training strategy to improve transferability and generalizability. Extensive experiments on two benchmarks demonstrate that kgTransformer can consistently outperform both KG embedding-based baselines and advanced encoders on nine in-domain and out-of-domain reasoning tasks. Additionally, kgTransformer can reason with explainability via providing the full reasoning paths to interpret given answers.

For agents

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

get_harvested_code_for_paper("2208.07638")
get_code_for_paper("2208.07638")
have("2208.07638")

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

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

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

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

Connect an agent — have() is free.