Bmretriever 7B
模型简介
该模型基于论文《BMRetriever:将大语言模型调优为更优的生物医学文本检索器》所述方法进行微调,旨在提升生物医学领域的信息检索效率和质量。
模型特点
生物医学领域优化
专门针对医学和生物学领域的文本检索任务进行微调,提升相关领域的检索效果。
大语言模型支持
基于70亿参数的大语言模型,具备强大的语义理解能力。
多源数据训练
使用包括医学教材、PubMed文献、StatPearls医学百科等多种生物医学数据源进行训练。
模型能力
生物医学文本检索
医学文献相关性评估
科学论断支持性文献查找
使用案例
医学研究
医学论断验证
检索支持或反驳特定医学论断的相关文献
高效找到相关性高的支持或反驳证据
生物医学信息检索
专业文献检索
在大量生物医学文献中快速找到相关内容
提高研究人员获取相关文献的效率
🚀 BMRetriever-7B模型
本模型是按照论文《BMRetriever: Tuning Large Language Models as Better Biomedical Text Retrievers》中描述的方法进行微调的。相关的GitHub仓库可在 此处 查看。
该模型拥有70亿个参数,详细信息请参阅论文 链接。
🚀 快速开始
本模型可通过HuggingFace的transformers库加载预训练模型,以下是详细的使用步骤。
📦 安装指南
使用前请确保已安装HuggingFace的transformers库,若未安装,可使用以下命令进行安装:
pip install transformers
💻 使用示例
基础用法
通过HuggingFace的transformers库加载预训练模型:
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("BMRetriever/BMRetriever-7B")
tokenizer = AutoTokenizer.from_pretrained("BMRetriever/BMRetriever-7B")
高级用法
获取不同句子的嵌入表示,并计算句子之间的相似度得分:
import torch
import torch.nn.functional as F
from torch import Tensor
from transformers import AutoTokenizer, AutoModel
def last_token_pool(last_hidden_states: Tensor,
attention_mask: Tensor) -> Tensor:
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
if left_padding:
embedding = last_hidden[:, -1]
else:
sequence_lengths = attention_mask.sum(dim=1) - 1
batch_size = last_hidden.shape[0]
embedding = last_hidden[torch.arange(batch_size, device=last_hidden.device), sequence_lengths]
return embedding
def get_detailed_instruct_query(task_description: str, query: str) -> str:
return f'{task_description}\nQuery: {query}'
def get_detailed_instruct_passage(passage: str) -> str:
return f'Represent this passage\npassage: {passage}'
# Each query must come with a one-sentence instruction that describes the task
task = 'Given a scientific claim, retrieve documents that support or refute the claim'
queries = [
get_detailed_instruct_query(task, 'Cis-acting lncRNAs control the expression of genes that are positioned in the vicinity of their transcription sites.'),
get_detailed_instruct_query(task, 'Forkhead 0 (fox0) transcription factors are involved in apoptosis.')
]
# No need to add instruction for retrieval documents
documents = [
get_detailed_instruct_passage("Gene regulation by the act of long non-coding RNA transcription Long non-protein-coding RNAs (lncRNAs) are proposed to be the largest transcript class in the mouse and human transcriptomes. Two important questions are whether all lncRNAs are functional and how they could exert a function. Several lncRNAs have been shown to function through their product, but this is not the only possible mode of action. In this review we focus on a role for the process of lncRNA transcription, independent of the lncRNA product, in regulating protein-coding-gene activity in cis. We discuss examples where lncRNA transcription leads to gene silencing or activation, and describe strategies to determine if the lncRNA product or its transcription causes the regulatory effect."),
get_detailed_instruct_passage("Noncoding transcription at enhancers: general principles and functional models. Mammalian genomes are extensively transcribed outside the borders of protein-coding genes. Genome-wide studies recently demonstrated that cis-regulatory genomic elements implicated in transcriptional control, such as enhancers and locus-control regions, represent major sites of extragenic noncoding transcription. Enhancer-templated transcripts provide a quantitatively small contribution to the total amount of cellular nonribosomal RNA; nevertheless, the possibility that enhancer transcription and the resulting enhancer RNAs may, in some cases, have functional roles, rather than represent mere transcriptional noise at accessible genomic regions, is supported by an increasing amount of experimental data. In this article we review the current knowledge on enhancer transcription and its functional implications.")
]
input_texts = queries + documents
max_length = 512
# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=max_length-1, padding=True, truncation=True, return_tensors='pt')
# Important! Adding EOS token at the end
batch_dict['input_ids'] = [input_ids + [tokenizer.eos_token_id] for input_ids in batch_dict['input_ids']]
batch_dict = tokenizer.pad(batch_dict, padding=True, return_attention_mask=True, return_tensors='pt').to("cuda")
model.eval()
with torch.no_grad():
outputs = model(**batch_dict)
embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
scores = (embeddings[:2] @ embeddings[2:].T)
print(scores.tolist())
📄 许可证
本项目采用MIT许可证。
📚 引用
如果您觉得本仓库对您有帮助,请考虑引用相应的论文,感谢!
@misc{xu2024bmretriever,
title={BMRetriever: Tuning Large Language Models as Better Biomedical Text Retrievers},
author={Ran Xu and Wenqi Shi and Yue Yu and Yuchen Zhuang and Yanqiao Zhu and May D. Wang and Joyce C. Ho and Chao Zhang and Carl Yang},
year={2024},
eprint={2404.18443},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
📋 数据集
本模型使用了以下数据集进行训练:
数据集 |
---|
MedRAG/textbooks |
MedRAG/pubmed |
MedRAG/statpearls |
mteb/raw_biorxiv |
mteb/raw_medrxiv |
ms_marco |
BMRetriever/biomed_retrieval_dataset |
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