🚀 colbertv2-camembert-L4-mmarcoFR
這是一個輕量級的 ColBERTv2 模型,專為 法語 語義搜索而設計。它能將查詢語句和文本段落編碼成基於詞元級別的嵌入矩陣,並藉助可擴展的向量相似度(MaxSim)算子,高效地找出與查詢語句在上下文上匹配的段落。
🚀 快速開始
本模型可搭配 RAGatouille 或 colbert-ai 使用,以下是使用示例。
📦 安裝指南
使用 RAGatouille
首先,你需要安裝以下庫:
pip install -U ragatouille
使用 ColBERT-AI
首先,你需要安裝以下庫:
pip install git+https://github.com/stanford-futuredata/ColBERT.git torch faiss-gpu==1.7.2
💻 使用示例
使用 RAGatouille
from ragatouille import RAGPretrainedModel
index_name: str = "my_index"
documents: list = ["Ceci est un premier document.", "Voici un second document.", "etc."]
RAG = RAGPretrainedModel.from_pretrained("antoinelouis/colbertv2-camembert-L4-mmarcoFR")
RAG.index(name=index_name, collection=documents)
RAG = RAGPretrainedModel.from_index(index_name)
RAG.search(query="Comment effectuer une recherche avec ColBERT ?", k=10)
使用 ColBERT-AI
from colbert import Indexer, Searcher
from colbert.infra import Run, RunConfig
n_gpu: int = 1
experiment: str = "colbert"
index_name: str = "my_index"
documents: list = ["Ceci est un premier document.", "Voici un second document.", "etc."]
with Run().context(RunConfig(nranks=n_gpu,experiment=experiment)):
indexer = Indexer(checkpoint="antoinelouis/colbertv2-camembert-L4-mmarcoFR")
indexer.index(name=index_name, collection=documents)
with Run().context(RunConfig(nranks=n_gpu,experiment=experiment)):
searcher = Searcher(index=index_name)
results = searcher.search(query="Comment effectuer une recherche avec ColBERT ?", k=10)
📚 詳細文檔
評估
該模型在 mMARCO-fr 的較小開發集上進行評估,該開發集包含 6980 個查詢,針對 880 萬個候選段落的語料庫。我們報告了平均倒數排名(MRR)、歸一化折損累積增益(NDCG)、平均精度均值(MAP)以及不同截斷點的召回率(R@k)。
以下是該模型與其他在相同數據集上微調的公開可用法語 ColBERT 模型的性能比較。若要查看該模型與其他法語神經檢索器的比較情況,請查看 DécouvrIR 排行榜。
模型 |
參數數量(↓) |
大小 |
維度 |
索引大小 |
召回率@1000 |
召回率@500 |
召回率@100 |
召回率@10 |
MRR@10 |
colbertv2-camembert-L4-mmarcoFR |
54M |
0.2GB |
32 |
9GB |
91.9 |
90.3 |
81.9 |
56.7 |
32.3 |
FraColBERTv2 |
111M |
0.4GB |
128 |
28GB |
90.0 |
88.9 |
81.2 |
57.1 |
32.4 |
colbertv1-camembert-base-mmarcoFR |
111M |
0.4GB |
128 |
28GB |
89.7 |
88.4 |
80.0 |
54.2 |
29.5 |
注意:索引大小是指使用 ColBERTv2 的殘差壓縮機制時,mMARCO-fr 索引(880 萬個段落)在磁盤上的大小。
訓練
數據
我們使用 mMARCO 數據集中的法語訓練樣本,這是 MS MARCO 的多語言機器翻譯版本,包含 880 萬個段落和 53.9 萬個訓練查詢。我們沒有使用官方 三元組 提供的 BM25 負樣本,而是從 12 個不同的密集檢索器中為每個查詢採樣了 62 個更難的負樣本,使用的是 msmarco-hard-negatives 蒸餾數據集。
接下來,我們使用 cross-encoder-ms-marco-MiniLM-L-6-v2-scores 數據集,收集了一個表現力強的 交叉編碼器重排器 對所有(查詢,段落)對的相關性得分。最終,我們得到了 1040 萬個不同的 64 元組,形式為 [查詢,(正樣本,正樣本得分),(負樣本 1,負樣本 1 得分),...,(負樣本 62,負樣本 62 得分)],用於訓練模型。
實現
該模型從 camembert-L4 檢查點初始化,並通過結合 KL 散度損失(用於將交叉編碼器得分蒸餾到模型中)和批內採樣的 softmax 交叉熵損失(應用於每個查詢的正樣本得分與同一批次中所有其他查詢對應的段落得分)進行優化(如 ColBERTv2 所述)。
該模型在一塊 80GB 的 NVIDIA H100 GPU 上進行了 32.5 萬步的微調,使用 AdamW 優化器,批量大小為 32,峰值學習率為 1e-5,在前 2 萬步進行熱身,並採用線性調度。嵌入維度設置為 32,問題和段落的最大序列長度分別固定為 32 和 160 個詞元。我們使用餘弦相似度來計算相關性得分。
📄 許可證
本項目採用 MIT 許可證。
🔗 引用
@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',
}