SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1906.06187 · 2019

NLProlog: Reasoning with Weak Unification for Question Answering in Natural Language

arXiv · PDF · Open in the Atlas

Code that ran

9 of 11 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 9 have no contract verdict; 0 failures of our instrument; 2 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/1906.06187.json · badge: /api/ran/1906.06187.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
leonweber/nlprolog canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
batched_weighted_sum Ran
ran on a synthesized input
leonweber/nlprolog/utils.py
code served (permissive licence) · get_code("6c8c3d4b27fb45b3")
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. 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

# Construct arguments for batched_weighted_sum
# The function expects:
# - weights: an iterable of numeric values
# - vecs: an iterable of numeric values or arrays
# - batch_size: an integer >= 1

# Create small test data
weights = [0.5, 0.3, 0.2, 0.1]  # 4 weights
vecs = [
    np.array([1.0, 2.0, 3.0, 4.0]),
    np.array([2.0, 3.0, 4.0, 5.0]),
    np.array([3.0, 4.0, 5.0, 6.0]),
    np.array([4.0, 5.0, 6.0, 7.0])
]  # 4 vectors of dimension 4

batch_size = 2

ARGS = {
    "weights": weights,
    "vecs": vecs,
    "batch_size": batch_size
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
build_tree Ran
ran on a synthesized input
leonweber/nlprolog/visualize_proof_tree.py
code served (permissive licence) · get_code("66053e173ef275e6")
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. 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 re

class Node:
    def __init__(self, id, parent, rule):
        self.id = id
        self.parent = parent
        self.rule = rule
        self.children = []

    def get_leftmost_active_child(self):
        for child in self.children:
            if not child.rule.is_done():
                return child
        return None

    def __str__(self):
        return str(self.rule)

    def __repr__(self):
        self.__str__()

class Rule:
    def __init__(self, head, body):
        self.head = head
        self.body = body
        self.status = [False for atom in body]

    def __str__(self):
        return self.head + ' :- ' + ','.join(self.body)

    @staticmethod
    def parse(rule):
        split = rule.split(':-')
        head = split[0].strip()
        body = split[1] if len(split) > 1 else ''
        body_atoms = re.findall('(.+?\\(.+?\\)\\s*)[,.]', body)
        body_atoms = [b.strip() for b in body_atoms]
        return Rule(head, body_atoms)

    @staticmethod
    def signature(atom):
        return atom.split('(')[0] + '/' + str(atom.count(',') + 1)

    def is_done(self):
        return False not in self.status

def build_tree(rules):
    split = rules.split('|')
    rules = split[::2]
    scores = split[1::2]
    root = Node(0, None, Rule.parse(rules[0]))
    edges = []
    nodes = [root]
    for i, rule in enumerate(rules[1:], start=1):
        rule = Rule.parse(rule)
        current_node = root
        next_node = current_node.get_leftmost_active_child()
        while next_node is not None:
            current_node = next_node
            next_node = next_node.get_leftmost_active_child()
        rule_node = Node(i, current_node, rule)
        current_node.children.append(rule_node)
        nodes.append(rule_node)
        edges.append((current_node.id, i, scores[i - 1]))
        current_node = rule_node
        while current_node != root and current_node.rule.is_done():
            for i, parent_body_elem in enumerate(current_node.parent.rule.body):
                if not current_node.parent.rule.status[i]:
                    sig1 = Rule.signature(parent_body_elem)
                    sig2 = Rule.signature(current_node.rule.head)
                    assert sig1 == sig2, f'sig1: {sig1}, sig2: {sig2}'
                    current_node.parent.rule.status[i] = True
                    break
            current_node = current_node.parent
    return (nodes, edges)

rules_str = "parent(X,Y) :- father(X,Y).|0.9|father(X,Y) :- male(X), child(Y,X).|0.8|male(john).|0.7|child(mary,john).|0.6"

ARGS = {
    "rules": rules_str
}
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 — a tuple output has no array shape of its own; none is 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
clean_text Ran
ran on a synthesized input
leonweber/nlprolog/preprocessing.py
code served (permissive licence) · get_code("5dc0130fdfd31748")
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 str. 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 re

def clean_text(text):
    text = text.lower()
    text = re.sub('\\s\\s*', ' ', text)
    text = re.sub('^\\s*,\\s*', '', text)
    text = re.sub('\\s*,\\s*$', '', text)
    return text

ARGS = {
    "text": "  HELLO  ,  WORLD  ,  "
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
cosine_similarity Ran
ran on a synthesized input
leonweber/nlprolog/model.py
code served (permissive licence) · get_code("e8c9a1f414af2fce")
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 2, dtype family float, shape (2, 2) 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

torch.manual_seed(0)

# Create two small tensors with shape (batch=2, dim=4)
x1 = torch.randn(2, 4)
x2 = torch.randn(2, 4)

ARGS = {
    "x1": x1,
    "x2": x2,
    "eps": 1e-08
}
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 2, dtype family float, shape (2, 2) — shape (2, 2) 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
get_linear Ran
ran on a synthesized input
leonweber/nlprolog/model.py
code served (permissive licence) · get_code("02f07f3773ca95ee")
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 2, dtype family float, shape (4, 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 numpy as np

def get_linear(shape):
    std = 1.0 / np.sqrt(shape[1])
    return np.random.uniform(-std, std, shape)

# The function takes a shape parameter which should be a tuple/list of integers
# representing the dimensions of a matrix. The function uses shape[0] and shape[1]
# to create a weight matrix initialized with uniform distribution.
# A typical use case would be initializing weights for a linear layer.

# Create a small shape tuple (4, 3) for testing
shape_value = (4, 3)

ARGS = {
    "shape": shape_value
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — 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 (4, 3) — shape (4, 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
luk Ran
ran on a synthesized input
leonweber/nlprolog/prolog.py
code served (permissive licence) · get_code("49c3bc68899deda4")
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 int, ndim 0, dtype family int, shape () 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

torch.manual_seed(0)

# The function luk(a, b) takes two parameters and returns max(0, a + b - 1)
# Both parameters should be numeric values that support addition

a = 5
b = 3

ARGS = {
    "a": a,
    "b": b
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () 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
make_title Ran
ran on a synthesized input
leonweber/nlprolog/preprocessing.py
code served (permissive licence) · get_code("1f0f6e29595f9263")
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 MockDoc. 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

class MockToken:
    def __init__(self, text):
        self.text = text

class MockDoc:
    def __init__(self, tokens):
        self.tokens = tokens
    
    def __iter__(self):
        return iter(self.tokens)

class MockNLP:
    def __call__(self, text):
        # Return a mock doc-like object
        words = text.split()
        tokens = [MockToken(w) for w in words]
        return MockDoc(tokens)

# Create mock objects
doc = MockDoc([
    MockToken("hello"),
    MockToken("world"),
    MockToken("python")
])

nlp = MockNLP()

ARGS = {
    "doc": doc,
    "nlp": nlp
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MockDoc — a MockDoc output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MockDoc 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
prod Ran
ran on a synthesized input
leonweber/nlprolog/prolog.py
code served (permissive licence) · get_code("f97356fe5f557abd")
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 2, dtype family float, shape (2, 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

torch.manual_seed(0)

# The prod function multiplies two arguments together
# We need to provide two values that support the * operator

a = torch.tensor([[1.0, 2.0, 3.0, 4.0],
                   [5.0, 6.0, 7.0, 8.0]])  # shape: (2, 4)

b = torch.tensor([[0.5, 0.5, 0.5, 0.5],
                   [0.5, 0.5, 0.5, 0.5]])  # shape: (2, 4)

ARGS = {
    'a': a,
    'b': b
}
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 2, dtype family float, shape (2, 4) — shape (2, 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
sim Ran
ran on a synthesized input
leonweber/nlprolog/model.py
code served (permissive licence) · get_code("a2e8d8ee2aa98330")
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 2, dtype family float, shape (2, 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

torch.manual_seed(0)

# Create two small tensors with distinct shapes for x and y
# x: (2, 4) - batch_size=2, embedding_dim=4
# y: (3, 4) - batch_size=3, embedding_dim=4
x = torch.randn(2, 4)
y = torch.randn(3, 4)

ARGS = {
    "x": x,
    "y": y,
}
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 2, dtype family float, shape (2, 3) — shape (2, 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
plot Not yet run
unverified (harvested, no recorded run)
leonweber/nlprolog/visualize_proof_tree.py
code served (permissive licence) · get_code("b6a8a382d767df09")
How it ran

no invocation recorded.

truncate Not yet run
unverified (harvested, no recorded run)
leonweber/nlprolog/preprocessing.py
code served (permissive licence) · get_code("0d57be32fa41e563")
How it ran

no invocation recorded.

Also present in other papers' code

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

Rule-based models are attractive for various tasks because they inherently lead to interpretable and explainable decisions and can easily incorporate prior knowledge. However, such systems are difficult to apply to problems involving natural language, due to its linguistic variability. In contrast, neural models can cope very well with ambiguity by learning distributed representations of words and their composition from data, but lead to models that are difficult to interpret. In this paper, we describe a model combining neural networks with logic programming in a novel manner for solving multi-hop reasoning tasks over natural language. Specifically, we propose to use a Prolog prover which we extend to utilize a similarity function over pretrained sentence encoders. We fine-tune the representations for the similarity function via backpropagation. This leads to a system that can apply rule-based reasoning to natural language, and induce domain-specific rules from training data. We evaluate the proposed system on two different question answering tasks, showing that it outperforms two baselines -- BIDAF (Seo et al., 2016a) and FAST QA (Weissenborn et al., 2017b) on a subset of the WikiHop corpus and achieves competitive results on the MedHop data set (Welbl et al., 2017).

For agents

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

get_harvested_code_for_paper("1906.06187")
get_code_for_paper("1906.06187")
have("1906.06187")

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

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

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

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

Connect an agent — have() is free.