Tom Aarsen commited on
Commit
d1cf1c1
·
1 Parent(s): 0b0237d

Update code snippets, MRL

Browse files
Files changed (1) hide show
  1. README.md +42 -18
README.md CHANGED
@@ -32,7 +32,7 @@ tags:
32
  - Model Size: 0.5B
33
  - Embedding Dimension: 896
34
  - Max Input Tokens: 32k
35
- - MLR: 896 512 256 128 64
36
  - Attn: Bidirectional attention
37
  - Pooling: Mean pooling
38
 
@@ -93,20 +93,32 @@ Then you can use the model like this:
93
 
94
  ```python
95
  from sentence_transformers import SentenceTransformer
 
96
 
97
-
98
- sentences = ["This is an example sentence", "Each sentence is converted"]
99
-
100
- model = SentenceTransformer("{MODEL_NAME_OR_PATH}", trust_remote_code=True, model_kwargs={"torch_dtype": torch.bfloat16, "attn_implementation": "flash_attention_2"})
 
 
 
 
101
  model.max_seq_length = 512
102
 
 
103
  embeddings = model.encode(
104
- sentences,
105
  normalize_embeddings=True,
106
- batch_size=256,
107
- show_progress_bar=True
108
- )
109
  print(embeddings)
 
 
 
 
 
 
110
  ```
111
 
112
  We add task instructions for asymmetric tasks: retrieval, reranking, classification, and clustering.
@@ -115,22 +127,34 @@ If you want to add task instructions to the query, you can use the model like th
115
 
116
  ```python
117
  from sentence_transformers import SentenceTransformer
 
118
 
119
-
120
- sentences = ["This is an example sentence", "Each sentence is converted"]
121
-
122
- model = SentenceTransformer("{MODEL_NAME_OR_PATH}", trust_remote_code=True, model_kwargs={"torch_dtype": torch.bfloat16, "attn_implementation": "flash_attention_2"})
 
 
 
 
123
  model.max_seq_length = 512
124
 
125
- prompt = "Instruct: Classifying the category of french news. \n Query: "
 
126
  embeddings = model.encode(
127
- sentences,
128
  prompt=prompt,
129
  normalize_embeddings=True,
130
- batch_size=256,
131
- show_progress_bar=True
132
- )
133
  print(embeddings)
 
 
 
 
 
 
134
  ```
135
 
136
  ### vllm support
 
32
  - Model Size: 0.5B
33
  - Embedding Dimension: 896
34
  - Max Input Tokens: 32k
35
+ - MRL dimensions: 896, 512, 256, 128, and 64
36
  - Attn: Bidirectional attention
37
  - Pooling: Mean pooling
38
 
 
93
 
94
  ```python
95
  from sentence_transformers import SentenceTransformer
96
+ import torch
97
 
98
+ model = SentenceTransformer(
99
+ "KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5",
100
+ trust_remote_code=True,
101
+ model_kwargs={
102
+ "torch_dtype": torch.bfloat16,
103
+ "attn_implementation": "flash_attention_2", # Optional
104
+ },
105
+ )
106
  model.max_seq_length = 512
107
 
108
+ sentences = ["This is an example sentence", "Each sentence is converted"]
109
  embeddings = model.encode(
110
+ sentences,
111
  normalize_embeddings=True,
112
+ batch_size=256,
113
+ show_progress_bar=True,
114
+ )
115
  print(embeddings)
116
+ '''
117
+ [[-0.01043701 -0.02172852 0.0100708 ... -0.02807617 0.00157166
118
+ -0.03637695]
119
+ [-0.00424194 0.02966309 0.03686523 ... -0.02587891 0.01953125
120
+ -0.00125122]]
121
+ '''
122
  ```
123
 
124
  We add task instructions for asymmetric tasks: retrieval, reranking, classification, and clustering.
 
127
 
128
  ```python
129
  from sentence_transformers import SentenceTransformer
130
+ import torch
131
 
132
+ model = SentenceTransformer(
133
+ "KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5",
134
+ trust_remote_code=True,
135
+ model_kwargs={
136
+ "torch_dtype": torch.bfloat16,
137
+ "attn_implementation": "flash_attention_2", # Optional
138
+ },
139
+ )
140
  model.max_seq_length = 512
141
 
142
+ sentences = ["This is an example sentence", "Each sentence is converted"]
143
+ prompt = "Instruct: Classifying the category of french news.\nQuery:"
144
  embeddings = model.encode(
145
+ sentences,
146
  prompt=prompt,
147
  normalize_embeddings=True,
148
+ batch_size=256,
149
+ show_progress_bar=True,
150
+ )
151
  print(embeddings)
152
+ '''
153
+ [[-0.01867676 0.02319336 0.00280762 ... -0.02075195 0.00196838
154
+ -0.0703125 ]
155
+ [-0.0067749 0.03491211 0.01434326 ... -0.0043335 0.00509644
156
+ -0.04174805]]
157
+ '''
158
  ```
159
 
160
  ### vllm support