Views
No views yet

transformers >= 5.4. It does not require trust_remote_code=True and works out of the box with AutoModel and AutoTokenizer. Task-specific LoRA adapters are loaded via the standard Transformers adapter API.trust_remote_code=True.AutoModel. To use a task-specific LoRA adapter,
load it from the corresponding subfolder in the repository and activate it with set_adapter:1import torch
2import torch.nn.functional as F
3from transformers import AutoModel, AutoTokenizer
4
5model = AutoModel.from_pretrained("jinaai/jina-embeddings-v3-hf", dtype=torch.float32)
6
7# Load and activate the retrieval_query LoRA adapter
8# Available tasks: retrieval_query, retrieval_passage, separation, classification, text_matching
9task = "retrieval_query"
10model.load_adapter("jinaai/jina-embeddings-v3-hf", adapter_name=task, adapter_kwargs={"subfolder": task})
11model.set_adapter(task)
12model.eval()
13
14tokenizer = AutoTokenizer.from_pretrained("jinaai/jina-embeddings-v3-hf")
15texts = ["How is the weather today?", "What is the current weather like today?"]
16encoded = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
17
18with torch.no_grad():
19 outputs = model(**encoded)
20
21# Mean pooling
22attention_mask = encoded["attention_mask"].unsqueeze(-1)
23embeddings = (outputs.last_hidden_state * attention_mask).sum(dim=1) / attention_mask.sum(dim=1)
24embeddings = F.normalize(embeddings, p=2, dim=1)
25
26print(embeddings.shape)
27# Cosine similarity
28print(embeddings @ embeddings.T)1from sentence_transformers import SentenceTransformer
2
3# Load model with a task-specific adapter via config_kwargs
4task = "retrieval_query" # retrieval_passage, separation, classification, text_matching
5model = SentenceTransformer("jinaai/jina-embeddings-v3-hf", config_kwargs={"subfolder": task})
6
7sentences = ["How is the weather today?", "What is the current weather like today?"]
8embeddings = model.encode(sentences)
9
10print(embeddings.shape)jina-embeddings-v3 is a multilingual multi-task text embedding model designed for a variety of NLP applications.
Based on the Jina-XLM-RoBERTa architecture,
this model supports Rotary Position Embeddings to handle long input sequences up to 8192 tokens.
Additionally, it features 5 LoRA adapters to generate task-specific embeddings efficiently.retrieval_query: Used for query embeddings in asymmetric retrieval tasksretrieval_passage: Used for passage embeddings in asymmetric retrieval tasksseparation: Used for embeddings in clustering and re-ranking applicationsclassification: Used for embeddings in classification taskstext_matching: Used for embeddings in tasks that quantify similarity between two texts, such as STS or symmetric retrieval tasks32, 64, 128, 256, 512, 768, 1024), allowing for truncating embeddings to fit your application.jina-embeddings-v3 is listed on AWS & Azure. If you need to use it beyond those platforms or on-premises within your company, note that the models is licensed under CC BY-NC 4.0. For commercial usage inquiries, feel free to contact us.jina-embeddings-v3 useful in your research, please cite the following paper:1@misc{sturua2024jinaembeddingsv3multilingualembeddingstask,
2 title={jina-embeddings-v3: Multilingual Embeddings With Task LoRA},
3 author={Saba Sturua and Isabelle Mohr and Mohammad Kalim Akram and Michael Günther and Bo Wang and Markus Krimmel and Feng Wang and Georgios Mastrapas and Andreas Koukounas and Andreas Koukounas and Nan Wang and Han Xiao},
4 year={2024},
5 eprint={2409.10173},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2409.10173},
9}
10