michael-guenther commited on
Commit
82f150e
·
1 Parent(s): 1524216

Add Sentence Transformers compatibility (#1)

Browse files

- Integrate with Sentence Transformers (8a96ae29be741908f0f3c15807a132e34d38e44e)
- Remove query/document mention (9b487e658a646ae0203e0970c3f3f537e33b4c07)
- Add default "Document: " prompt (f7f4fb8066c59a9752deed2257ea367d8889aa7a)
- Update README snippet results using new prompt (9fda0b7ae095b62ca1acfac8fc8034ea66e2f16b)

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,43 @@ 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-clustering",
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
+ "We propose a novel neural network architecture for image segmentation.",
79
+ "This paper analyzes the effects of monetary policy on inflation.",
80
+ "Our method achieves state-of-the-art results on object detection benchmarks.",
81
+ "We study the relationship between interest rates and housing prices.",
82
+ "A new attention mechanism is introduced for visual recognition tasks.",
83
+ ]
84
+
85
+ # Encode texts
86
+ embeddings = model.encode(texts)
87
+ print(embeddings.shape)
88
+ # (5, 1024)
89
+
90
+ similarity = model.similarity(embeddings, embeddings)
91
+ print(similarity)
92
+ # tensor([[1.0000, 0.2983, 0.8631, 0.3098, 0.9106],
93
+ # [0.2983, 1.0000, 0.3257, 0.8041, 0.3201],
94
+ # [0.8631, 0.3257, 1.0000, 0.3263, 0.9007],
95
+ # [0.3098, 0.8041, 0.3263, 1.0000, 0.3122],
96
+ # [0.9106, 0.3201, 0.9007, 0.3122, 1.0000]])
97
+ ```
98
+ </details>
99
+
100
  <details>
101
  <summary>via <a href="https://github.com/vllm-project/vllm">vLLM</a></summary>
102
 
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
+ ]