SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2010.01057 · EMNLP · 2020

LUKE: Deep Contextualized Entity Representations with Entity-aware Self-attention

Ikuya Yamada, Yuji Matsumoto, Hiroyuki Shindo, Hideaki Takeda

arXiv · PDF · Open in the Atlas

Code that ran

3 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 7 no recorded run), measured 2026-11-21; 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/2010.01057.json · badge: /api/ran/2010.01057.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
studio-ousia/luke marked official in Papers with Code
Papers with Code archive
3 ran · 5 no recorded run
huggingface/transformers community
Papers with Code archive
0 ran · 1 no recorded run
JiachengLi1995/UCTopic community
Papers with Code archive
0 ran · 1 no recorded run
FunctionStatusWhere it lives
EntityAwareAttention Ran
ran on a synthesized input
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("fb78ccc0f682352e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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 torch
import torch.nn as nn
from transformers.models.bert.modeling_bert import BertConfig

# Create a minimal BertConfig
config = BertConfig(
    hidden_size=8,
    num_attention_heads=2,
    attention_probs_dropout_prob=0.1,
    hidden_dropout_prob=0.1,
    layer_norm_eps=1e-12
)

INIT_ARGS = {
    'config': config
}

# Create input tensors with distinct dimensions
batch_size = 2
word_seq_len = 5
entity_seq_len = 3
hidden_size = config.hidden_size

word_hidden_states = torch.randn(batch_size, word_seq_len, hidden_size)
entity_hidden_states = torch.randn(batch_size, entity_seq_len, hidden_size)

# Create attention mask
# The mask should be broadcastable to [batch_size, num_heads, total_seq_len, total_seq_len]
# where total_seq_len = word_seq_len + entity_seq_len
total_seq_len = word_seq_len + entity_seq_len
attention_mask = torch.zeros(batch_size, 1, total_seq_len, total_seq_len)

ARGS = {
    'word_hidden_states': word_hidden_states,
    'entity_hidden_states': entity_hidden_states,
    'attention_mask': attention_mask
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
EntityEmbeddings Ran
ran on a synthesized input · constructed an object; no result was computed
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("8d7fce1bd60c4918")
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 an instance of its own class, EntityEmbeddings: the run constructed the object and did not call it, so no result was computed. 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
from torch import nn
from transformers.models.bert.modeling_bert import BertConfig, BertEmbeddings, BertIntermediate, BertLayer, BertOutput, BertPooler, BertSelfOutput

torch.manual_seed(0)

class LukeConfig(BertConfig):

    def __init__(self, vocab_size: int, entity_vocab_size: int, bert_model_name: str, entity_emb_size: int=None, cls_entity_prediction: bool=False, **kwargs):
        super().__init__(vocab_size, **kwargs)
        self.entity_vocab_size = entity_vocab_size
        self.bert_model_name = bert_model_name
        if entity_emb_size is None:
            self.entity_emb_size = self.hidden_size
        else:
            self.entity_emb_size = entity_emb_size
        self.cls_entity_prediction = cls_entity_prediction

    def __repr__(self):
        return '{} {}'.format(self.__class__.__name__, self.to_json_string(use_diff=False))

class EntityEmbeddings(nn.Module):

    def __init__(self, config: LukeConfig):
        super().__init__()
        self.config = config
        self.entity_embeddings = nn.Embedding(config.entity_vocab_size, config.entity_emb_size, padding_idx=0)
        if config.entity_emb_size != config.hidden_size:
            self.entity_embedding_dense = nn.Linear(config.entity_emb_size, config.hidden_size, bias=False)
        self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
        self.token_type_embeddings = nn.Embedding(config.type_vocab_size, config.hidden_size)
        self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
        self.dropout = nn.Dropout(config.hidden_dropout_prob)

    def forward(self, entity_ids: torch.LongTensor, position_ids: torch.LongTensor, token_type_ids: torch.LongTensor=None):
        if token_type_ids is None:
            token_type_ids = torch.zeros_like(entity_ids)
        entity_embeddings = self.entity_embeddings(entity_ids)
        if self.config.entity_emb_size != self.config.hidden_size:
            entity_embeddings = self.entity_embedding_dense(entity_embeddings)
        position_embeddings = self.position_embeddings(position_ids.clamp(min=0))
        position_embedding_mask = (position_ids != -1).type_as(position_embeddings).unsqueeze(-1)
        position_embeddings = position_embeddings * position_embedding_mask
        position_embeddings = torch.sum(position_embeddings, dim=-2)
        position_embeddings = position_embeddings / position_embedding_mask.sum(dim=-2).clamp(min=1e-07)
        token_type_embeddings = self.token_type_embeddings(token_type_ids)
        embeddings = entity_embeddings + position_embeddings + token_type_embeddings
        embeddings = self.LayerNorm(embeddings)
        embeddings = self.dropout(embeddings)
        return embeddings


config = LukeConfig(
    vocab_size=100,
    entity_vocab_size=50,
    bert_model_name="bert-base-uncased",
    entity_emb_size=4,
    hidden_size=4,
    max_position_embeddings=128,
    type_vocab_size=2,
    layer_norm_eps=1e-12,
    hidden_dropout_prob=0.1
)

entity_embeddings_module = EntityEmbeddings(config)

batch_size = 2
seq_length = 3

entity_ids = torch.randint(1, 50, (batch_size, seq_length), dtype=torch.long)
position_ids = torch.randint(0, 128, (batch_size, seq_length, 2), dtype=torch.long)
token_type_ids = torch.randint(0, 2, (batch_size, seq_length), dtype=torch.long)

ARGS = {
    "config": config,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EntityEmbeddings — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a EntityEmbeddings 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
LukeConfig Ran
ran on a synthesized input · constructed an object; no result was computed
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("65315a42df7afec6")
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 an instance of its own class, LukeConfig: the run constructed the object and did not call it, so no result was computed. 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 torch.nn as nn
from transformers.models.bert.modeling_bert import BertConfig

torch.manual_seed(0)

ARGS = {
    "vocab_size": 1000,
    "entity_vocab_size": 500,
    "bert_model_name": "bert-base-uncased",
    "entity_emb_size": 768,
    "cls_entity_prediction": False,
    "hidden_size": 768,
    "num_hidden_layers": 2,
    "num_attention_heads": 4,
    "intermediate_size": 512,
    "hidden_act": "gelu",
    "hidden_dropout_prob": 0.1,
    "attention_probs_dropout_prob": 0.1,
    "max_position_embeddings": 512,
    "type_vocab_size": 2,
    "initializer_range": 0.02,
    "layer_norm_eps": 1e-12,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LukeConfig — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a LukeConfig 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
EntityAwareEncoder Not yet run
unverified (harvested, no recorded run)
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("5f47aef368b5af00")
How it ran

no invocation recorded.

EntityAwareLayer Not yet run
unverified (harvested, no recorded run)
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("75c5d0233ea564ee")
How it ran

no invocation recorded.

LukeEncoder Not yet run
unverified (harvested, no recorded run)
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("6139734334c69c5d")
How it ran

no invocation recorded.

LukeEntityAwareAttentionModel Not yet run
unverified (harvested, no recorded run)
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("de51e92ef6ec77d5")
How it ran

no invocation recorded.

LukeModel Not yet run
unverified (harvested, no recorded run)
studio-ousia/luke/luke/model.py
code served (permissive licence) · get_code("607f66ef6841b94f")
How it ran

no invocation recorded.

LukeSelfAttention Not yet run
unverified (harvested, no recorded run)
huggingface/transformers/src/transformers/models/luke/modeling_luke.py
code served (permissive licence) · get_code("12ca593ec040ed10")
How it ran

no invocation recorded.

UCTopicModel Not yet run
unverified (harvested, no recorded run)
JiachengLi1995/UCTopic/uctopic/models.py
code served (permissive licence) · get_code("42a369215b401697")
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-21.

Repositories linked to this paper

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

Abstract

Entity representations are useful in natural language tasks involving entities. In this paper, we propose new pretrained contextualized representations of words and entities based on the bidirectional transformer (Vaswani et al., 2017). The proposed model treats words and entities in a given text as independent tokens, and outputs contextualized representations of them. Our model is trained using a new pretraining task based on the masked language model of BERT (Devlin et al., 2019). The task involves predicting randomly masked words and entities in a large entity-annotated corpus retrieved from Wikipedia. We also propose an entity-aware self-attention mechanism that is an extension of the self-attention mechanism of the transformer, and considers the types of tokens (words or entities) when computing attention scores. The proposed model achieves impressive empirical performance on a wide range of entity-related tasks. In particular, it obtains state-of-the-art results on five well-known datasets: Open Entity (entity typing), TACRED (relation classification), CoNLL-2003 (named entity recognition), ReCoRD (cloze-style question answering), and SQuAD 1.1 (extractive question answering). Our source code and pretrained representations are available at https: //github.com/studio-ousia/luke.

For agents

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

get_harvested_code_for_paper("2010.01057")
get_code_for_paper("2010.01057")
have("2010.01057")

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

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

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

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

Connect an agent — have() is free.