ONNX 模型库
返回模型

说明文档

<!-- TODO: add evaluation results here --> <br><br>

<p align="center"> <img src="https://huggingface.co/datasets/jinaai/documentation-images/resolve/main/logo.webp" alt="Jina AI: Your Search Foundation, Supercharged!" width="150px"> </p>

<p align="center"> <b>由 <a href="https://jina.ai/"><b>Jina AI</b></a> 训练的文字嵌入模型。</b> </p>

快速开始

使用 jina-embeddings-v2-base-de 最简单的方法是使用 Jina AI 的 Embedding API

预期用途与模型信息

jina-embeddings-v2-base-de 是一款支持 8192 序列长度 的德语/英语双语文字嵌入模型。 它基于 BERT 架构(JinaBERT),该架构支持 ALiBi 的对称双向变体,可实现更长的序列长度。 我们设计它是为了在单语和跨语言应用中实现高性能,并专门针对混合德语-英语输入进行训练,不产生偏差。 此外,我们还提供以下嵌入模型:

jina-embeddings-v2-base-de ist ein zweisprachiges Text Embedding Modell für Deutsch und Englisch, welches Texteingaben mit einer Länge von bis zu 8192 Token unterstützt. Es basiert auf der adaptierten Bert-Modell-Architektur JinaBERT, welche mithilfe einer symmetrische Variante von ALiBi längere Eingabetexte erlaubt. Wir haben, das Model für hohe Performance in einsprachigen und cross-lingual Anwendungen entwickelt und speziell darauf trainiert, gemischte deutsch-englische Eingaben ohne einen Bias zu kodieren. Des Weiteren stellen wir folgende Embedding-Modelle bereit:

数据与参数

数据和训练细节详见此技术报告

使用方法

<details><summary>集成模型时请使用 mean pooling(平均池化)。</summary> <p>

为什么要用 mean pooling?

mean pooling(平均池化)会从模型输出中获取所有 token 嵌入,并在句子/段落级别进行平均。 已被证明是生成高质量句子嵌入的最有效方法。 我们提供了一个 encode 函数来处理这个问题。

但是,如果您不想使用默认的 encode 函数:

import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel

def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0]
    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)

sentences = ['How is the weather today?', 'What is the current weather like today?']

tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-embeddings-v2-base-de')
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-de', trust_remote_code=True, torch_dtype=torch.bfloat16)

encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')

with torch.no_grad():
    model_output = model(**encoded_input)

embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
embeddings = F.normalize(embeddings, p=2, dim=1)

</p> </details>

您可以直接从 transformers 包使用 Jina 嵌入模型。

!pip install transformers
import torch
from transformers import AutoModel
from numpy.linalg import norm

cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-de', trust_remote_code=True, torch_dtype=torch.bfloat16)
embeddings = model.encode(['How is the weather today?', 'Wie ist das Wetter heute?'])
print(cos_sim(embeddings[0], embeddings[1]))

如果您只想处理较短的序列,例如 2k,可以将 max_length 参数传递给 encode 函数:

embeddings = model.encode(
    ['Very long ... document'],
    max_length=2048
)

使用最新版本(v2.3.0)的 sentence-transformers 也支持 Jina 嵌入(请确保您已登录 huggingface):

!pip install -U sentence-transformers
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim

model = SentenceTransformer(
    "jinaai/jina-embeddings-v2-base-de", # 切换为 en/zh 可用于英语或中文
    trust_remote_code=True
)

# 控制您的输入序列长度,最高可达 8192
model.max_seq_length = 1024

embeddings = model.encode([
    'How is the weather today?',
    'Wie ist das Wetter heute?'
])
print(cos_sim(embeddings[0], embeddings[1]))

使用 Transformers 包的替代方案

  1. 托管 SaaS:在 Jina AI 的 Embedding API 上使用免费密钥开始使用。
  2. 私有化高性能部署:从我们的模型套件中选择并部署在 AWS Sagemaker 上。

基准测试结果

我们已在 MTEB 基准测试 上所有可用的德语和英语评估任务上评估了我们的双语模型。此外,我们还在其他德语、英语和多语言模型的额外德语评估任务上对该模型进行了评估:

<img src="de_evaluation_results.png" width="780px">

使用 Jina 嵌入进行 RAG

根据 LLamaIndex 的最新博客文章:

总之,为了在命中率和 MRR 方面达到最佳性能,OpenAI 或 JinaAI-Base 嵌入与 CohereRerank/bge-reranker-large 重新排序器的组合表现突出。

<img src="https://miro.medium.com/v2/resize:fit:4800/format:webp/1*ZP2RVejCZovF3FDCg-Bx3A.png" width="780px">

联系方式

加入我们的 Discord 社区,与其他社区成员交流想法。

引用

如果您在研究中发现 Jina 嵌入很有用,请引用以下论文:

@article{mohr2024multi,
  title={Multi-Task Contrastive Learning for 8192-Token Bilingual Text Embeddings},
  author={Mohr, Isabelle and Krimmel, Markus and Sturua, Saba and Akram, Mohammad Kalim and Koukounas, Andreas and G{\\"u}nther, Michael and Mastrapas, Georgios and Ravishankar, Vinit and Mart{\'\i}nez, Joan Fontanals and Wang, Feng and others},
  journal={arXiv preprint arXiv:2402.17016},
  year={2024}
}

jinaai/jina-embeddings-v2-base-de

作者 jinaai

feature-extraction sentence-transformers
↓ 931.5K ♥ 82

创建时间: 2024-01-12 14:04:50+00:00

更新时间: 2025-01-06 16:26:47+00:00

在 Hugging Face 上查看

文件 (18)

.gitattributes
1_Pooling/config.json
README.md
config.json
config_sentence_transformers.json
de_evaluation_results.png
merges.txt
model.safetensors
modules.json
onnx/model.onnx ONNX
onnx/model_fp16.onnx ONNX
onnx/model_quantized.onnx ONNX
pytorch_model.bin
sentence_bert_config.json
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.json