说明文档
Snowflake 的 Arctic-embed-m-v2.0
<h4 align="center"> <p> <a href=#news>新闻</a> | <a href=#models>模型</a> | <a href=#usage>使用</a> | <a href="#evaluation">评估</a> | <a href="#contact">联系</a> | <a href="#faq">常见问题</a> <a href="#license">许可证</a> | <a href="#acknowledgement">致谢</a> <p> </h4>
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=d5cb84e7-4b3a-4d82-85a1-19ec3721c447" />
新闻
- 2024/12/11: 发布技术报告
- 2024/12/04: 发布snowflake-arctic-embed-l-v2.0和snowflake-arctic-embed-m-v2.0,这是我们专门针对多语言工作负载设计的新一代模型。
模型
Snowflake arctic-embed-m-v2.0 是 Snowflake 发布的嵌入模型系列中的最新成员,在检索性能和推理效率方面进行了优化。 Arctic Embed 2.0 为多语言嵌入模型树立了新标准,在不牺牲英文性能的前提下实现了高质量的多语言文本检索。 Arctic Embed 2.0 采用宽松的 Apache 2.0 许可证发布,非常适合需要可靠的企业级多语言搜索和大规模检索的应用场景。
主要特点:
-
无妥协的多语言支持:在英文和非英文检索方面表现出色,在 MTEB Retrieval、CLEF 和 MIRACL 等基准测试中优于领先的开源和专有模型。
-
推理效率高:其 113M 非嵌入参数推理速度快、效率高,适用于任何规模。
-
压缩友好:通过使用套娃表征学习(Matryoshka Representation Learning,MRL)和量化感知嵌入训练,能够使用小至 128 字节/向量的嵌入实现高质量检索。请注意,与我们的 v1.5 模型一样,此模型的 MRL 为 256 维,高质量的 128 字节压缩是通过 4 位量化实现的(例如使用
pq256x4fs快速扫描 FAISS 索引或使用随 1.5 模型发布的示例代码)。 -
长上下文支持:arctic-embed-m-v2.0 基于 GTE-multilingual-base,通过使用 RoPE 可以支持最高 8192 的上下文窗口。
质量基准
与大多数其他开源模型不同,Arctic-embed-m-v2.0 在英文(通过 MTEB Retrieval)和多语言(通过 MIRACL 和 CLEF)方面都表现出色。 您不再需要支持多个模型来赋能高质量的英文和多语言检索。以下所有数字都是所讨论数据集的平均 NDCG@10。
| 模型名称 | # 参数 | # 非嵌入参数 | # 维度 | BEIR (15) | MIRACL (4) | CLEF (Focused) | CLEF (Full) |
|---|---|---|---|---|---|---|---|
| snowflake-arctic-m-v2.0 | 305M | 113M | 768 | 55.4 | 55.2 | 51.7 | 53.9 |
| snowflake-arctic-m | 109M | 86M | 768 | 54.9 | 24.9 | 34.4 | 29.1 |
| me5 base | 560M | 303M | 1024 | 51.4 | 54.0 | 43.0 | 34.6 |
| bge-m3 (BAAI) | 568M | 303M | 1024 | 48.8 | 56.8 | 40.8 | 41.3 |
| gte (Alibaba) | 305M | 113M | 768 | 51.1 | 52.3 | 47.7 | 53.1 |
除了高质量的检索能力之外,arctic 生成的嵌入还易于压缩。通过使用 MRL 进行向量截断,可以将向量大小减少 3 倍,而质量仅下降约 3%。 将 MRL 处理后的向量与向量压缩(Int4)结合使用,可以实现每个文档 128 字节的检索能力。
| 模型 | BEIR (15) | 相对性能 | MIRACL (4) | 相对性能 | CLEF (5) | 相对性能 | CLEF (Full) | 相对性能 | |
|---|---|---|---|---|---|---|---|---|---|
| snowflake-arctic-m-v2.0 | 768 | 55.4 | 不适用 | 55.2 | 不适用 | 51.7 | 不适用 | 53.9 | 不适用 |
| snowflake-arctic-m-v2.0 | 256 | 54.4 | -1.81% | 54.0 | -2.17% | 50.6 | -2.13% | 52.3 | -3.06% |
使用方法
使用 Sentence Transformers
from sentence_transformers import SentenceTransformer
# 加载模型
model_name = 'Snowflake/snowflake-arctic-embed-m-v2.0'
model = SentenceTransformer(model_name, trust_remote_code=True)
# 定义查询和文档
queries = ['what is snowflake?', 'Where can I get the best tacos?']
documents = ['The Data Cloud!', 'Mexico City of Course!']
# 计算嵌入:使用 `prompt_name="query"` 来编码查询!
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)
# 计算余弦相似度分数
scores = model.similarity(query_embeddings, document_embeddings)
# 输出结果
for query, query_scores in zip(queries, scores):
doc_score_pairs = list(zip(documents, query_scores))
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
print("Query:", query)
for document, score in doc_score_pairs:
print(score, document)
使用 Huggingface Transformers
您可以使用 transformers 包来使用 Snowflake 的 arctic-embed 模型,如下所示。为了获得最佳的检索质量,请使用 CLS token 对每个文本部分进行嵌入,并仅在查询上使用以下查询前缀。
import torch
from transformers import AutoModel, AutoTokenizer
model_name = 'Snowflake/snowflake-arctic-embed-m-v2.0'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name, add_pooling_layer=False, trust_remote_code=True)
model.eval()
query_prefix = 'query: '
queries = ['what is snowflake?', 'Where can I get the best tacos?']
queries_with_prefix = ["{}{}".format(query_prefix, i) for i in queries]
query_tokens = tokenizer(queries_with_prefix, padding=True, truncation=True, return_tensors='pt', max_length=8192)
documents = ['The Data Cloud!', 'Mexico City of Course!']
document_tokens = tokenizer(documents, padding=True, truncation=True, return_tensors='pt', max_length=8192)
# 计算 token 嵌入
with torch.no_grad():
query_embeddings = model(**query_tokens)[0][:, 0]
document_embeddings = model(**document_tokens)[0][:, 0]
# 归一化嵌入
query_embeddings = torch.nn.functional.normalize(query_embeddings, p=2, dim=1)
document_embeddings = torch.nn.functional.normalize(document_embeddings, p=2, dim=1)
scores = torch.mm(query_embeddings, document_embeddings.transpose(0, 1))
for query, query_scores in zip(queries, scores):
doc_score_pairs = list(zip(documents, query_scores))
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
#输出段落和分数
print("Query:", query)
for document, score in doc_score_pairs:
print(score, document)
使用 Huggingface Transformers.js
如果您还没有安装,可以从 NPM 安装 Transformers.js JavaScript 库:
npm i @huggingface/transformers
然后您可以按如下方式使用该模型进行检索:
import { pipeline, dot } from '@huggingface/transformers';
// 创建特征提取管道
const extractor = await pipeline('feature-extraction', 'Snowflake/snowflake-arctic-embed-m-v2.0');
// 生成句子嵌入
const sentences = [
'query: what is snowflake?',
'The Data Cloud!',
'Mexico City of Course!',
]
const output = await extractor(sentences, { normalize: true, pooling: 'cls' });
// 计算相似度分数
const [source_embeddings, ...document_embeddings ] = output.tolist();
const similarities = document_embeddings.map(x => dot(source_embeddings, x));
console.log(similarities); // [0.32719788157046004, 0.06960141111667434]
联系方式
如果您对此项目有任何问题或建议,欢迎提交 issue 或 pull request。 您也可以发送电子邮件给 Daniel Campos(daniel.campos@snowflake.com)。
许可证
Arctic 采用 Apache-2 许可证。发布的模型可免费用于商业目的。
Snowflake/snowflake-arctic-embed-m-v2.0
作者 Snowflake
创建时间: 2024-11-08 16:52:25+00:00
更新时间: 2025-04-24 17:37:05+00:00
在 Hugging Face 上查看