Gte Qwen2 7B Instruct GGUF
G
Gte Qwen2 7B Instruct GGUF
由 mav23 开发
基于Qwen2架构的7B参数规模指令微调模型,专注于句子相似度计算和文本嵌入任务
下载量 118
发布时间 : 10/10/2024
模型简介
该模型是基于Qwen2架构开发的7B参数规模的指令微调模型,主要用于句子相似度计算、文本嵌入和检索任务。在MTEB基准测试中表现出色,支持多种自然语言处理任务。
模型特点
多任务性能优异
在MTEB基准测试的多种任务中表现优异,包括分类、聚类、检索等
大规模参数
7B参数规模提供了强大的语义理解能力
指令微调优化
经过指令微调,特别适合处理结构化任务
模型能力
句子相似度计算
文本分类
文本聚类
信息检索
搜索结果重排序
语义文本相似度评估
使用案例
电子商务
商品评论情感分析
分析亚马逊商品评论的情感倾向
在AmazonPolarity分类任务中达到97.5%准确率
反事实评论检测
识别亚马逊平台上的反事实评论
在AmazonCounterfactual分类任务中达到91.3%准确率
客户服务
银行业务分类
对银行客户咨询进行自动分类
在Banking77分类任务中达到87.6%准确率
学术研究
论文聚类
对arXiv和biorxiv论文进行主题聚类
在ArxivClusteringP2P任务中获得56.46 V-measure
问答系统
技术问答检索
在技术论坛中检索相似问题
在AskUbuntuDupQuestions重排序任务中达到67.58 MAP
🚀 gte-Qwen2-7B-instruct
gte-Qwen2-7B-instruct 是 gte(通用文本嵌入)模型家族的最新模型,截至 2024 年 6 月 16 日,该模型在大规模文本嵌入基准测试 MTEB 基准 的英文和中文评估中均排名 第一。
近期,通义团队 发布了通义千问 2 系列模型,我们基于 Qwen2-7B 大语言模型训练了 gte-Qwen2-7B-instruct 模型。与 gte-Qwen1.5-7B-instruct 模型相比,gte-Qwen2-7B-instruct 模型在微调阶段使用了相同的训练数据和训练策略,唯一的区别是将基础模型升级为 Qwen2-7B。考虑到通义千问 2 系列模型相较于通义千问 1.5 系列的改进,我们也可以预期嵌入模型的性能会有相应提升。
该模型包含了以下几个关键的改进:
- 集成了双向注意力机制,丰富了其上下文理解能力。
- 仅在查询端应用指令调优,以提高效率。
- 在庞大的多语言文本语料库上进行全面训练,涵盖了不同领域和场景。这种训练利用了弱监督和监督数据,确保模型适用于多种语言和广泛的下游任务。
✨ 主要特性
- 性能卓越:在 MTEB 基准测试的英文和中文评估中均排名第一,展现出强大的文本嵌入能力。
- 架构升级:基于 Qwen2-7B 基础模型,集成双向注意力机制,提升上下文理解能力。
- 指令调优:仅在查询端应用指令调优,提高效率。
- 多语言支持:在多语言文本语料库上进行训练,适用于多种语言和下游任务。
📦 安装指南
transformers>=4.39.2
flash_attn>=2.5.6
💻 使用示例
基础用法
Sentence Transformers
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Alibaba-NLP/gte-Qwen2-7B-instruct", trust_remote_code=True)
# 如果你想减少最大长度:
model.max_seq_length = 8192
queries = [
"how much protein should a female eat",
"summit define",
]
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments.",
]
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)
scores = (query_embeddings @ document_embeddings.T) * 100
print(scores.tolist())
你可以查看 config_sentence_transformers.json 以了解所有预构建的提示名称。否则,你可以使用 model.encode(queries, prompt="Instruct: ...\nQuery: "
来使用你选择的自定义提示。
Transformers
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:
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
if left_padding:
return last_hidden_states[:, -1]
else:
sequence_lengths = attention_mask.sum(dim=1) - 1
batch_size = last_hidden_states.shape[0]
return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
def get_detailed_instruct(task_description: str, query: str) -> str:
return f'Instruct: {task_description}\nQuery: {query}'
# 每个查询必须附带一个描述任务的单句指令
task = 'Given a web search query, retrieve relevant passages that answer the query'
queries = [
get_detailed_instruct(task, 'how much protein should a female eat'),
get_detailed_instruct(task, 'summit define')
]
# 检索文档无需添加指令
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
]
input_texts = queries + documents
tokenizer = AutoTokenizer.from_pretrained('Alibaba-NLP/gte-Qwen2-7B-instruct', trust_remote_code=True)
model = AutoModel.from_pretrained('Alibaba-NLP/gte-Qwen2-7B-instruct', trust_remote_code=True)
max_length = 8192
# 对输入文本进行分词
batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
# 对嵌入向量进行归一化
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:2] @ embeddings[2:].T) * 100
print(scores.tolist())
📚 详细文档
模型信息
属性 | 详情 |
---|---|
模型规模 | 7B |
嵌入维度 | 3584 |
最大输入令牌数 | 32k |
评估
MTEB & C-MTEB
你可以使用 scripts/eval_mteb.py 来复现 gte-Qwen2-7B-instruct 在 MTEB(英文)/C-MTEB(中文)上的以下结果:
模型名称 | MTEB(56) | C-MTEB(35) | MTEB-fr(26) | MTEB-pl(26) |
---|---|---|---|---|
bge-base-en-1.5 | 64.23 | - | - | - |
bge-large-en-1.5 | 63.55 | - | - | - |
gte-large-en-v1.5 | 65.39 | - | - | - |
gte-base-en-v1.5 | 64.11 | - | - | - |
mxbai-embed-large-v1 | 64.68 | - | - | - |
acge_text_embedding | - | 69.07 | - | - |
stella-mrl-large-zh-v3.5-1792d | - | 68.55 | - | - |
gte-large-zh | - | 66.72 | - | - |
multilingual-e5-base | 59.45 | 56.21 | - | - |
multilingual-e5-large | 61.50 | 58.81 | - | - |
e5-mistral-7b-instruct | 66.63 | 60.81 | - | - |
gte-Qwen1.5-7B-instruct | 67.34 | 69.52 | - | - |
NV-Embed-v1 | 69.32 | - | - | - |
gte-Qwen2-7B-instruct | 70.24 | 72.05 | 68.25 | 67.86 |
gte-Qwen2-1.5B-instruct | 67.16 | 67.65 | 66.60 | 64.04 |
GTE 模型
gte 系列模型一直发布两种类型的模型:仅编码器模型(基于 BERT 架构)和解码器模型(基于大语言模型架构)。
模型 | 语言 | 最大序列长度 | 维度 | 模型大小(内存使用,fp32) |
---|---|---|---|---|
GTE-large-zh | 中文 | 512 | 1024 | 1.25GB |
GTE-base-zh | 中文 | 512 | 512 | 0.41GB |
GTE-small-zh | 中文 | 512 | 512 | 0.12GB |
GTE-large | 英文 | 512 | 1024 | 1.25GB |
GTE-base | 英文 | 512 | 512 | 0.21GB |
GTE-small | 英文 | 512 | 384 | 0.10GB |
GTE-large-en-v1.5 | 英文 | 8192 | 1024 | 1.74GB |
GTE-base-en-v1.5 | 英文 | 8192 | 768 | 0.51GB |
GTE-Qwen1.5-7B-instruct | 多语言 | 32000 | 4096 | 26.45GB |
GTE-Qwen2-7B-instruct | 多语言 | 32000 | 3584 | 26.45GB |
GTE-Qwen2-1.5B-instruct | 多语言 | 32000 | 1536 | 6.62GB |
云 API 服务
除了开源的 GTE 系列模型外,GTE 系列模型还可在阿里云上作为商业 API 服务使用。
请注意,商业 API 背后的模型与开源模型并不完全相同。
📄 许可证
@article{li2023towards,
title={Towards general text embeddings with multi-stage contrastive learning},
author={Li, Zehan and Zhang, Xin and Zhang, Yanzhao and Long, Dingkun and Xie, Pengjun and Zhang, Meishan},
journal={arXiv preprint arXiv:2308.03281},
year={2023}
}
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