This repository contains ALIA MrBERT Spanish Legal and Administrative Reranker, a Spanish legal domain cross-encoder (reranker) model for information retrieval and document ranking tasks. It is built upon MrBERT-es, a bilingual (Spanish–English) foundational language model based on the ModernBERT architecture, and fine-tuned on domain-specific legal and administrative data using a Curriculum Learning strategy.
[!WARNING] DISCLAIMER: This model is a domain-specific proof-of-concept designed to demonstrate retrieval capabilities in the Spanish legal and administrative domain. While optimized for this domain, results should be verified against official legal sources. The model may fail in out-of-domain or adversarial inputs.
ModernBERT (architecture)
↓
MrBERT-es (BSC-LT)
Bilingual ES/EN encoder
150M parameters
↓
ALIA-MrBERT-es-legal-administrative-reranker (SINAI)
Legal domain fine-tuning
Curriculum Learning + Hard Negatives
This model uses the same base architecture as MrBERT-es, formatted as a Cross-Encoder for sentence pair classification:
| Base Architecture | ModernBERT |
| Total Parameters | ~150M |
| Hidden size | 768 |
| Intermediate size | 1,152 |
| Attention heads | 12 |
| Hidden layers | 22 |
| Context length | 8,192 tokens |
| Vocabulary size | 51,200 |
| Precision | bfloat16 |
| Model Type | Cross-Encoder |
The model was fine-tuned using a Curriculum Learning strategy, progressively increasing the difficulty of training examples. For this Cross-Encoder, the training focused on the most challenging examples: pairs that a Bi-Encoder might struggle to distinguish.
The dataset consists of text pairs incorporating hard negatives mined from the corpus SINAI/ALIA-es-legal-administrative-triplets/train. For the Cross-Encoder, the data is flattened into independent {query, document, label} pairs, where label is either 1.0 (relevant) or 0.0 (irrelevant).
Refinement with Hard Negatives: Training uses mined hard negatives to force the model to distinguish fine-grained nuances. Examples are processed in order of increasing difficulty (easy → medium → hard) to improve convergence and generalization.
Before training, hyperparameter search was conducted using Optuna (20 trials) to maximize NDCG@10 (with fallback to MRR@10) on a control subset:
OptunaPruningCallback reporting NDCG@10CrossEncoderRerankingEvaluator| Hyperparameter | Value | Description |
|---|---|---|
| Learning Rate | 4.8021×10⁻⁵ | Nominal learning rate |
| Batch Size | 32 | Global batch size per device |
| Gradient Accumulation | 8 | Simulates larger effective batches |
| Warmup Ratio | 0.1111 | Linear LR warmup during the first 11% of steps |
| Weight Decay | 0.0360 | L2 regularization |
| Optimizer | AdamW | Standard HuggingFace Trainer optimizer |
| Precision | bf16 | Bfloat16 for supported architectures |
| Max Sequence Length | 2,048 | Maximum tokens processed for the concatenated (query, doc) pair |
| Loss Function | BinaryCrossEntropyLoss | Treats pairs as an independent binary classification problem |
| Gradient Checkpointing | Enabled | Memory optimization for long contexts (use_reentrant=False) |
| Component | Details |
|---|---|
| Library | PyTorch, sentence-transformers, HuggingFace datasets |
| Distributed | DDP (Distributed Data Parallel) via torchrun |
| Memory optimization | Gradient Checkpointing (expandable_segments:True) |
| Logging | WandB (via report_to=wandb) |
This model is designed for document reranking and semantic matching tasks in the Spanish legal and administrative domain. Primary use cases include:
sentence-transformersfrom sentence_transformers import CrossEncoder
model = CrossEncoder("SINAI/ALIA-MrBERT-es-legal-administrative-reranker")
query = "¿Cuáles son los requisitos para solicitar una prestación por desempleo?"
documents = [
"El trabajador que cese en su actividad laboral tendrá derecho a la prestación por desempleo...",
"La prestación por desempleo contributiva se reconoce a quienes hayan cotizado al menos 360 días...",
"El subsidio de incapacidad temporal requiere un certificado médico en vigor.",
]
# We want to score the query with each document
pairs = [[query, doc] for doc in documents]
scores = model.predict(pairs)
print(scores)
The model was evaluated using the MTEB (Massive Text Embedding Benchmark) framework, adapted for the legal domain. The main reported metric is NDCG@10 (Normalized Discounted Cumulative Gain at k=10), which is the standard metric used in retrieval leaderboards and aligns with the metric reported in the MrBERT family.
| Dataset | Category | Description |
|---|---|---|
| miracl | Reranking | Spanish reranking subset of the MIRACL (mteb/MIRACLReranking) |
| esci | Reranking | ESCI dataset for Spanish language (mteb/ESCIReranking) |
| justicio | Reranking | Subset of legal domain QA dataset for RAG evaluation derived from the Justicio corpus (dariolopez/justicio-rag-embedding-qa-tmp) and a subset based on an article from the Spanish Constitution (dariolopez/justicio-BOE-A-1978-31229-constitucion-by-articles-qa-qa-groq_llama3_70b_8192-sas) |
| ssld | Reranking | Spanish legal language triplet dataset (wilfredomartel/small-spanish-legal-dataset) |
| pairs650 | Reranking | Subset of 650 evaluation pairs (query + context) derived from SINAI/ALIA-es-legal-administrative-triplets/test |
| pairs1.3k | Reranking | Subset of 1.3K evaluation pairs (query + context) derived from SINAI/ALIA-es-legal-administrative-triplets/test |
The following table reports the performance of the model compared to leading commercial/open-weight generalist models:
| Model | miracl | esci | justicio | ssld | pairs650 | pairs1.3k |
|---|---|---|---|---|---|---|
| BAAI/bge-reranker-v2-m3 | 0.6777 | 0.8321 | 0.8055 | 0.8765 | 0.9814 | 0.9820 |
| nvidia/llama-nemotron-rerank-1b-v2 | 0.6258 | 0.8004 | 0.7998 | 0.9198 | 0.9536 | 0.9497 |
| tomaarsen/Qwen3-Reranker-0.6B-seq-cls | 0.6724 | 0.8133 | 0.7898 | 0.87 | 0.9812 | 0.9807 |
| ALIA-MrBERT-es-legal-administrative-reranker (ours) | 0.5144 | 0.8018 | 0.7880 | 0.9140 | 0.9811 | 0.9840 |
Note: The BGE reranker and Nemotron reranker are significantly larger scale models (billions of parameters), yet our domain-specific 150M parameter cross-encoder performs comparably or better on specialized legal Spanish datasets (e.g., ssld, pairs650, pairs1.3k).
If you use this model in your research, please cite:
@misc{ALIA-MrBERT-es-legal-administrative-reranker,
title = {ALIA MrBERT Spanish Legal and Administrative Reranker Model},
author = {SINAI Research Group, Universidad de Jaén},
year = {2026},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/SINAI/ALIA-MrBERT-es-legal-administrative-reranker}}
}
Please also cite the base model:
@misc{tamayo2026mrbertmodernmultilingualencoders,
title={MrBERT: Modern Multilingual Encoders via Vocabulary, Domain, and Dimensional Adaptation},
author={Daniel Tamayo and Iñaki Lacunza and Paula Rivera-Hidalgo and Severino Da Dalt and Javier Aula-Blasco and Aitor Gonzalez-Agirre and Marta Villegas},
year={2026},
eprint={2602.21379},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2602.21379},
}
This work is funded by the Ministerio para la Transformación Digital y de la Función Pública - Funded by EU – NextGenerationEU within the framework of the project ALIA.
This dataset has been generated thanks to CEATIC (Centro de Estudios Avanzados en Tecnologías de la Información y de la Comunicación) – UJA (Universidad de Jaén) which provided the needed computational resources on its clusters.
Contact: ALIA Project - SINAI Research Group - Universidad de Jaén
More Information: SINAI Research Group | ALIA-UJA Project
BSC-LT/MrBERT-es