This is a lightweight dense single-vector bi-encoder model for
French
that can be used for semantic search.
The model maps queries and passages to 768-dimensional dense vectors which are used to compute relevance through cosine similarity.
It uses a
CamemBERT-L4
backbone, which is a pruned version of the pre-trained
CamemBERT
checkpoint with 51% less parameters, obtained by
dropping the top-layers
from the original model.
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."]
model = SentenceTransformer('antoinelouis/biencoder-camembert-L4-mmarcoFR')
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."]
model = FlagModel('antoinelouis/biencoder-camembert-L4-mmarcoFR')
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:
import torch
from torch.nn.functional import normalize
from transformers import AutoTokenizer, AutoModel
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."]
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/biencoder-camembert-L4-mmarcoFR')
model = AutoModel.from_pretrained('antoinelouis/biencoder-camembert-L4-mmarcoFR')
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
The model is evaluated on the smaller development set of
mMARCO-fr
, which consists of 6,980 queries for a corpus of
8.8M candidate passages. We report the mean reciprocal rank (MRR), normalized discounted cumulative gainand (NDCG), mean average precision (MAP), and recall at various cut-offs (R@k).
To see how it compares to other neural retrievers in French, check out the
DécouvrIR
leaderboard.
Training
Data
We use the French training samples from the
mMARCO
dataset, a multilingual machine-translated version of MS MARCO
that contains 8.8M passages and 539K training queries. We do not employ the BM25 negatives provided by the official dataset but instead sample harder negatives mined
from 12 distinct dense retrievers, using the
msmarco-hard-negatives
distillation dataset.
Implementation
The model is initialized from the
camembert-L4
checkpoint and optimized via the cross-entropy loss
(as in
DPR
) with a temperature of 0.05. It is fine-tuned on one 32GB NVIDIA V100 GPU for 17.4k steps (or 40 epochs)
using the AdamW optimizer with a batch size of 1152, a peak learning rate of 2e-5 with warm up along the first 1736 steps and linear scheduling.
We set the maximum sequence lengths for both the questions and passages to 128 tokens. We use the cosine similarity to compute relevance scores.
Citation
@online{louis2024decouvrir,
author = 'Antoine Louis',
title = 'DécouvrIR: A Benchmark for Evaluating the Robustness of Information Retrieval Models in French',
publisher = 'Hugging Face',
month = 'mar',
year = '2024',
url = 'https://huggingface.co/spaces/antoinelouis/decouvrir',
}
Runs of antoinelouis biencoder-camembert-L4-mmarcoFR on huggingface.co
30
Total runs
-1
24-hour runs
-1
3-day runs
-14
7-day runs
-69
30-day runs
More Information About biencoder-camembert-L4-mmarcoFR huggingface.co Model
More biencoder-camembert-L4-mmarcoFR license Visit here:
biencoder-camembert-L4-mmarcoFR huggingface.co is an AI model on huggingface.co that provides biencoder-camembert-L4-mmarcoFR's model effect (), which can be used instantly with this antoinelouis biencoder-camembert-L4-mmarcoFR model. huggingface.co supports a free trial of the biencoder-camembert-L4-mmarcoFR model, and also provides paid use of the biencoder-camembert-L4-mmarcoFR. Support call biencoder-camembert-L4-mmarcoFR model through api, including Node.js, Python, http.
biencoder-camembert-L4-mmarcoFR huggingface.co is an online trial and call api platform, which integrates biencoder-camembert-L4-mmarcoFR's modeling effects, including api services, and provides a free online trial of biencoder-camembert-L4-mmarcoFR, you can try biencoder-camembert-L4-mmarcoFR online for free by clicking the link below.
antoinelouis biencoder-camembert-L4-mmarcoFR online free url in huggingface.co:
biencoder-camembert-L4-mmarcoFR is an open source model from GitHub that offers a free installation service, and any user can find biencoder-camembert-L4-mmarcoFR on GitHub to install. At the same time, huggingface.co provides the effect of biencoder-camembert-L4-mmarcoFR install, users can directly use biencoder-camembert-L4-mmarcoFR installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
biencoder-camembert-L4-mmarcoFR install url in huggingface.co: