This is a
multilingual
dense single-vector bi-encoder model. It maps questions and paragraphs 768-dimensional dense vectors and can be used for semantic search. The model uses an
XMOD
backbone, which allows it to learn from monolingual fine-tuning in a high-resource language, like English, and perform zero-shot retrieval across multiple languages.
Start by installing the
library
:
pip install -U sentence-transformers
. Then, you can use the model like this:
from sentence_transformers import SentenceTransformer
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
language_code = "fr_FR"#Find all codes here: https://huggingface.co/facebook/xmod-base#languages
model = SentenceTransformer('antoinelouis/dpr-xm')
model[0].auto_model.set_default_language(language_code) #Activate the language-specific adapters
q_embeddings = model.encode(queries, normalize_embeddings=True)
p_embeddings = model.encode(passages, normalize_embeddings=True)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
Using FlagEmbedding
Start by installing the
library
:
pip install -U FlagEmbedding
. Then, you can use the model like this:
from FlagEmbedding import FlagModel
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
language_code = "fr_FR"#Find all codes here: https://huggingface.co/facebook/xmod-base#languages
model = FlagModel('antoinelouis/dpr-xm')
model.model.set_default_language(language_code) #Activate the language-specific adapters
q_embeddings = model.encode(queries, normalize_embeddings=True)
p_embeddings = model.encode(passages, normalize_embeddings=True)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
Using Transformers
Start by installing the
library
:
pip install -U transformers
. Then, you can use the model like this:
from transformers import AutoTokenizer, AutoModel
from torch.nn.functional import normalize
defmean_pooling(model_output, attention_mask):
""" Perform mean pooling on-top of the contextualized word embeddings, while ignoring mask tokens in the mean computation."""
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
language_code = "fr_FR"#Find all codes here: https://huggingface.co/facebook/xmod-base#languages
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/dpr-xm')
model = AutoModel.from_pretrained('antoinelouis/dpr-xm')
model.set_default_language(language_code) #Activate the language-specific adapters
q_input = tokenizer(queries, padding=True, truncation=True, return_tensors='pt')
p_input = tokenizer(passages, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
q_output = model(**encoded_queries)
p_output = model(**encoded_passages)
q_embeddings = mean_pooling(q_output, q_input['attention_mask'])
q_embedddings = normalize(q_embeddings, p=2, dim=1)
p_embeddings = mean_pooling(p_output, p_input['attention_mask'])
p_embedddings = normalize(p_embeddings, p=2, dim=1)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
Evaluation
mMARCO
:
We evaluate our model on the small development sets of
mMARCO
, which consists of 6,980 queries for a corpus of 8.8M candidate passages in 14 languages. Below, we compared its multilingual performance with other retrieval models on the dataset official metrics, i.e., mean reciprocal rank at cut-off 10 (MRR@10).
We use the English training samples from the
MS MARCO passage ranking
dataset, which contains 8.8M passages and 539K training queries. We do not employ the BM25 netaives provided by the official dataset but instead sample harder negatives mined from 12 distinct dense retrievers, using the
msmarco-hard-negatives
distillation dataset. Our final training set consists of 25.6M (q, p+, p-) triples.
Implementation
The model is initialized from the
xmod-base
checkpoint and optimized via the in-batch sampled softmax cross-entropy loss (as in
DPR
). It is fine-tuned on one 32GB NVIDIA V100 GPU for 200k steps using the AdamW optimizer with a batch size of 128, a peak learning rate of 2e-5 with warm up along the first 10% of training steps and linear scheduling. We set the maximum sequence lengths for both the questions and passages to 128 tokens.
Citation
@article{louis2024modular,
author = {Louis, Antoine and Saxena, Vageesh and van Dijck, Gijs and Spanakis, Gerasimos},
title = {ColBERT-XM: A Modular Multi-Vector Representation Model for Zero-Shot Multilingual Information Retrieval},
journal = {CoRR},
volume = {abs/2402.15059},
year = {2024},
url = {https://arxiv.org/abs/2402.15059},
doi = {10.48550/arXiv.2402.15059},
eprinttype = {arXiv},
eprint = {2402.15059},
}
Runs of antoinelouis dpr-xm on huggingface.co
39
Total runs
1
24-hour runs
-1
3-day runs
-3
7-day runs
-108
30-day runs
More Information About dpr-xm huggingface.co Model
dpr-xm huggingface.co
dpr-xm huggingface.co is an AI model on huggingface.co that provides dpr-xm's model effect (), which can be used instantly with this antoinelouis dpr-xm model. huggingface.co supports a free trial of the dpr-xm model, and also provides paid use of the dpr-xm. Support call dpr-xm model through api, including Node.js, Python, http.
dpr-xm huggingface.co is an online trial and call api platform, which integrates dpr-xm's modeling effects, including api services, and provides a free online trial of dpr-xm, you can try dpr-xm online for free by clicking the link below.
antoinelouis dpr-xm online free url in huggingface.co:
dpr-xm is an open source model from GitHub that offers a free installation service, and any user can find dpr-xm on GitHub to install. At the same time, huggingface.co provides the effect of dpr-xm install, users can directly use dpr-xm installed effect in huggingface.co for debugging and trial. It also supports api for free installation.