Views
No views yet

jina-embeddings-v2-base-es is to use Jina AI's Embedding API.jina-embeddings-v2-base-es is a Spanish/English bilingual text embedding model supporting 8192 sequence length.
It is based on a BERT architecture (JinaBERT) that supports the symmetric bidirectional variant of ALiBi to allow longer sequence length.
We have designed it for high performance in mono-lingual & cross-lingual applications and trained it specifically to support mixed Spanish-English input without bias.
Additionally, we provide the following embedding models:jina-embeddings-v2-base-es es un modelo (embedding) de texto bilingüe Inglés/Español que admite una longitud de secuencia de 8192.
Se basa en la arquitectura BERT (JinaBERT) que incorpora la variante bi-direccional simétrica de ALiBi para permitir una mayor longitud de secuencia.
Hemos diseñado este modelo para un alto rendimiento en aplicaciones monolingües y bilingües, y está entrenando específicamente para admitir entradas mixtas de español e inglés sin sesgo.
Adicionalmente, proporcionamos los siguientes modelos (embeddings):jina-embeddings-v2-small-en: 33 million parameters.jina-embeddings-v2-base-en: 137 million parameters.jina-embeddings-v2-base-zh: Chinese-English Bilingual embeddings.jina-embeddings-v2-base-de: German-English Bilingual embeddings.jina-embeddings-v2-base-es: Spanish-English Bilingual embeddings (you are here).mean pooling takes all token embeddings from model output and averaging them at sentence/paragraph level.
It has been proved to be the most effective way to produce high-quality sentence embeddings.
We offer an encode function to deal with this.encode function:1import torch
2import torch.nn.functional as F
3from transformers import AutoTokenizer, AutoModel
4
5def mean_pooling(model_output, attention_mask):
6 token_embeddings = model_output[0]
7 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
8 return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
9
10sentences = ['How is the weather today?', 'What is the current weather like today?']
11
12tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-embeddings-v2-base-es')
13model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-es', trust_remote_code=True)
14
15encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
16
17with torch.no_grad():
18 model_output = model(**encoded_input)
19
20embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
21embeddings = F.normalize(embeddings, p=2, dim=1)transformers package:1!pip install transformers
2from transformers import AutoModel
3from numpy.linalg import norm
4
5cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
6model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-es', trust_remote_code=True) # trust_remote_code is needed to use the encode method
7embeddings = model.encode(['How is the weather today?', '¿Qué tiempo hace hoy?'])
8print(cos_sim(embeddings[0], embeddings[1]))max_length parameter to the encode function:1embeddings = model.encode(
2 ['Very long ... document'],
3 max_length=2048
4)sentence-transformers package:1from sentence_transformers import SentenceTransformer, util
2
3model = SentenceTransformer("jinaai/jina-embeddings-v2-base-es", trust_remote_code=True)
4embeddings = model.encode(['How is the weather today?', '¿Qué tiempo hace hoy?'])
5print(util.cos_sim(embeddings[0], embeddings[1]))model.max_seq_lengthmodel.max_seq_length = 2048In summary, to achieve the peak performance in both hit rate and MRR, the combination of OpenAI or JinaAI-Base embeddings with the CohereRerank/bge-reranker-large reranker stands out.

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