说明文档
gte-modernbert-base
我们很高兴为大家介绍 gte-modernbert 系列模型,这些模型基于最新的 ModernBERT 预训练纯编码器基础模型构建。gte-modernbert 系列模型包括文本嵌入模型和重排序模型。
gte-modernbert 模型在多个文本嵌入和文本检索评估任务中展现出与当前开源社区同类规模模型相当的竞争性能。这包括 MTEB、LoCO 和 COIR 等评估。
模型概览
- 开发团队:通义实验室,阿里巴巴集团
- 模型类型:文本嵌入
- 主要语言:英语
- 模型大小:149M
- 最大输入长度:8192 tokens
- 输出维度:768
模型列表
| 模型 | 语言 | 模型类型 | 模型大小 | 最大序列长度 | 维度 | MTEB-en | BEIR | LoCo | CoIR |
|---|---|---|---|---|---|---|---|---|---|
gte-modernbert-base |
English | 文本嵌入 | 149M | 8192 | 768 | 64.38 | 55.33 | 87.57 | 79.31 |
gte-reranker-modernbert-base |
English | 文本重排序 | 149M | 8192 | - | - | 56.19 | 90.68 | 79.99 |
使用方法
[!提示] 对于
transformers和sentence-transformers,如果您的 GPU 支持,高效的 Flash Attention 2 会在您安装flash_attn后自动使用。这不是强制要求的。pip install flash_attn
配合 transformers 使用:
# Requires transformers>=4.48.0
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
input_texts = [
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms"
]
model_path = "Alibaba-NLP/gte-modernbert-base"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path)
# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
embeddings = outputs.last_hidden_state[:, 0]
# (Optionally) normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())
# [[42.89073944091797, 71.30911254882812, 33.664554595947266]]
配合 sentence-transformers 使用:
# Requires transformers>=4.48.0
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
input_texts = [
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms"
]
model = SentenceTransformer("Alibaba-NLP/gte-modernbert-base")
embeddings = model.encode(input_texts)
print(embeddings.shape)
# (4, 768)
similarities = cos_sim(embeddings[0], embeddings[1:])
print(similarities)
# tensor([[0.4289, 0.7131, 0.3366]])
配合 transformers.js 使用:
// npm i @huggingface/transformers
import { pipeline, matmul } from "@huggingface/transformers";
// Create a feature extraction pipeline
const extractor = await pipeline(
"feature-extraction",
"Alibaba-NLP/gte-modernbert-base",
{ dtype: "fp32" }, // Supported options: "fp32", "fp16", "q8", "q4", "q4f16"
);
// Embed queries and documents
const embeddings = await extractor(
[
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms",
],
{ pooling: "cls", normalize: true },
);
// Compute similarity scores
const similarities = (await matmul(embeddings.slice([0, 1]), embeddings.slice([1, null]).transpose(1, 0))).mul(100);
console.log(similarities.tolist()); // [[42.89077377319336, 71.30916595458984, 33.66455841064453]]
此外,您还可以通过 Text Embeddings Inference (TEI) 部署 Alibaba-NLP/gte-modernbert-base:
- CPU
docker run --platform linux/amd64 \
-p 8080:80 \
-v $PWD/data:/data \
--pull always \
ghcr.io/huggingface/text-embeddings-inference:cpu-1.7 \
--model-id Alibaba-NLP/gte-modernbert-base
- GPU
docker run --gpus all \
-p 8080:80 \
-v $PWD/data:/data \
--pull always \
ghcr.io/huggingface/text-embeddings-inference:1.7 \
--model-id Alibaba-NLP/gte-modernbert-base
随后,您可以通过 OpenAI 兼容的 v1/embeddings 接口向部署的 API 发送请求(更多关于 OpenAI Embeddings API 的信息):
curl https://0.0.0.0:8080/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"input": [
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms"
],
"model": "Alibaba-NLP/gte-modernbert-base",
"encoding_format": "float"
}'
训练细节
gte-modernbert 系列模型遵循先前 GTE 模型的训练方案,唯一不同的是预训练语言模型基座从 GTE-MLM 更换为 ModernBERT。更多训练细节请参考我们的论文:mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval
评估
MTEB
其他模型的结果来自 MTEB 排行榜。由于 gte-modernbert 系列模型参数量均小于 1B,我们仅关注 MTEB 排行榜中参数量小于 1B 的模型结果。
| 模型名称 | 参数量 (M) | 维度 | 序列长度 | 平均 (56) | 分类 (12) | 聚类 (11) | 文本对分类 (3) | 重排 (4) | 检索 (15) | 语义相似度 (10) | 摘要 (1) |
|---|---|---|---|---|---|---|---|---|---|---|---|
| mxbai-embed-large-v1 | 335 | 1024 | 512 | 64.68 | 75.64 | 46.71 | 87.2 | 60.11 | 54.39 | 85 | 32.71 |
| multilingual-e5-large-instruct | 560 | 1024 | 514 | 64.41 | 77.56 | 47.1 | 86.19 | 58.58 | 52.47 | 84.78 | 30.39 |
| bge-large-en-v1.5 | 335 | 1024 | 512 | 64.23 | 75.97 | 46.08 | 87.12 | 60.03 | 54.29 | 83.11 | 31.61 |
| gte-base-en-v1.5 | 137 | 768 | 8192 | 64.11 | 77.17 | 46.82 | 85.33 | 57.66 | 54.09 | 81.97 | 31.17 |
| bge-base-en-v1.5 | 109 | 768 | 512 | 63.55 | 75.53 | 45.77 | 86.55 | 58.86 | 53.25 | 82.4 | 31.07 |
| gte-large-en-v1.5 | 409 | 1024 | 8192 | 65.39 | 77.75 | 47.95 | 84.63 | 58.50 | 57.91 | 81.43 | 30.91 |
| modernbert-embed-base | 149 | 768 | 8192 | 62.62 | 74.31 | 44.98 | 83.96 | 56.42 | 52.89 | 81.78 | 31.39 |
| nomic-embed-text-v1.5 | 768 | 8192 | 62.28 | 73.55 | 43.93 | 84.61 | 55.78 | 53.01 | 81.94 | 30.4 | |
| gte-multilingual-base | 305 | 768 | 8192 | 61.4 | 70.89 | 44.31 | 84.24 | 57.47 | 51.08 | 82.11 | 30.58 |
| jina-embeddings-v3 | 572 | 1024 | 8192 | 65.51 | 82.58 | 45.21 | 84.01 | 58.13 | 53.88 | 85.81 | 29.71 |
| gte-modernbert-base | 149 | 768 | 8192 | 64.38 | 76.99 | 46.47 | 85.93 | 59.24 | 55.33 | 81.57 | 30.68 |
LoCo(长文档检索)(NDCG@10)
| 模型名称 | 维度 | 序列长度 | 平均 (5) | Qmsum检索 | SummScreen检索 | Qasper摘要检索 | Qasper标题检索 | 政务报告检索 |
|---|---|---|---|---|---|---|---|---|
| gte-qwen1.5-7b | 4096 | 32768 | 87.57 | 49.37 | 93.10 | 99.67 | 97.54 | 98.21 |
| gte-large-v1.5 | 1024 | 8192 | 86.71 | 44.55 | 92.61 | 99.82 | 97.81 | 98.74 |
| gte-base-v1.5 | 768 | 8192 | 87.44 | 49.91 | 91.78 | 99.82 | 97.13 | 98.58 |
| gte-modernbert-base | 768 | 8192 | 88.88 | 54.45 | 93.00 | 99.82 | 98.03 | 98.70 |
| gte-reranker-modernbert-base | - | 8192 | 90.68 | 70.86 | 94.06 | 99.73 | 99.11 | 89.67 |
COIR(代码检索任务)(NDCG@10)
| 模型名称 | 维度 | 序列长度 | 平均(20) | CodeSearchNet-ccr-go | CodeSearchNet-ccr-java | CodeSearchNet-ccr-javascript | CodeSearchNet-ccr-php | CodeSearchNet-ccr-python | CodeSearchNet-ccr-ruby | CodeSearchNet-go | CodeSearchNet-java | CodeSearchNet-javascript | CodeSearchNet-php | CodeSearchNet-python | CodeSearchNet-ruby | apps | codefeedback-mt | codefeedback-st | codetrans-contest | codetrans-dl | cosqa | stackoverflow-qa | synthetic-text2sql |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| gte-modernbert-base | 768 | 8192 | 79.31 | 94.15 | 93.57 | 94.27 | 91.51 | 93.93 | 90.63 | 88.32 | 83.27 | 76.05 | 85.12 | 88.16 | 77.59 | 57.54 | 82.34 | 85.95 | 71.89 | 35.46 | 43.47 | 91.2 | 61.87 |
| gte-reranker-modernbert-base | - | 8192 | 79.99 | 96.43 | 96.88 | 98.32 | 91.81 | 97.7 | 91.96 | 88.81 | 79.71 | 76.27 | 89.39 | 98.37 | 84.11 | 47.57 | 83.37 | 88.91 | 49.66 | 36.36 | 44.37 | 89.58 | 64.21 |
BEIR (NDCG@10)
| 模型名称 | 维度 | 序列长度 | 平均(15) | ArguAna | ClimateFEVER | CQADupstackAndroid检索 | DBPedia | FEVER | FiQA2018 | HotpotQA | MSMARCO | NFCorpus | NQ | Quora检索 | SCIDOCS | SciFact | Touche2020 | TRECCOVID |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| gte-modernbert-base | 768 | 8192 | 55.33 | 72.68 | 37.74 | 42.63 | 41.79 | 91.03 | 48.81 | 69.47 | 40.9 | 36.44 | 57.62 | 88.55 | 21.29 | 77.4 | 21.68 | 81.95 |
| gte-reranker-modernbert-base | - | 8192 | 56.73 | 69.03 | 37.79 | 44.68 | 47.23 | 94.54 | 49.81 | 78.16 | 45.38 | 30.69 | 64.57 | 87.77 | 20.60 | 73.57 | 27.36 | 79.89 |
招聘
通义实验室现招聘 研究实习生 和 全职研究员 加入我们的团队。我们寻找对表示学习、基于 LLM 的信息检索、检索增强生成(RAG)以及基于 Agent 的系统充满热情的专业人才。我们的团队位于充满活力的 北京 和 杭州。如果你对工作充满好奇并渴望通过自己的努力产生有意义的影响,我们很乐意收到你的简历。请将你的简历及简要介绍发送至 <a href="mailto:dingkun.ldk@alibaba-inc.com">dingkun.ldk@alibaba-inc.com</a>。
引用
如果你发现我们的论文或模型对你有帮助,欢迎引用我们。
@inproceedings{zhang2024mgte,
title={mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval},
author={Zhang, Xin and Zhang, Yanzhao and Long, Dingkun and Xie, Wen and Dai, Ziqi and Tang, Jialong and Lin, Huan and Yang, Baosong and Xie, Pengjun and Huang, Fei and others},
booktitle={Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing: Industry Track},
pages={1393--1412},
year={2024}
}
@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}
}
Alibaba-NLP/gte-modernbert-base
作者 Alibaba-NLP
创建时间: 2025-01-20 03:03:48+00:00
更新时间: 2025-07-04 10:03:26+00:00
在 Hugging Face 上查看