🚀 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',
}