🚀 跨編碼器CamemBERT基礎模型 - mMARCO法語版
這是一個用於法語的跨編碼器模型。它在問題 - 段落對之間執行交叉注意力,並輸出相關性得分。該模型可作為語義搜索的重排器:給定一個查詢和一組由高效的第一階段檢索系統(如BM25或經過微調的密集單向量雙編碼器)檢索到的潛在相關段落,對每個查詢 - 段落對進行編碼,並根據模型預測的得分按相關性降序對段落進行排序。
🚀 快速開始
本模型可結合 Sentence - Transformers、FlagEmbedding 或 Huggingface Transformers 庫使用,以下是具體示例。
💻 使用示例
基礎用法
使用Sentence - Transformers
首先安裝 庫:pip install -U sentence-transformers
。然後,你可以這樣使用模型:
from sentence_transformers import CrossEncoder
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
model = CrossEncoder('antoinelouis/crossencoder-camembert-base-mmarcoFR')
scores = model.predict(pairs)
print(scores)
使用FlagEmbedding
首先安裝 庫:pip install -U FlagEmbedding
。然後,你可以這樣使用模型:
from FlagEmbedding import FlagReranker
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
reranker = FlagReranker('antoinelouis/crossencoder-camembert-base-mmarcoFR')
scores = reranker.compute_score(pairs)
print(scores)
使用HuggingFace Transformers
首先安裝 庫:pip install -U transformers
。然後,你可以這樣使用模型:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/crossencoder-camembert-base-mmarcoFR')
model = AutoModelForSequenceClassification.from_pretrained('antoinelouis/crossencoder-camembert-base-mmarcoFR')
model.eval()
with torch.no_grad():
inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
print(scores)
📚 詳細文檔
評估
該模型在 [mMARCO - fr](https://ir - datasets.com/mmarco.html#mmarco/v2/fr/) 的較小開發集上進行評估,該開發集包含6980個查詢,需要對包含正樣本和 ColBERTv2硬負樣本 的1000個段落集合進行重排。我們報告了平均倒數排名(MRR)和不同截斷點的召回率(R@k)。若要查看該模型與其他法語神經檢索器的對比情況,請查看 DécouvrIR 排行榜。
訓練
數據
我們使用 [mMARCO](https://huggingface.co/datasets/unicamp - dl/mmarco) 數據集中的法語訓練樣本,這是MS MARCO的多語言機器翻譯版本,包含880萬個段落和53.9萬個訓練查詢。我們沒有使用官方數據集提供的BM25負樣本,而是使用 [msmarco - hard - negatives](https://huggingface.co/datasets/sentence - transformers/msmarco - hard - negatives#msmarco - hard - negativesjsonlgz) 蒸餾數據集,從12個不同的密集檢索器中挖掘並採樣更難的負樣本。最終,我們採樣了260萬個形式為(查詢、段落、相關性)的訓練三元組,正樣本與負樣本的比例為1(即50%的對是相關的,50%是不相關的)。
實現
該模型從 [almanach/camembert - base](https://huggingface.co/almanach/camembert - base) 檢查點進行初始化,並通過二元交叉熵損失進行優化(如 monoBERT 中所述)。使用AdamW優化器在一塊80GB的NVIDIA H100 GPU上進行20000步的微調,批量大小為128,恆定學習率為2e - 5。我們將連接後的問題 - 段落對的最大序列長度設置為256個標記。使用sigmoid函數得到0到1之間的分數。
📄 許可證
本模型採用MIT許可證。
🔖 模型信息
屬性 |
詳情 |
模型類型 |
跨編碼器模型 |
訓練數據 |
mMARCO數據集中的法語訓練樣本 |
基礎模型 |
almanach/camembert - base |
📚 引用
@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',
}