Instructions to use ArchitRastogi/bert-base-italian-embeddings with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ArchitRastogi/bert-base-italian-embeddings with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="ArchitRastogi/bert-base-italian-embeddings")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("ArchitRastogi/bert-base-italian-embeddings") model = AutoModel.from_pretrained("ArchitRastogi/bert-base-italian-embeddings", device_map="auto") - Notebooks
- Google Colab
- Kaggle
A 110M-parameter BERT model fine-tuned with contrastive learning from
dbmdz/bert-base-italian-xxl-uncased.
On Italian mMARCO it raises Recall@1000 from 0.206 (base model) to 0.972.
At a glance
| Use it for | Italian passage retrieval, semantic search, the retrieval stage of RAG |
| Embedding | [CLS] token, 768 dimensions, L2-normalised |
| Architecture | BERT-base: 12 layers, hidden size 768, vocabulary 32,102, 512 positions |
| Size | about 110.7M parameters, 443 MB (safetensors, float32) |
| Training data | italian-embedding-finetune-dataset |
| Code | github.com/ArchitRastogi20/ITA-BERT-IR (training and evaluation) |
| License | Apache-2.0 for the weights; see licensing for the training text |
Results
Evaluated on Italian mMARCO with 6,980 queries. The fine-tuned model is highest in every row.
| Metric | Base model | facebook/mcontriever-msmarco |
This model |
|---|---|---|---|
| Recall@1 | 0.0026 | 0.0828 | 0.2106 |
| Recall@100 | 0.0417 | 0.5028 | 0.8356 |
| Recall@1000 | 0.2061 | 0.8049 | 0.9719 |
| Average Precision | 0.0050 | 0.1397 | 0.3173 |
| NDCG@10 | 0.0043 | 0.1591 | 0.3601 |
| NDCG@100 | 0.0108 | 0.2086 | 0.4218 |
| NDCG@1000 | 0.0299 | 0.2454 | 0.4391 |
| MRR@10 | 0.0036 | 0.1299 | 0.3047 |
| MRR@100 | 0.0045 | 0.1385 | 0.3167 |
| MRR@1000 | 0.0050 | 0.1397 | 0.3173 |
"Base model" is dbmdz/bert-base-italian-xxl-uncased, a masked-language-model checkpoint that was never
trained to produce embeddings, so its column shows what contrastive fine-tuning added rather than a competitive
baseline. The comparison against mcontriever-msmarco is the meaningful one, and it is an older multilingual
model: these numbers do not place this model against recent multilingual embedding models.
Usage
The model is a plain BertModel. Use the [CLS] vector and normalise it, exactly as in training and evaluation.
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel
model_id = "ArchitRastogi/bert-base-italian-embeddings"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModel.from_pretrained(model_id).eval()
def embed(texts, max_length=512):
batch = tokenizer(texts, padding=True, truncation=True, max_length=max_length, return_tensors="pt")
with torch.no_grad():
cls = model(**batch).last_hidden_state[:, 0] # [CLS] token
return F.normalize(cls, dim=-1)
query = embed(["Stanchi di non riuscire a trovare il partner perfetto?"])
passages = embed([
"La cosa principale da fare รจ pubblicare il proprio annuncio e aspettare una risposta.",
"Quale rapporto tra investimenti IT e sicurezza?",
])
print(query @ passages.T) # cosine similarity; the first passage scores higher (about 0.62 against 0.31)
Do not load it with AutoModelForMaskedLM: this checkpoint has no language-modelling head, so that call
creates a randomly initialised one and returns logits, not embeddings.
Training
| Base model | dbmdz/bert-base-italian-xxl-uncased |
| Objective | InfoNCE on L2-normalised [CLS] embeddings: each query is scored against the positives and hard negatives of the batch, temperature 0.05 |
| Optimiser | AdamW, learning rate 2e-5, linear schedule with 10% warm-up |
| Data | (query, positive, hard negative) triplets built from the Italian portion of the multilingual C4 corpus (mC4) by sliding-window segmentation and in-document sampling |
| Run | 3 epochs, 922,958 steps, about 5 days 2 hours on one NVIDIA A40 |
Optimiser and temperature are the defaults of the training script in the linked repository.
Intended use and limitations
Intended use. Italian information retrieval and retrieval-augmented generation, in research and production.
- Evaluated only on mMARCO, which is machine-translated MS MARCO. Results on native Italian queries or on legal, medical and other specialised text are untested here.
- The triplets come from web text and carry its biases and noise.
- The training script's default maximum length is 128 tokens. The weights accept 512 and the evaluation used 512, but behaviour on long passages was not studied separately.
- A single aggregate score can hide large per-language differences. See the companion audit below before choosing an embedding model from a leaderboard number.
Licensing
The weights are released under Apache-2.0. The fine-tuning triplets derive from the Italian portion of mC4 (multilingual C4), which is distributed under ODC-By 1.0 and inherits the Common Crawl terms of use; the Apache-2.0 label covers the model weights, not the underlying web text.
Related
- Training data:
italian-embedding-finetune-dataset - Legal-domain sibling:
BGE-Small-LegalEmbeddings-USCode - Italian, Hindi and Japanese finance-and-law RAG benchmark:
multilingual-rag-finance-law, released with A Reliability Audit of Aggregated MTEB Scores (IJCNLP-AACL 2026), ACL Anthology
Citation
@misc{rastogi2024bertitalianembeddings,
author = {Rastogi, Archit},
title = {bert-base-italian-embeddings: a contrastively fine-tuned Italian BERT for retrieval},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/ArchitRastogi/bert-base-italian-embeddings}}
}
Contact
Open a thread in the Community tab, or write to architrastogi20@gmail.com.
- Downloads last month
- 32
Model tree for ArchitRastogi/bert-base-italian-embeddings
Base model
dbmdz/bert-base-italian-xxl-uncasedDataset used to train ArchitRastogi/bert-base-italian-embeddings
Collection including ArchitRastogi/bert-base-italian-embeddings
Evaluation results
- Recall@1 on mMARCO (Italian)self-reported0.211
- Recall@100 on mMARCO (Italian)self-reported0.836
- Recall@1000 on mMARCO (Italian)self-reported0.972
- Average Precision on mMARCO (Italian)self-reported0.317
- NDCG@10 on mMARCO (Italian)self-reported0.360
- NDCG@100 on mMARCO (Italian)self-reported0.422
- NDCG@1000 on mMARCO (Italian)self-reported0.439
- MRR@10 on mMARCO (Italian)self-reported0.305