Provence Reranker Debertav3 V1
Provence是一款轻量级的上下文剪枝模型,专为检索增强生成优化,尤其适用于问答场景。
下载量 1,506
发布时间 : 12/11/2024
模型简介
Provence能移除段落中与用户问题无关的句子,适用于任何大语言模型(LLM),能加速生成过程并减少上下文噪声。
模型特点
上下文剪枝
自动检测并移除段落中与用户问题无关的句子,减少上下文噪声。
多领域适用
训练数据结合了多样化的MS Marco和自然问题数据集,适用于各种领域。
即插即用
可与任何大语言模型(LLM)配合使用,无需额外调整。
共指关系捕捉
同时编码段落中的所有句子,能够捕捉句子之间的共指关系,提供更准确的上下文剪枝。
模型能力
文本重排序
上下文剪枝
问答优化
使用案例
问答系统
维基百科问答
在维基百科文章中剪枝无关句子,提高问答准确性。
减少上下文噪声,加速生成过程。
检索增强生成
LLM上下文优化
为大语言模型(LLM)提供剪枝后的上下文,减少无关信息干扰。
提高生成效率和质量。
🚀 Provence-reranker模型卡片
Provence是一款轻量级的上下文修剪模型,专为检索增强生成而设计,尤其针对问答场景进行了优化。给定用户问题和检索到的段落,Provence能够从段落中移除与用户问题无关的句子。这一特性以即插即用的方式适用于任何大语言模型(LLM),不仅加快了生成速度,还减少了上下文噪声。
- 论文:https://arxiv.org/abs/2501.16214,已被ICLR 2025接收
- 博客文章:https://huggingface.co/blog/nadiinchi/provence
- 开发者:Naver Labs Europe
- 许可证:CC BY - NC 4.0
- 模型:
provence-reranker-debertav3-v1
(用于修剪和重新排序检索到的相关上下文的Provence模型) - 骨干模型:DeBERTav3 - reranker(基于DeBERTa - v3 - large训练)
- 模型大小:4.3亿参数
- 上下文长度:512个标记
🚀 快速开始
安装依赖
Provence使用nltk
,你可以通过以下命令进行安装:
pip install nltk
python -c "import nltk; nltk.download('punkt_tab')"
单问题单上下文修剪示例
from transformers import AutoModel
provence = AutoModel.from_pretrained("naver/provence-reranker-debertav3-v1", trust_remote_code=True)
context = "Shepherd’s pie. History. In early cookery books, the dish was a means of using leftover roasted meat of any kind, and the pie dish was lined on the sides and bottom with mashed potato, as well as having a mashed potato crust on top. Variations and similar dishes. Other potato-topped pies include: The modern ”Cumberland pie” is a version with either beef or lamb and a layer of bread- crumbs and cheese on top. In medieval times, and modern-day Cumbria, the pastry crust had a filling of meat with fruits and spices.. In Quebec, a varia- tion on the cottage pie is called ”Paˆte ́ chinois”. It is made with ground beef on the bottom layer, canned corn in the middle, and mashed potato on top.. The ”shepherdess pie” is a vegetarian version made without meat, or a vegan version made without meat and dairy.. In the Netherlands, a very similar dish called ”philosopher’s stew” () often adds ingredients like beans, apples, prunes, or apple sauce.. In Brazil, a dish called in refers to the fact that a manioc puree hides a layer of sun-dried meat."
question = 'What goes on the bottom of Shepherd’s pie?'
provence_output = provence.process(question, context)
# print(f"Provence Output: {provence_output}")
# Provence Output: {'reranking_score': 3.022725, pruned_context': 'In early cookery books, the dish was a means of using leftover roasted meat of any kind, and the pie dish was lined on the sides and bottom with mashed potato, as well as having a mashed potato crust on top.']]
批量处理
你还可以传入问题列表和上下文列表(每个问题对应多个上下文)进行批量处理。
保留标题
设置always_select_title=True
将保留第一句 “Shepherd’s pie”。这对于维基百科文章特别有用,因为标题通常有助于理解上下文。更多关于标题定义的详细信息如下:
provence_output = provence.process(question, context, always_select_title=True)
# print(f"Provence Output: {provence_output}")
# Provence Output: {'reranking_score': 3.022725, pruned_context': 'Shepherd’s pie. In early cookery books, the dish was a means of using leftover roasted meat of any kind, and the pie dish was lined on the sides and bottom with mashed potato, as well as having a mashed potato crust on top.']]
✨ 主要特性
- 联合编码句子:Provence对段落中的所有句子进行联合编码,这使得它能够捕捉句子之间的指代关系,从而更准确地修剪上下文。
- 自动检测保留句子数量:Provence根据阈值自动检测要保留的句子数量。我们发现默认阈值在各种领域都表现良好,但也可以根据具体用例进一步调整。
- 跨领域鲁棒性:Provence在多样化的MS Marco和Natural Questions数据组合上进行训练,因此对各种领域具有鲁棒性。
- 与任何LLM兼容:Provence可以直接与任何大语言模型配合使用。
💻 使用示例
基础用法
from transformers import AutoModel
provence = AutoModel.from_pretrained("naver/provence-reranker-debertav3-v1", trust_remote_code=True)
context = "Shepherd’s pie. History. In early cookery books, the dish was a means of using leftover roasted meat of any kind, and the pie dish was lined on the sides and bottom with mashed potato, as well as having a mashed potato crust on top. Variations and similar dishes. Other potato-topped pies include: The modern ”Cumberland pie” is a version with either beef or lamb and a layer of bread- crumbs and cheese on top. In medieval times, and modern-day Cumbria, the pastry crust had a filling of meat with fruits and spices.. In Quebec, a varia- tion on the cottage pie is called ”Paˆte ́ chinois”. It is made with ground beef on the bottom layer, canned corn in the middle, and mashed potato on top.. The ”shepherdess pie” is a vegetarian version made without meat, or a vegan version made without meat and dairy.. In the Netherlands, a very similar dish called ”philosopher’s stew” () often adds ingredients like beans, apples, prunes, or apple sauce.. In Brazil, a dish called in refers to the fact that a manioc puree hides a layer of sun-dried meat."
question = 'What goes on the bottom of Shepherd’s pie?'
provence_output = provence.process(question, context)
高级用法
# 批量处理示例,传入问题列表和上下文列表
questions = ['What goes on the bottom of Shepherd’s pie?', 'Another question']
contexts = [
"Shepherd’s pie. History. In early cookery books, the dish was a means of using leftover roasted meat of any kind, and the pie dish was lined on the sides and bottom with mashed potato, as well as having a mashed potato crust on top. Variations and similar dishes. Other potato-topped pies include: The modern ”Cumberland pie” is a version with either beef or lamb and a layer of bread- crumbs and cheese on top. In medieval times, and modern-day Cumbria, the pastry crust had a filling of meat with fruits and spices.. In Quebec, a varia- tion on the cottage pie is called ”Paˆte ́ chinois”. It is made with ground beef on the bottom layer, canned corn in the middle, and mashed potato on top.. The ”shepherdess pie” is a vegetarian version made without meat, or a vegan version made without meat and dairy.. In the Netherlands, a very similar dish called ”philosopher’s stew” () often adds ingredients like beans, apples, prunes, or apple sauce.. In Brazil, a dish called in refers to the fact that a manioc puree hides a layer of sun-dried meat.",
"Another context"
]
provence_output = provence.process(questions, contexts)
📚 详细文档
模型接口
process
函数的接口如下:
参数 | 类型 | 详情 |
---|---|---|
question |
Union[List[str], str] |
输入问题(单个字符串)或问题列表(用于批量处理) |
context |
Union[List[List[str]], str] |
要修剪的上下文。可以是单个字符串(单个问题的情况),也可以是上下文列表(每个问题对应多个上下文),contexts 的长度应等于questions 的长度 |
title |
Optional[Union[List[List[str]], str]] ,默认值: “first_sentence” |
定义标题的可选参数。如果title = first_sentence ,则假设每个上下文的第一句为标题。如果title = None ,则假设未提供标题。标题也可以作为字符串列表的列表传入,其形状应与上下文相同。仅当always_select_title = True 时使用标题 |
threshold |
float, ∈ [0, 1] ,默认值: 0.1 |
上下文修剪的阈值。我们建议使用0.1进行更保守的修剪(无性能下降或最低性能下降),使用0.5进行更高的压缩,但该值可以进一步调整以满足特定用例的要求 |
always_select_title |
bool ,默认值: True |
如果为True,每次模型选择非空句子集合时,第一句(标题)将被包含在选择中。这对于维基百科段落等很重要,以便为后续句子提供适当的上下文 |
batch_size |
int ,默认值: 32 |
批量大小 |
reorder |
bool ,默认值: False |
如果为True,每个问题的上下文将根据计算的问题 - 段落相关性得分重新排序。如果为False,将保留用户提供的上下文原始顺序 |
top_k |
int ,默认值: 5 |
如果reorder = True ,指定每个问题要保留的排名最高的段落数量 |
enable_warnings |
bool ,默认值: True |
用户是否希望打印有关模型使用的警告信息,例如上下文或问题过长 |
模型详情
- 输入:用户问题(例如,一个句子) + 检索到的上下文段落(例如,一个段落)
- 输出:修剪后的上下文段落(即移除了无关句子) + 相关性得分(可用于重新排序)
- 模型架构:该模型基于DeBERTav3 - reranker初始化,并通过两个目标进行微调:(1) 输出可用于修剪无关句子的二进制掩码;(2) 保留初始的重新排序能力。
- 训练数据:MS Marco(文档) + NQ训练集,使用LLama - 3 - 8B对要保留的句子进行合成银标签标注。
- 支持语言:英语
- 上下文长度:512个标记(与预训练的DeBERTa模型相似)
- 评估:我们在来自不同领域的7个数据集上对Provence进行评估,包括维基百科、生物医学数据、课程大纲和新闻。评估是在仅在MS Marco数据上训练的模型上进行的。我们发现Provence能够在所有领域修剪无关句子,且性能下降很小或无下降,并且在帕累托前沿(图的右上角)上优于现有的基线模型。
更多分析请查看论文!
📄 许可证
本作品采用CC BY - NC 4.0许可证。
🔗 引用
@misc{chirkova2025provenceefficientrobustcontext,
title={Provence: efficient and robust context pruning for retrieval-augmented generation},
author={Nadezhda Chirkova and Thibault Formal and Vassilina Nikoulina and Stéphane Clinchant},
year={2025},
eprint={2501.16214},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2501.16214},
}
🙏 致谢
该模型由Naver Labs Europe训练。
团队成员
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98