SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1909.06639 · 2019

Tree Transformer: Integrating Tree Structures into Self-Attention

arXiv · PDF · Open in the Atlas

Code that ran

9 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, 1 violated it and 6 have no contract verdict; 2 failures of our instrument; 1 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/1909.06639.json · badge: /api/ran/1909.06639.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
itzpankajpanwar/Tree-transform community (classifier label)
classifier basis not recorded on the link
9 ran · 1 no recorded run
FunctionStatusWhere it lives
attention Ran
ran on a synthesized input
itzpankajpanwar/Tree-transform/attention.py
code served (permissive licence) · get_code("30ac4034117b7c76")
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. 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 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
import torch.nn.functional as F
import math
import numpy as np

torch.manual_seed(0)

# Build tensors with distinct dimensions for probing
batch_size = 2
seq_len = 3
d_k = 4

query = torch.randn(batch_size, seq_len, d_k)
key = torch.randn(batch_size, seq_len, d_k)
value = torch.randn(batch_size, seq_len, d_k)

# Create a mask tensor: boolean tensor of shape (batch_size, seq_len, seq_len)
# This will be used in masked_fill operation
mask = torch.zeros(batch_size, seq_len, seq_len, dtype=torch.bool)
mask[0, 2, :] = True  # Mask out last token in first batch

# Create a dropout layer
dropout = nn.Dropout(p=0.1)

# Create group_prob: shape (batch_size, seq_len)
group_prob = torch.ones(batch_size, seq_len)

ARGS = {
    "query": query,
    "key": key,
    "value": value,
    "mask": mask,
    "dropout": dropout,
    "group_prob": group_prob,
    "no_cuda": True
}
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 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
itzpankajpanwar/Tree-transform/parse.py
code served (permissive licence) · get_code("a940e63fb38eb615")
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 set. 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

# Create a small break_probs array
# The function indexes it as break_probs[layer, start:end]
# So we need a 2D array with enough layers and positions
break_probs = np.array([
    [0.9, 0.85, 0.75, 0.88, 0.92],  # layer 0
    [0.5, 0.6, 0.4, 0.7, 0.55],     # layer 1
    [0.3, 0.2, 0.15, 0.25, 0.35],   # layer 2
    [0.1, 0.05, 0.12, 0.08, 0.09],  # layer 3
])

layer = 1
start = 0
end = 4
threshold = 0.8

ARGS = {
    "break_probs": break_probs,
    "layer": layer,
    "start": start,
    "end": end,
    "threshold": threshold,
}
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 set — a set output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a set 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
cc Ran
ran on a synthesized input
itzpankajpanwar/Tree-transform/utils.py
code served (permissive licence) · get_code("4fdb28c59aa02f3c")
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. 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, 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
import torch

torch.manual_seed(0)

# The function cc takes an array and converts it to a torch tensor
# If no_cuda is False, it tries to move to cuda (which will fail in CPU-only environment)
# If no_cuda is True, it stays on CPU

# Create a simple numpy array
arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=np.float32)

ARGS = {
    "arr": arr,
    "no_cuda": True
}
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 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
clones Ran
ran; our contract draft was wrong, not the code
itzpankajpanwar/Tree-transform/modules.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from DSE-MSU/R-transformer, is pointer only (licence: NONE) · get_code("b1bec2c4b1c9b491")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from DSE-MSU/R-transformer, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

dump_tree Ran
ran on a synthesized input
itzpankajpanwar/Tree-transform/parse.py
code served (permissive licence) · get_code("60427abde198d7f8")
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 Tree. 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
from nltk import Tree

# Set random seed for reproducibility
np.random.seed(0)

# Create small test data
# break_probs: 2D array of shape (num_layers, sequence_length)
# The function indexes it as break_probs[layer, start:end]
break_probs = np.random.uniform(0.5, 0.95, size=(5, 8))

# layer: integer index into first dimension of break_probs
layer = 3

# start: integer index
start = 0

# end: integer index, should be > start for meaningful execution
end = 5

# text: list or array-like that can be indexed by integers
# The function accesses text[idx] for idx in range(start, end)
text = ['hello', 'world', 'foo', 'bar', 'baz', 'test', 'data', 'sample']

# threshold: float parameter with default 0.8
threshold = 0.8

ARGS = {
    'break_probs': break_probs,
    'layer': layer,
    'start': start,
    'end': end,
    'text': text,
    'threshold': threshold
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
nltk, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tree — a Tree 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
make_save_dir Ran
ran on a synthesized input
itzpankajpanwar/Tree-transform/utils.py
code served (permissive licence) · get_code("215c1b4a8625c6f5")
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 os
import tempfile

# Create a temporary directory path for testing
temp_dir = tempfile.mkdtemp(prefix="test_save_dir_")

# Clean up the temp directory so we can test the creation logic
os.rmdir(temp_dir)

ARGS = {
    "save_dir": temp_dir
}
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
read_json Ran
ran; our contract draft was wrong, not the code
itzpankajpanwar/Tree-transform/utils.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from yaushian/Unparalleled-Text-Summarization-using-GAN, is pointer only (licence: NONE) · get_code("c204acb9ea9e761d")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from yaushian/Unparalleled-Text-Summarization-using-GAN, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

subsequent_mask Ran
ran, violated the contract we drafted
itzpankajpanwar/Tree-transform/modules.py
code served (permissive licence) · get_code("79e53d4ea458987d")
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 3, dtype family float, shape (1, 4, 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 numpy as np
import torch

torch.manual_seed(0)

# The function takes a single parameter 'size' which is used to create
# a numpy array of shape (1, size, size) and then converted to a torch tensor.
# We need to provide a small integer value for size.

size = 4

ARGS = {
    "size": size
}
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 Tensor, ndim 3, dtype family float, shape (1, 4, 4) — shape (1, 4, 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
word2tree Ran
ran on a synthesized input
itzpankajpanwar/Tree-transform/parse.py
code served (permissive licence) · get_code("7832e4cac7a9683c")
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 Tree. 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 nltk
from nltk import Tree

torch.manual_seed(0)

ARGS = {
    'start': 0,
    'end': 3,
    'text': ['hello', 'world', 'test', 'example']
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
nltk, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tree — a Tree output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Tree output the recorded ndim 2 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_std_opt Not yet run
unverified (harvested, no recorded run)
itzpankajpanwar/Tree-transform/modules.py
code served (permissive licence) · get_code("009d3f80a8ce3436")
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, 3 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 2 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.

FunctionAlso present inEarliest-datedOthers named
clones 79 other papers
16 dated earlier, 63 later · 11 only as an assembly brick
1411.4555 (2014-11)
Show and Tell: A Neural Image Caption Generator
1612.00563 (2016-12)
Self-critical Sequence Training for Image Captioning
1706.03762 (2017-06)
Attention Is All You Need
and 76 more not named here
subsequent_mask 21 other papers
6 dated earlier, 15 later
1411.4555 (2014-11)
Show and Tell: A Neural Image Caption Generator
1612.00563 (2016-12)
Self-critical Sequence Training for Image Captioning
1707.07998 (2017-07)
Bottom-Up and Top-Down Attention for Image Captioning and Visual Question Answering
and 18 more not named here
read_json 1 other paper
1 dated earlier
1810.02851 (2018-10)
Learning to Encode Text as Human-Readable Summaries using Generative Adversarial Networks

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

Pre-training Transformer from large-scale raw texts and fine-tuning on the desired task have achieved state-of-the-art results on diverse NLP tasks. However, it is unclear what the learned attention captures. The attention computed by attention heads seems not to match human intuitions about hierarchical structures. This paper proposes Tree Transformer, which adds an extra constraint to attention heads of the bidirectional Transformer encoder in order to encourage the attention heads to follow tree structures. The tree structures can be automatically induced from raw texts by our proposed "Constituent Attention" module, which is simply implemented by self-attention between two adjacent words. With the same training procedure identical to BERT, the experiments demonstrate the effectiveness of Tree Transformer in terms of inducing tree structures, better language modeling, and further learning more explainable attention scores.

For agents

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

get_harvested_code_for_paper("1909.06639")
get_code_for_paper("1909.06639")
have("1909.06639")

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

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

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

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

Connect an agent — have() is free.