🚀 gte-base-en-v1.5
我們推出了 gte-v1.5
系列,這是升級版的 gte
嵌入模型,支持最長達 8192 的上下文長度,同時進一步提升了模型性能。該模型基於 transformer++
編碼器 骨幹網絡(BERT + RoPE + GLU)構建。
gte-v1.5
系列在 MTEB 基準測試中,於相同模型大小類別裡取得了最先進的分數,並且在 LoCo 長上下文檢索測試中表現出色(請參考評估)。
我們還推出了 gte-Qwen1.5-7B-instruct
,這是一個最先進的指令調優多語言嵌入模型,在 MTEB 中排名第二,在 C - MTEB 中排名第一。
模型列表
🚀 快速開始
使用 Python 和 transformers
庫
使用以下代碼開始使用該模型:
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-base-en-v1.5'
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
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]
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())
⚠️ 重要提示
建議安裝 xformers
並啟用無填充(unpadding)以加速推理,詳情請參考 enable - unpadding - and - xformers。
使用 sentence-transformers
庫
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
sentences = ['That is a happy person', 'That is a very happy person']
model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
embeddings = model.encode(sentences)
print(cos_sim(embeddings[0], embeddings[1]))
使用 transformers.js
庫
import { pipeline, dot } from '@xenova/transformers';
const extractor = await pipeline('feature-extraction', 'Alibaba-NLP/gte-base-en-v1.5', {
quantized: false,
});
const sentences = [
"what is the capital of China?",
"how to implement quick sort in python?",
"Beijing",
"sorting algorithms"
]
const output = await extractor(sentences, { normalize: true, pooling: 'cls' });
const [source_embeddings, ...document_embeddings ] = output.tolist();
const similarities = document_embeddings.map(x => 100 * dot(source_embeddings, x));
console.log(similarities);
使用 Infinity
Infinity 是一個遵循 MIT 許可的 OpenAI 兼容部署服務器。
docker run --gpus all -v $PWD/data:/app/.cache -p "7997":"7997" \
michaelf34/infinity:0.0.68 \
v2 --model-id Alibaba-NLP/gte-base-en-v1.5 --revision "4c742dc2b781e4ab062a4a77f4f7cbad4bdee970" --dtype bfloat16 --batch-size 32 --device cuda --engine torch --port 7997
📚 詳細文檔
訓練數據
- 掩碼語言模型(MLM):
c4-en
- 弱監督對比預訓練(CPT):GTE 預訓練數據
- 監督對比微調:GTE 微調數據
訓練過程
為了使骨幹模型支持 8192 的上下文長度,我們採用了多階段訓練策略。模型首先在較短長度上進行初步的 MLM 預訓練,然後重新採樣數據,減少短文本的比例,並繼續進行 MLM 預訓練。
整個訓練過程如下:
- MLM - 2048:學習率 5e - 4,掩碼概率 0.3,批次大小 4096,步數 70000,RoPE 基數 10000
- MLM - 8192:學習率 5e - 5,掩碼概率 0.3,批次大小 1024,步數 20000,RoPE 基數 500000
- CPT:最大長度 512,學習率 2e - 4,批次大小 32768,步數 100000
- 微調:待完成
🔧 技術細節
MTEB 評估
其他模型的結果從 MTEB 排行榜 獲取。
gte
評估設置:mteb==1.2.0
,FP16 自動混合精度,max_length = 8192
,並將 NTK 縮放因子設置為 2(相當於 RoPE 基數 * 2)。
LoCo 評估
模型名稱 |
維度 |
序列長度 |
平均值(5) |
Qsmsum 檢索 |
SummScreen 檢索 |
Qasper 摘要檢索 |
Qasper 標題檢索 |
GovReport 檢索 |
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 |
📄 許可證
本項目遵循 Apache - 2.0 許可證。
📚 引用
如果您發現我們的論文或模型有幫助,請考慮以下引用:
@misc{zhang2024mgte,
title={mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval},
author={Xin Zhang and Yanzhao Zhang and Dingkun Long and Wen Xie and Ziqi Dai and Jialong Tang and Huan Lin and Baosong Yang and Pengjun Xie and Fei Huang and Meishan Zhang and Wenjie Li and Min Zhang},
year={2024},
eprint={2407.19669},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2407.19669},
}
@misc{li2023gte,
title={Towards General Text Embeddings with Multi-stage Contrastive Learning},
author={Zehan Li and Xin Zhang and Yanzhao Zhang and Dingkun Long and Pengjun Xie and Meishan Zhang},
year={2023},
eprint={2308.03281},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2308.03281},
}