SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2305.09148 · ACL · 2023

Dual-Alignment Pre-training for Cross-lingual Sentence Embedding

Furu Wei, Qi Zhang, Jian Jiao, Weiwei Deng, Shaohan Huang, Zihan Zhang, Zhi-Hong Deng, Haizhen Huang, Ziheng Li, Qiang Lou

arXiv · PDF · Open in the Atlas

Code that ran

2 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 1 has no contract verdict; 1 failure of our instrument; 5 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/2305.09148.json · badge: /api/ran/2305.09148.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
ChillingDream/DAP community
Papers with Code archive
2 ran · 5 no recorded run
FunctionStatusWhere it lives
XLMEmbeddings Ran
ran on a synthesized input
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("50850d9a18be38b7")
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 Tensor, ndim 3, dtype family float, shape (2, 3, 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
import torch.nn as nn
from transformers.models.bert.modeling_bert import BertEmbeddings

class XLMEmbeddings(BertEmbeddings):

    def __init__(self, config):
        super().__init__(config)
        if hasattr(config, 'n_langs') and config.n_langs > 1 and config.use_lang_emb:
            self.lang_embeddings = nn.Embedding(config.n_langs, config.hidden_size)

    def forward(self, input_ids=None, langs=None, token_type_ids=None, position_ids=None, inputs_embeds=None, past_key_values_length=0):
        if input_ids is not None:
            input_shape = input_ids.size()
        else:
            input_shape = inputs_embeds.size()[:-1]
        seq_length = input_shape[1]
        if position_ids is None:
            position_ids = self.position_ids[:, past_key_values_length:seq_length + past_key_values_length]
        if token_type_ids is None:
            if hasattr(self, 'token_type_ids'):
                buffered_token_type_ids = self.token_type_ids[:, :seq_length]
                buffered_token_type_ids_expanded = buffered_token_type_ids.expand(input_shape[0], seq_length)
                token_type_ids = buffered_token_type_ids_expanded
            else:
                token_type_ids = torch.zeros(input_shape, dtype=torch.long, device=self.position_ids.device)
        if inputs_embeds is None:
            inputs_embeds = self.word_embeddings(input_ids)
        token_type_embeddings = self.token_type_embeddings(token_type_ids)
        embeddings = inputs_embeds + token_type_embeddings
        if langs is not None and hasattr(self, 'lang_embeddings'):
            lang_embeddings = self.lang_embeddings(langs)
            embeddings += lang_embeddings
        if self.position_embedding_type == 'absolute':
            position_embeddings = self.position_embeddings(position_ids)
            embeddings += position_embeddings
        embeddings = self.LayerNorm(embeddings)
        embeddings = self.dropout(embeddings)
        return embeddings


class Config:
    def __init__(self):
        self.vocab_size = 100
        self.hidden_size = 4
        self.num_hidden_layers = 2
        self.num_attention_heads = 2
        self.intermediate_size = 8
        self.hidden_act = "gelu"
        self.hidden_dropout_prob = 0.1
        self.attention_probs_dropout_prob = 0.1
        self.max_position_embeddings = 512
        self.type_vocab_size = 2
        self.initializer_range = 0.02
        self.layer_norm_eps = 1e-12
        self.pad_token_id = 0
        self.position_embedding_type = "absolute"
        self.n_langs = 3
        self.use_lang_emb = True


INIT_ARGS = {
    'config': Config()
}

ARGS = {
    'input_ids': torch.tensor([[1, 2, 3], [4, 5, 6]], dtype=torch.long),
    'langs': torch.tensor([[0], [1]], dtype=torch.long),
    'token_type_ids': None,
    'position_ids': None,
    'inputs_embeds': None,
    'past_key_values_length': 0
}

if __name__ == '__main__':
    model = XLMEmbeddings(**INIT_ARGS)
    output = model(**ARGS)
    print(output.shape)
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 Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
sentemb_forward Ran
ran; our contract draft was wrong, not the code
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("9c4a22aa68aaf689")
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 BaseModelOutputWithPoolingAndCrossAttentions. 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.modeling_outputs import BaseModelOutputWithPoolingAndCrossAttentions

torch.manual_seed(0)

# Stand-in config class
class Config:
    def __init__(self):
        self.use_return_dict = True

# Stand-in model_args class
class ModelArgs:
    def __init__(self):
        self.mlp_only_train = False

# Minimal encoder that returns expected output structure
class MinimalEncoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(100, 4)
    
    def forward(self, input_ids, langs=None, attention_mask=None, token_type_ids=None, 
                position_ids=None, head_mask=None, inputs_embeds=None, 
                output_attentions=None, output_hidden_states=False, return_dict=False):
        # Embed input_ids
        last_hidden_state = self.embedding(input_ids)  # (batch, seq_len, 4)
        hidden_states = (last_hidden_state,) if output_hidden_states else None
        
        return BaseModelOutputWithPoolingAndCrossAttentions(
            last_hidden_state=last_hidden_state,
            pooler_output=last_hidden_state[:, 0, :],
            hidden_states=hidden_states
        )

# Minimal pooler
class MinimalPooler(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, attention_mask, outputs):
        # Simple mean pooling
        return outputs.last_hidden_state[:, 0, :]

# Minimal MLP
class MinimalMLP(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.linear(x)

# Minimal cls object with all required attributes and methods
class MinimalCls:
    def __init__(self):
        self.config = Config()
        self.model_args = ModelArgs()
        self.pooler_type = 'cls'
        self.pooler = MinimalPooler()
        self.mlp = MinimalMLP()

# Construct arguments
cls = MinimalCls()
encoder = MinimalEncoder()

batch_size = 2
seq_len = 5
num_sentences = 3  # reshape dimension

input_ids = torch.randint(0, 100, (batch_size * num_sentences, seq_len))
attention_mask = torch.ones((batch_size * num_sentences, seq_len))
token_type_ids = torch.zeros((batch_size * num_sentences, seq_len), dtype=torch.long)
langs = torch.zeros((batch_size * num_sentences, seq_len), dtype=torch.long)
position_ids = None
head_mask = None
inputs_embeds = None
labels = None
output_attentions = False
output_hidden_states = False
return_dict = True

ARGS = {
    'cls': cls,
    'encoder': encoder,
    'input_ids': input_ids,
    'attention_mask': attention_mask,
    'token_type_ids': token_type_ids,
    'position_ids': position_ids,
    'head_mask': head_mask,
    'inputs_embeds': inputs_embeds,
    'langs': langs,
    'labels': labels,
    'output_attentions': output_attentions,
    'output_hidden_states': output_hidden_states,
    'return_dict': return_dict
}
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 BaseModelOutputWithPoolingAndCrossAttentions — a BaseModelOutputWithPoolingAndCrossAttentions output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a BaseModelOutputWithPoolingAndCrossAttentions 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
BertForRTL Not yet run
unverified (harvested, no recorded run)
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("3e8006c3e4f18596")
How it ran

no invocation recorded.

SimCSEModel Not yet run
unverified (harvested, no recorded run)
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("a374bbeb0bab66e1")
How it ran

no invocation recorded.

XLMBertModel Not yet run
unverified (harvested, no recorded run)
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("f7f82b2df9f8a191")
How it ran

no invocation recorded.

cl_forward Not yet run
unverified (harvested, no recorded run)
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("6902d67afe6ef0d7")
How it ran

no invocation recorded.

cl_init Not yet run
unverified (harvested, no recorded run)
ChillingDream/DAP/core/models.py
code served (permissive licence) · get_code("0e83ce43dc99ea57")
How it ran

no invocation recorded.

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

Recent studies have shown that dual encoder models trained with the sentence-level translation ranking task are effective methods for cross-lingual sentence embedding. However, our research indicates that token-level alignment is also crucial in multilingual scenarios, which has not been fully explored previously. Based on our findings, we propose a dual-alignment pre-training (DAP) framework for cross-lingual sentence embedding that incorporates both sentence-level and token-level alignment. To achieve this, we introduce a novel representation translation learning (RTL) task, where the model learns to use one-side contextualized token representation to reconstruct its translation counterpart. This reconstruction objective encourages the model to embed translation information into the token representation. Compared to other token-level alignment methods such as translation language modeling, RTL is more suitable for dual encoder architectures and is computationally efficient. Extensive experiments on three sentencelevel cross-lingual benchmarks demonstrate that our approach can significantly improve sentence embedding. Our code is available at https://github.com/ChillingDream/DAP.

For agents

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

get_harvested_code_for_paper("2305.09148")
get_code_for_paper("2305.09148")
have("2305.09148")

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

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

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

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

Connect an agent — have() is free.