Views
No views yet
pip install hf-hub-ctranslate2>=2.12.0 ctranslate2>=3.17.11# from transformers import AutoTokenizer
2model_name = "michaelfeil/ct2fast-jina-embedding-s-en-v1"
3model_name_orig="jinaai/jina-embedding-s-en-v1"
4
5from hf_hub_ctranslate2 import EncoderCT2fromHfHub
6model = EncoderCT2fromHfHub(
7 # load in int8 on CUDA
8 model_name_or_path=model_name,
9 device="cuda",
10 compute_type="int8_float16"
11)
12outputs = model.generate(
13 text=["I like soccer", "I like tennis", "The eiffel tower is in Paris"],
14 max_length=64,
15) # perform downstream tasks on outputs
16outputs["pooler_output"]
17outputs["last_hidden_state"]
18outputs["attention_mask"]
19
20# alternative, use SentenceTransformer Mix-In
21# for end-to-end Sentence embeddings generation
22# (not pulling from this CT2fast-HF repo)
23
24from hf_hub_ctranslate2 import CT2SentenceTransformer
25model = CT2SentenceTransformer(
26 model_name_orig, compute_type="int8_float16", device="cuda"
27)
28embeddings = model.encode(
29 ["I like soccer", "I like tennis", "The eiffel tower is in Paris"],
30 batch_size=32,
31 convert_to_numpy=True,
32 normalize_embeddings=True,
33)
34print(embeddings.shape, embeddings)
35scores = (embeddings @ embeddings.T) * 100
36
37# Hint: you can also host this code via REST API and
38# via github.com/michaelfeil/infinity
39
40compute_type=int8_float16 for device="cuda"compute_type=int8 for device="cpu"LLama-2 -> removed <pad> token.jina-embedding-s-en-v1 is a language model that has been trained using Jina AI's Linnaeus-Clean dataset.
This dataset consists of 380 million pairs of sentences, which include both query-document pairs.
These pairs were obtained from various domains and were carefully selected through a thorough cleaning process.
The Linnaeus-Full dataset, from which the Linnaeus-Clean dataset is derived, originally contained 1.6 billion sentence pairs.jina-embedding-t-en-v1: 14 million parameters.jina-embedding-s-en-v1: 35 million parameters (you are here).jina-embedding-b-en-v1: 110 million parameters.jina-embedding-l-en-v1: 330 million parameters.jina-embedding-1b-en-v1: 1.2 billion parameters, 10 times bert-base (soon).jina-embedding-6b-en-v1: 6 billion parameters, 30 times bert-base (soon).all-minilm-l6-v2/all-mpnet-base-v2 from sbert and text-embeddings-ada-002 from OpenAI:| Name | param | dimension |
|---|---|---|
| all-minilm-l6-v2 | 23m | 384 |
| all-mpnet-base-v2 | 110m | 768 |
| ada-embedding-002 | Unknown/OpenAI API | 1536 |
| jina-embedding-t-en-v1 | 14m | 312 |
| jina-embedding-s-en-v1 | 35m | 512 |
| jina-embedding-b-en-v1 | 110m | 768 |
| jina-embedding-l-en-v1 | 330m | 1024 |
| Name | STS12 | STS13 | STS14 | STS15 | STS16 | STS17 | TRECOVID | Quora | SciFact |
|---|---|---|---|---|---|---|---|---|---|
| all-minilm-l6-v2 | 0.724 | 0.806 | 0.756 | 0.854 | 0.79 | 0.876 | 0.473 | 0.876 | 0.645 |
| all-mpnet-base-v2 | 0.726 | 0.835 | 0.78 | 0.857 | 0.8 | 0.906 | 0.513 | 0.875 | 0.656 |
| ada-embedding-002 | 0.698 | 0.833 | 0.761 | 0.861 | 0.86 | 0.903 | 0.685 | 0.876 | 0.726 |
| jina-embedding-t-en-v1 | 0.717 | 0.773 | 0.731 | 0.829 | 0.777 | 0.860 | 0.482 | 0.840 | 0.522 |
| jina-embedding-s-en-v1 | 0.743 | 0.786 | 0.738 | 0.837 | 0.80 | 0.875 | 0.523 | 0.857 | 0.524 |
| jina-embedding-b-en-v1 | 0.751 | 0.809 | 0.761 | 0.856 | 0.812 | 0.890 | 0.606 | 0.876 | 0.594 |
| jina-embedding-l-en-v1 | 0.745 | 0.832 | 0.781 | 0.869 | 0.837 | 0.902 | 0.573 | 0.881 | 0.598 |
1!pip install finetuner
2import finetuner
3
4model = finetuner.build_model('jinaai/jina-embedding-s-en-v1')
5embeddings = finetuner.encode(
6 model=model,
7 data=['how is the weather today', 'What is the current weather like today?']
8)
9print(finetuner.cos_sim(embeddings[0], embeddings[1]))1from sentence_transformers import SentenceTransformer
2from sentence_transformers.util import cos_sim
3
4sentences = ['how is the weather today', 'What is the current weather like today?']
5
6model = SentenceTransformer('jinaai/jina-embedding-s-en-v1')
7embeddings = model.encode(sentences)
8print(cos_sim(embeddings[0], embeddings[1]))jina-embedding-s-en-v2 is currently underway with two main objectives: improving performance and increasing the maximum sequence length.jina-embedding-s/b/l-de-v1.1@misc{günther2023jina,
2 title={Jina Embeddings: A Novel Set of High-Performance Sentence Embedding Models},
3 author={Michael Günther and Louis Milliken and Jonathan Geuter and Georgios Mastrapas and Bo Wang and Han Xiao},
4 year={2023},
5 eprint={2307.11224},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}