SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1711.04071 · 2017

KBGAN: Adversarial Learning for Knowledge Graph Embeddings

arXiv · PDF · Open in the Atlas

Code that ran

7 of 7 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 5 have no contract verdict; 2 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/1711.04071.json · badge: /api/ran/1711.04071.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
cai-lw/KBGAN canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
WeidongLi-KG/KBGAN_PyTorch-v0.4.1 community (classifier label)
classifier basis not recorded on the link
1 ran · 0 no recorded run
cdhx/KBGAN_for_RotatE community (classifier label)
classifier basis not recorded on the link
1 ran · 0 no recorded run
FunctionStatusWhere it lives
get_bern_prob Ran
ran on a synthesized input
cai-lw/KBGAN/corrupter.py
code served (permissive licence) · get_code("db62f010de292105")
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 Tensor, ndim 1, dtype family float, shape (3,) 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
from collections import defaultdict

torch.manual_seed(0)

# Construct minimal valid arguments for get_bern_prob
# The function expects:
# - data: tuple of (src, rel, dst) tensors
# - n_ent: int, number of entities
# - n_rel: int, number of relations

# Create small tensors for a knowledge graph with a few triples
src = torch.tensor([0, 1, 0, 2, 1, 2], dtype=torch.long)
rel = torch.tensor([0, 0, 1, 1, 2, 2], dtype=torch.long)
dst = torch.tensor([1, 2, 0, 1, 0, 2], dtype=torch.long)

data = (src, rel, dst)
n_ent = 3
n_rel = 3

ARGS = {
    "data": data,
    "n_ent": n_ent,
    "n_rel": n_rel,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (3,) — shape (3,) 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
graph_size Ran
ran on a synthesized input
cai-lw/KBGAN/read_data.py
code served (permissive licence) · get_code("833096aa3cb77f0b")
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 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 torch

class KBIndex:
    def __init__(self, num_entities, num_relations):
        self.ent_id = list(range(num_entities))
        self.rel_id = list(range(num_relations))

kb_index = KBIndex(num_entities=5, num_relations=3)

ARGS = {
    "kb_index": kb_index
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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 int — 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
heads_tails Ran
ran on a synthesized input
cai-lw/KBGAN/data_utils.py
code served (permissive licence) · get_code("36c5046a9d1fc4c8")
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
from collections import defaultdict

torch.manual_seed(0)

# The function expects:
# - n_ent: int (number of entities)
# - train_data: tuple of (src, rel, dst) lists
# - valid_data: optional tuple of (src, rel, dst) lists
# - test_data: optional tuple of (src, rel, dst) lists

n_ent = 5

# Create small train data: lists of entity/relation indices
train_src = [0, 1, 2]
train_rel = [0, 1, 0]
train_dst = [1, 2, 3]
train_data = (train_src, train_rel, train_dst)

# Create small valid data
valid_src = [0, 2]
valid_rel = [1, 0]
valid_dst = [3, 4]
valid_data = (valid_src, valid_rel, valid_dst)

# Create small test data
test_src = [1, 3]
test_rel = [0, 1]
test_dst = [4, 0]
test_data = (test_src, test_rel, test_dst)

ARGS = {
    "n_ent": n_ent,
    "train_data": train_data,
    "valid_data": valid_data,
    "test_data": test_data
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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
mrr_mr_hitk Ran
ran on a synthesized input
cai-lw/KBGAN/metrics.py
code served (permissive licence) · get_code("718b2a832f1896ce")
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 as t

t.manual_seed(0)

# Create small scores tensor and target index
# scores should be a 1D tensor of scores for ranking
# target is an integer index we're looking for
scores = t.tensor([3.2, 1.5, 4.1, 2.8], dtype=t.float32)
target = t.tensor(2)  # Looking for index 2

ARGS = {
    "scores": scores,
    "target": target,
    "k": 10
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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
mrr_mr_hitk Ran
ran; our contract draft was wrong, not the code
WeidongLi-KG/KBGAN_PyTorch-v0.4.1/metrics.py
code served (permissive licence) · get_code("6f77d9ef5bdda39c")
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. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 as t

t.manual_seed(0)

# The function expects:
# - scores: a tensor of scores that can be sorted
# - target: a tensor containing a target index
# - k: an integer (default 10)

# Looking at the function body:
# - t.sort(scores) is called, so scores should be a 1D tensor
# - target is compared with sorted_idx (==), so target should be a scalar tensor
# - target.cuda() is called, so target must support .cuda()
# - t.nonzero(find_target)[0, 0] is accessed, so find_target must have at least one True value
# - The result is converted to int with .item()

# Create a small scores tensor (1D)
scores = t.tensor([0.5, 0.2, 0.9, 0.1], dtype=t.float32)

# Create a target that exists in the scores (index 2, which has value 0.9)
target = t.tensor(2, dtype=t.long)

# k parameter
k = 10

ARGS = {
    "scores": scores,
    "target": target,
    "k": k
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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
mrr_mr_hitk Ran
ran; our contract draft was wrong, not the code
cdhx/KBGAN_for_RotatE/metrics.py
code served (permissive licence) · get_code("dd4ffbbba9e475b7")
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 as t

t.manual_seed(0)

# scores: a tensor of scores that will be sorted
# target: an index (scalar) indicating which position should be found
scores = t.tensor([0.5, 0.8, 0.3, 0.9], dtype=t.float32)
target = t.tensor(2, dtype=t.long)

# k: threshold for hit@k metric
k = 10

ARGS = {
    "scores": scores,
    "target": target,
    "k": k
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
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_data Ran
ran on a synthesized input
cai-lw/KBGAN/read_data.py
code served (permissive licence) · get_code("59872d7c9c0b328a")
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 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
import os

class KBIndex:
    def __init__(self):
        self.ent_id = {
            'entity_0': 0,
            'entity_1': 1,
            'entity_2': 2,
            'entity_3': 3,
        }
        self.rel_id = {
            'relation_0': 0,
            'relation_1': 1,
            'relation_2': 2,
        }

# Create a temporary file with triple data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write('entity_0\trelation_0\tentity_1\n')
temp_file.write('entity_1\trelation_1\tentity_2\n')
temp_file.write('entity_2\trelation_2\tentity_3\n')
temp_file.close()

kb_index = KBIndex()

ARGS = {
    'filename': temp_file.name,
    'kb_index': kb_index,
}
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 tuple, ndim 2, dtype family int — 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

Also present in other papers' code

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

We introduce KBGAN, an adversarial learning framework to improve the performances of a wide range of existing knowledge graph embedding models. Because knowledge graphs typically only contain positive facts, sampling useful negative training examples is a non-trivial task. Replacing the head or tail entity of a fact with a uniformly randomly selected entity is a conventional method for generating negative facts, but the majority of the generated negative facts can be easily discriminated from positive facts, and will contribute little towards the training. Inspired by generative adversarial networks (GANs), we use one knowledge graph embedding model as a negative sample generator to assist the training of our desired model, which acts as the discriminator in GANs. This framework is independent of the concrete form of generator and discriminator, and therefore can utilize a wide variety of knowledge graph embedding models as its building blocks. In experiments, we adversarially train two translation-based models, TransE and TransD, each with assistance from one of the two probability-based models, DistMult and ComplEx. We evaluate the performances of KBGAN on the link prediction task, using three knowledge base completion datasets: FB15k-237, WN18 and WN18RR. Experimental results show that adversarial training substantially improves the performances of target embedding models under various settings.

For agents

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

get_harvested_code_for_paper("1711.04071")
get_code_for_paper("1711.04071")
have("1711.04071")

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

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

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

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

Connect an agent — have() is free.