基础模型:
- meta-llama/Llama-3.1-8B
语言:
- 英语
许可证: cc-by-nc-4.0
任务标签: 特征提取
库名称: transformers
标签:
- 句子转换器
模型概述
ReasonIR-8B是首个专为通用推理任务训练的检索模型,在BRIGHT(推理密集型检索)基准上实现了最先进的检索性能。
当用于检索增强生成(RAG)时,ReasonIR-8B还在MMLU和GPQA基准上带来了显著提升。
- 论文: https://arxiv.org/abs/2504.20595
- 代码库: https://github.com/facebookresearch/ReasonIR
- 数据: https://huggingface.co/datasets/reasonir/reasonir-data
使用方法
请确保先安装transformers>=4.47.0
!
Transformers
from transformers import AutoModel
model = AutoModel.from_pretrained("reasonir/ReasonIR-8B", torch_dtype="auto", trust_remote_code=True)
model = model.to("cuda")
model.eval()
query = "敏捷的棕色狐狸跳过了懒惰的狗。"
document = "敏捷的棕色狐狸跳过了懒惰的狗。"
query_instruction = ""
doc_instruction = ""
query_emb = model.encode(query, instruction=query_instruction)
doc_emb = model.encode(document, instruction=doc_instruction)
sim = query_emb @ doc_emb.T
使用AutoModel
时,需要注意:
- 包含
trust_remote_code=True
以确保使用我们自定义的双向编码架构。
- 使用
torch_dtype="auto"
以激活bf16
(默认情况下torch会使用fp32
)。
Sentence Transformers
除了Transformers,你也可以使用Sentence Transformers来使用此模型
from sentence_transformers import SentenceTransformer
model_kwargs = {"torch_dtype": "auto"}
model = SentenceTransformer("reasonir/ReasonIR-8B", trust_remote_code=True, model_kwargs=model_kwargs)
query = "敏捷的棕色狐狸跳过了懒惰的狗。"
document = "敏捷的棕色狐狸跳过了懒惰的狗。"
query_instruction = ""
doc_instruction = ""
query_emb = model.encode(query, prompt=query_instruction)
doc_emb = model.encode(document, prompt=doc_instruction)
sim = model.similarity(query_emb, doc_emb)
同样需要包含trust_remote_code=True
和torch_dtype="auto"
,如前所述。
[!注意]
由于模型如何转换为bfloat16
数据类型,使用SentenceTransformer时会有一些非常轻微的浮点数差异,但通常不会影响结果。
我们感谢@tomaarsen改进了SentenceTransformer的集成并分析了浮点数差异的原因!
引用
@article{shao2025reasonir,
title={ReasonIR: 训练用于推理任务的检索模型},
author={Rulin Shao and Rui Qiao and Varsha Kishore and Niklas Muennighoff and Xi Victoria Lin and Daniela Rus and Bryan Kian Hsiang Low and Sewon Min and Wen-tau Yih and Pang Wei Koh and Luke Zettlemoyer},
year={2025},
journal={arXiv preprint arXiv:2504.20595},
url={https://arxiv.org/abs/2504.20595},
}