michael-guenther commited on
Commit
3bf9e1f
·
1 Parent(s): 4149d6b

Add Sentence Transformers compatibility (#1)

Browse files

- Integrate with Sentence Transformers (634aea7207207bf725aa0266a6af49ecc177926c)
- Default to "Document: " prompt (2ad0ca5b2043873beb9f27bf46f7cbd9b8f9f8b5)

1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 1024,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": true,
9
+ "include_prompt": true
10
+ }
README.md CHANGED
@@ -60,6 +60,41 @@ The following Python packages are required:
60
 
61
  </details>
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  <details>
64
  <summary>via <a href="https://github.com/vllm-project/vllm">vLLM</a></summary>
65
 
 
60
 
61
  </details>
62
 
63
+ <details>
64
+ <summary>via <a href="https://sbert.net/">sentence-transformers</a></summary>
65
+
66
+ ```python
67
+ from sentence_transformers import SentenceTransformer
68
+ import torch
69
+
70
+ model = SentenceTransformer(
71
+ "jinaai/jina-embeddings-v5-text-small-classification",
72
+ model_kwargs={"dtype": torch.bfloat16}, # Recommended for GPUs
73
+ config_kwargs={"_attn_implementation": "flash_attention_2"}, # Recommended but optional
74
+ )
75
+ # Optional: set truncate_dim in encode() to control embedding size
76
+
77
+ texts = [
78
+ "My order hasn't arrived yet and it's been two weeks.",
79
+ "How do I reset my password?",
80
+ "I'd like a refund for my recent purchase.",
81
+ "Your product exceeded my expectations. Great job!",
82
+ ]
83
+
84
+ # Encode texts
85
+ embeddings = model.encode(texts)
86
+ print(embeddings.shape)
87
+ # (4, 1024)
88
+
89
+ similarity = model.similarity(embeddings, embeddings)
90
+ print(similarity)
91
+ # tensor([[1.0000, 0.7347, 0.7988, 0.7523],
92
+ # [0.7347, 1.0000, 0.7440, 0.7228],
93
+ # [0.7988, 0.7440, 1.0000, 0.7321],
94
+ # [0.7523, 0.7228, 0.7321, 1.0000]])
95
+ ```
96
+ </details>
97
+
98
  <details>
99
  <summary>via <a href="https://github.com/vllm-project/vllm">vLLM</a></summary>
100
 
config_sentence_transformers.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "5.1.2",
4
+ "transformers": "4.57.0",
5
+ "pytorch": "2.8.0"
6
+ },
7
+ "prompts":{
8
+ "query": "",
9
+ "document": "Document: "
10
+ },
11
+ "default_prompt_name": "document",
12
+ "similarity_fn_name": "cosine"
13
+ }
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]