CoolFace
Modelpublic

AnjaliRuban/idiolex-bertin-es

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes55downloads
Model Card

IdioleX-ES — Style-Aware Spanish Sentence Embeddings

IdioleX-ES is a sentence encoder trained under the IDIOLEX framework for idiolectal representation learning — capturing how text is expressed rather than what it says. Embeddings encode stylistic and dialectal variation across 17 Spanish varieties, decoupled from semantic content.

Kantharuban et al., IDIOLEX: Unified and Continuous Representations for Idiolectal and Stylistic Variation (preprint, under review). Code: github.com/AnjaliRuban/IdioleX

Architecture

input_ids → BERTIN (RoBERTa-base) → layer-wise attention → mean pool
          → mean centering → L2 normalize → embedding
ComponentDetail
Base encoder`bertin-project/bertin-roberta-base-spanish`
PoolingLearnable layer-wise attention over all 13 hidden states (embedding + 12 transformer layers), then mean pool
CenteringRunning-mean subtraction estimated over the Spanish training corpus
OutputL2-normalized vector, 768-dimensional

The scalar-mix weights are learned jointly with the encoder, following Rei et al. (2020).

Training

Data

Training data consists of Reddit comments from 17 regional Spanish-language subreddits, collected via the Pushshift archive through December 2024 and filtered for language and quality. Pre-training uses ~557k authors and ~49.5M sentences. Feature-supervised training uses 200 authors per dialect with LLM-annotated linguistic features.

VarietySubredditVarietySubreddit
Argentinianr/argentinaMexicanr/mexico
Bolivianr/BOLIVIAPanamanianr/Panama
Chileanr/chileParaguayanr/Paraguay
Colombianr/ColombiaPeruvianr/PERU
Cubanr/cubaPeninsularr/spain
Dominicanr/DominicanUruguayanr/uruguay
Ecuadorianr/ecuadorVenezuelanr/vzla
El Salvadorianr/ElSalvador
Guatemalanr/guatemala
Honduranr/Honduras

Linguistic Features

41 binary dialectal features are extracted sentence-by-sentence using GPT-5-mini, covering: subject pronoun use (yo, , usted, vos, vosotros, ustedes, etc.), verbal morphology (voseo present/imperative suffixes, 2pl forms -áis/-éis/-ís), diminutive suffixes (-ito/a, -ico/a, -illo/a, -ino/a, -ete, etc.), clitic patterns (DOM a, accusative/dative doubling, preverbal clitics, clitic sequences), and orthographic markers (inverted punctuation, all-caps, repeated punctuation).

Objectives

Training proceeds in two stages:

Stage 1 — Ranking pre-training (full dataset): A margin ranking loss encourages sentences with higher hierarchical proximity to be closer in embedding space. Each batch of 16 is structured so every sentence has exactly one same-comment neighbor (r=3), two same-author neighbors (r=2), four same-dialect neighbors (r=1), and eight cross-dialect neighbors (r=0). The margin λ warms up linearly from 0 to 0.5 over 25k steps.

Stage 2 — Feature-aware training (annotated subset, α=0.5):

LossWeightPurpose
Margin ranking loss1 − α = 0.5Proximity-based ranking
Feature prediction BCE0.25 × α = 0.125Predict 41 linguistic features
Supervised contrastive (Jaccard-weighted)α = 0.5Feature-similarity alignment

A VICReg regularizer (weight 0.25) enforces variance ≥ 1 per dimension and decorrelates embedding dimensions to prevent anisotropy.

Hyperparameters

ParameterValue
Base modelbertin-project/bertin-roberta-base-spanish
Hidden size768
Transformer layers12
Max sequence length512
Batch size32
Ranking group size16
Feature vector dimension41
Feature loss weight (α)0.5
Contrastive temperature (τ)0.07
Jaccard top-k5
Learning rate1 × 10⁻⁵
LR warmup25k steps
OptimizerAdam
Margin (λ)0 → 0.5 (linear warmup)
Training GPUs4
Max training time≤ 48 hrs

Performance

Dialect Identification — DSL-ML 2024 (multi-label)

ModelF1Exact Match
IdioleX-ES0.850.62
Finetuned IdioleX-ES0.840.63
Finetuned IdioleX-ES + Lexical0.850.63
Finetuned BERT (baseline)0.800.59
Centroid Clustering w/ BERT0.770.57
Saleva & Palen-Michel, 2024 (shared task winner)0.820.50

Authorship Attribution — PAN 2019 (open-set, cross-domain)

ModelAccuracy
IdioleX-ES31%
Finetuned IdioleX-ES36%
Finetuned IdioleX-ES + Lexical38%
Finetuned BERT (baseline)28%
Centroid Clustering w/ BERT16%
Centroid Clustering w/ E527%

PAN 2019 is a cross-domain benchmark (test domain not seen during training), so these results demonstrate transfer of stylistic features beyond topical content.

Semantic Decoupling

Pearson correlation between IdioleX-ES idiolectal similarity scores and Multilingual-E5 semantic similarity scores on withheld Reddit test pairs: ρ = 0.09. Stylistic and semantic similarity are largely independent.

Usage

python
import torch
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained(
    "your-username/idiolex-bertin-spanish",
    trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained("your-username/idiolex-bertin-spanish")

sentences = [
    "Che, ¿me tirás una mano con esto?",   # Argentinian
    "Oye, ¿me echas una mano con esto?",   # Peninsular
]

inputs = tokenizer(
    sentences,
    return_tensors="pt",
    truncation=True,
    padding=True,
    max_length=model.config.model_len,  # 512
)

with torch.no_grad():
    embeddings = model(**inputs)   # [2, 768], L2-normalized

# Cosine similarity (embeddings are L2-normalized, so dot product = cosine sim)
similarity = embeddings @ embeddings.T
print(similarity)

Config

ParameterValue
base_modelbertin-project/bertin-roberta-base-spanish
embedding_dim768
layerwise_poolingTrue
num_layers13 (12 transformer layers + embedding layer)
layer_normFalse
layer_dropoutNone
mean_centerTrue
model_len512

Custom files

This model uses trust_remote_code=True. The following files are hosted in this repo:

FilePurpose
configuration_idiolex.pyIdioleXConfig
modeling_idiolex.pyIdioleXModel
centering.pyMeanCenterer — distributed running-mean buffer
layer_pool.pyLayerwiseAttention — scalar-mix of transformer layers
pooling_utils.pylast_token_pool, average_pool

Citation

bibtex
@article{kantharuban2025idiolex,
  title   = {IDIOLEX: Unified and Continuous Representations for Idiolectal and Stylistic Variation},
  author  = {Kantharuban, Anjali and Srivastava, Aarohi and Faisal, Fahim and Ahia, Orevaoghene
             and Anastasopoulos, Antonios and Chiang, David and Tsvetkov, Yulia and Neubig, Graham},
  year    = {2025},
  note    = {Preprint, under review}
}