SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2109.06304 · EMNLP · 2021

Phrase-BERT: Improved Phrase Embeddings from BERT with an Application to Corpus Exploration

Shufan Wang, Mohit Iyyer, Laure Thompson

arXiv · PDF · Open in the Atlas

Code that ran

8 of 9 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; 1 honoured the contract we drafted, 1 violated it and 6 have no contract verdict; 0 failures of our instrument; 1 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/2109.06304.json · badge: /api/ran/2109.06304.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
memray/llm_phrase_semantics community (classifier label)
classifier basis not recorded on the link
6 ran · 1 no recorded run
sf-wa-326/phrase-bert-topic-model marked official in Papers with Code
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
compute_triplet_loss Ran
ran, violated the contract we drafted
sf-wa-326/phrase-bert-topic-model/phrase-topic-model/model_utils.py
pointer only (licence: NOASSERTION) · get_code("251934aa5746841d")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, sf-wa-326/phrase-bert-topic-model (NOASSERTION). 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.

conduct_turney_test Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-semantic-eval/eval_turney.py
code served (permissive licence) · get_code("f683260388c1d177")
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

# Create small embedding arrays for testing
# Each embedding will be a small vector
embedding_dim = 4

# Create data_list: list of sublists, each with 8 string entries
# Structure: [bigram_query, correct, component1, component2, cand5, cand6, cand7, cand8]
data_list = [
    ["query1", "correct_word", "comp1", "comp2", "cand5", "cand6", "cand7", "cand8"],
    ["query2", "answer_word", "part1", "part2", "option5", "option6", "option7", "option8"]
]

# Create all_emb_list: list of sublists, each with 8 numpy arrays (embeddings)
# Each embedding is a small vector of dimension embedding_dim
all_emb_list = [
    [
        np.random.randn(embedding_dim).astype(np.float32),  # bigram query emb
        np.random.randn(embedding_dim).astype(np.float32),  # correct emb
        np.random.randn(embedding_dim).astype(np.float32),  # component1 emb
        np.random.randn(embedding_dim).astype(np.float32),  # component2 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand5 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand6 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand7 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand8 emb
    ],
    [
        np.random.randn(embedding_dim).astype(np.float32),  # bigram query emb
        np.random.randn(embedding_dim).astype(np.float32),  # correct emb
        np.random.randn(embedding_dim).astype(np.float32),  # component1 emb
        np.random.randn(embedding_dim).astype(np.float32),  # component2 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand5 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand6 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand7 emb
        np.random.randn(embedding_dim).astype(np.float32),  # cand8 emb
    ]
]

ARGS = {
    "data_list": data_list,
    "all_emb_list": all_emb_list
}
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
l2_normalize_batch Ran
ran, honoured the contract we drafted
sf-wa-326/phrase-bert-topic-model/phrase-topic-model/model_utils.py
pointer only (licence: NOASSERTION) · get_code("5ce2a7a23084e4c8")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, sf-wa-326/phrase-bert-topic-model (NOASSERTION). 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.

load_PiC_PS_data Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-semantic-eval/eval_PiC_PS.py
code served (permissive licence) · get_code("809d9efd59171d4c")
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 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 csv
import tempfile
import os

# Create a temporary TSV file with sample data
temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.tsv', delete=False, newline='')
temp_path = temp_file.name

# Write sample TSV data
writer = csv.writer(temp_file, delimiter='\t', quotechar='|')
writer.writerow(['col1', 'col2', 'col3'])
writer.writerow(['value1', 'value2', 'value3'])
writer.writerow(['value4', 'value5', 'value6'])
temp_file.close()

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 list, ndim 2, dtype family float — 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
load_bird_dev_data Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-semantic-eval/eval_bird.py
code served (permissive licence) · get_code("6bee788f8fa4c5d0")
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 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 csv
import tempfile
import os

# Create a temporary TSV file with sample data
temp_dir = tempfile.mkdtemp()
temp_file = os.path.join(temp_dir, "bird_dev.tsv")

with open(temp_file, 'w', newline='') as f:
    writer = csv.writer(f, delimiter='\t', quotechar='|')
    writer.writerow(['col1', 'col2', 'col3'])
    writer.writerow(['value1', 'value2', 'value3'])
    writer.writerow(['value4', 'value5', 'value6'])
    writer.writerow(['value7', 'value8', 'value9'])

ARGS = {
    'path': temp_file
}
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 float — 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
openai_conduct_bird_test Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-semantic-eval/eval_bird.py
code served (permissive licence) · get_code("f664f8b11ba8231e")
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 torch
import numpy as np
from unittest.mock import Mock, MagicMock

class MockOpenAIModel:
    def __init__(self):
        self.model_name = "gpt-3.5-turbo"
    
    def completions(self, prompt, n=1, temperature=0.0, top_p=1, max_tokens=256):
        # Return a list with a numeric string that can be parsed
        return ["42.5"]

# Create mock openai_model
openai_model = MockOpenAIModel()

# Create phrase details (list of dicts with phrase1 and phrase2)
phrase_details = [
    {'phrase1': 'access information', 'phrase2': 'information access'},
    {'phrase1': 'semantic similarity', 'phrase2': 'word similarity'},
]

# Create human scores (list of floats in range [0, 1] or [0, 100])
human_scores = [0.85, 0.72]

ARGS = {
    'openai_model': openai_model,
    'phrase_details': phrase_details,
    'human_scores': human_scores,
    'k_shot': 0,
    'is_amend': False,
    'cot': False,
    'max_tokens': 256,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy, torch, tqdm — 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
openai_conduct_turney_test Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-semantic-eval/eval_turney.py
code served (permissive licence) · get_code("d722ba66abb59aae")
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 random
from unittest.mock import Mock

# Create a mock model that implements the interface used by openai_conduct_turney_test
class MockOpenAIModel:
    def __init__(self):
        self.model_name = "test-model"
    
    def completions(self, prompt, n=1, temperature=0.0, top_p=1, max_tokens=256):
        # Return a mock response that matches the expected format
        # The function expects raw_pred[0] to be a string
        return ["dosser"]  # Return the correct answer for testing

# Create model instance
model = MockOpenAIModel()

# Create test data following the format described in the docstring
# Each sublist has: [bigram_query, correct_answer, component1, component2, candidate1, candidate2, candidate3, candidate4]
data_list = [
    ['street person', 'dosser', 'street', 'person', 'thoroughfare', 'individual', 'sectarianism', 'paraquat'],
    ['good story', 'funny', 'good', 'story', 'advantage', 'narrative', 'sportsmanship', 'cloudburst'],
    ['sport coat', 'blazer', 'sport', 'coat', 'athletics', 'overgarment', 'herbarium', 'archaebacterium'],
]

# Define arguments for the function
ARGS = {
    'model': model,
    'data_list': data_list,
    'k_shot': 2,
    'cot': False,
    'max_tokens': 256,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tqdm — 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
soft_cross_entropy Ran
ran on a synthesized input
memray/llm_phrase_semantics/phrase-topic-model/model_utils.py
code served (permissive licence) · get_code("f26677a468445f39")
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 0, dtype family float, 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 torch.nn.functional as F

torch.manual_seed(0)

# Create input tensor: batch_size=2, num_classes=4
input_tensor = torch.randn(2, 4)

# Create target tensor: batch_size=2, num_classes=4
# Target should be a probability distribution (soft labels) that sums to 1 along dim=1
target_tensor = torch.softmax(torch.randn(2, 4), dim=1)

ARGS = {
    "input": input_tensor,
    "target": target_tensor,
}
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 0, dtype family float, 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
openai_conduct_PiCPS_test Not yet run
unverified (harvested, no recorded run)
memray/llm_phrase_semantics/phrase-semantic-eval/eval_PiC_PS.py
code served (permissive licence) · get_code("edf9e080104293c0")
How it ran

no invocation recorded.

Also present in other papers' code

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

Phrase representations derived from BERT often do not exhibit complex phrasal compositionality, as the model relies instead on lexical similarity to determine semantic relatedness. In this paper, we propose a contrastive fine-tuning objective that enables BERT to produce more powerful phrase embeddings. Our approach (Phrase-BERT) relies on a dataset of diverse phrasal paraphrases, which is automatically generated using a paraphrase generation model, as well as a large-scale dataset of phrases in context mined from the Books3 corpus. Phrase-BERT outperforms baselines across a variety of phrase-level similarity tasks, while also demonstrating increased lexical diversity between nearest neighbors in the vector space. Finally, as a case study, we show that Phrase-BERT embeddings can be easily integrated with a simple autoencoder to build a phrase-based neural topic model that interprets topics as mixtures of words and phrases by performing a nearest neighbor search in the embedding space. Crowdsourced evaluations demonstrate that this phrase-based topic model produces more coherent and meaningful topics than baseline word and phrase-level topic models, further validating the utility of Phrase-BERT.

For agents

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

get_harvested_code_for_paper("2109.06304")
get_code_for_paper("2109.06304")
have("2109.06304")

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

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

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

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

Connect an agent — have() is free.