C
CICC/jina-embeddings-v2-base-es
模型介绍文件和版本分析
下载使用量0



由 Jina AI 训练的文本嵌入模型。

快速开始

开始使用 jina-embeddings-v2-base-es 最简单的方法是使用 Jina AI 的 嵌入 API。

预期用途与模型信息

jina-embeddings-v2-base-es 是一个支持 8192 序列长度的西班牙语/英语双语文本嵌入模型。 它基于 BERT 架构(JinaBERT),该架构支持 ALiBi 的对称双向变体,以实现更长的序列长度。 我们将其设计为在单语和跨语言应用中具有高性能,并对其进行专门训练以支持西班牙语-英语混合输入,且不带偏向性。 此外,我们还提供以下嵌入模型:

jina-embeddings-v2-base-es 是一个支持 8192 序列长度的英语/西班牙语双语文本嵌入模型。 它基于 BERT 架构(JinaBERT),该架构集成了 ALiBi 的对称双向变体,以支持更长的序列长度。 我们设计此模型旨在单语和双语应用中实现高性能,并且经过专门训练以支持西班牙语和英语的混合输入,且不带偏向性。 此外,我们提供以下嵌入模型:

  • jina-embeddings-v2-base-es: 西班牙语-英语双语嵌入 (当前模型)。

数据与参数

数据和训练详情在本技术报告中描述。

用法

集成模型时请应用均值池化。

为什么使用均值池化?

均值池化 从模型输出中获取所有标记嵌入,并在句子/段落级别对它们进行平均。 事实证明,这是生成高质量句子嵌入的最有效方法。 我们提供了一个 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-es')
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-es', trust_remote_code=True)

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)

您可以直接通过 transformers 包使用 Jina Embedding 模型:

!pip install transformers
# coding = utf-8
import os
import torch
import torch_npu

from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim

import argparse
from openmind import pipeline, is_torch_npu_available
parser = argparse.ArgumentParser(description='manual to this script')
parser.add_argument("--model_name_or_path", type=str, default="./")
args = parser.parse_args()
model_path = args.model_name_or_path
device = None
if is_torch_npu_available():
    device = "npu:0"
else:
    device = "cpu"


model = SentenceTransformer(model_path)
model = model.to(device)
embeddings = model.encode(['How is the weather today?', '¿Qué tiempo hace hoy?'])

cosine_scores = cos_sim(embeddings[0], embeddings[1])
print(f"cosine_scores: {cosine_scores}")

Transformers 和 Sentence Transformers 的替代方案

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

将 Jina Embeddings 用于 RAG

根据 LLamaIndex 最新的博客文章:

总之,要在命中率和 MRR 上实现最佳性能,OpenAI 或 JinaAI-Base 嵌入模型与 CohereRerank/bge-reranker-large 重排序器的组合表现突出。

计划

  1. 支持更多欧洲和亚洲语言的双语嵌入模型,包括法语、意大利语和日语。
  2. 多模态嵌入模型,支持多模态 RAG 应用。
  3. 高性能重排序器。

联系方式

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

引用

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

@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}
}