michael-guenther commited on
Commit
b46059e
·
verified ·
1 Parent(s): fa997ff

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -40
README.md CHANGED
@@ -57,38 +57,7 @@ The following Python packages are required:
57
  </details>
58
 
59
  <details>
60
- <summary>via <a href="https://huggingface.co/docs/transformers/en/index">transformers</a> (AutoModel with trust_remote_code=True)</summary>
61
-
62
- ```python
63
- # !pip install transformers>=4.53.0 torch>=2.7.1
64
-
65
- from transformers import AutoModel
66
- import torch
67
-
68
- # Initialize the model
69
- model = AutoModel.from_pretrained("jinaai/jina-code-embeddings-0.5b", trust_remote_code=True)
70
- model.to("cuda")
71
-
72
- # Configure truncate_dim, max_length, batch_size in the encode function if needed
73
-
74
- # Encode query
75
- query_embeddings = model.encode(
76
- ["print hello world in python"],
77
- task="nl2code",
78
- prompt_name="query",
79
- )
80
-
81
- # Encode passage
82
- passage_embeddings = model.encode(
83
- ["print('Hello World!')"],
84
- task="nl2code",
85
- prompt_name="passage",
86
- )
87
- ```
88
- </details>
89
-
90
- <details>
91
- <summary> via <a href="https://huggingface.co/docs/transformers/en/index">transformers</a> (using Qwen2Model without trust_remote_code)</summary>
92
 
93
  ```python
94
  # !pip install transformers>=4.53.0 torch>=2.7.1
@@ -96,8 +65,7 @@ passage_embeddings = model.encode(
96
  import torch
97
  import torch.nn.functional as F
98
 
99
- from transformers.models.qwen2 import Qwen2Model
100
- from transformers.models.qwen2.tokenization_qwen2_fast import Qwen2TokenizerFast
101
 
102
  INSTRUCTION_CONFIG = {
103
  "nl2code": {
@@ -152,8 +120,8 @@ documents = [
152
  ]
153
  all_inputs = queries + documents
154
 
155
- tokenizer = Qwen2TokenizerFast.from_pretrained('jinaai/jina-code-embeddings-0.5b')
156
- model = Qwen2Model.from_pretrained('jinaai/jina-code-embeddings-0.5b')
157
 
158
  batch_dict = tokenizer(
159
  all_inputs,
@@ -192,7 +160,8 @@ model = SentenceTransformer(
192
  "torch_dtype": torch.bfloat16,
193
  "attn_implementation": "flash_attention_2",
194
  "device_map": "cuda"
195
- }
 
196
  )
197
 
198
  # The queries and documents to embed
@@ -211,8 +180,8 @@ document_embeddings = model.encode(documents, prompt_name="nl2code_document")
211
  # Compute the (cosine) similarity between the query and document embeddings
212
  similarity = model.similarity(query_embeddings, document_embeddings)
213
  print(similarity)
214
- # tensor([[0.8157, 0.1222],
215
- # [0.1201, 0.5500]])
216
  ```
217
  </details>
218
 
@@ -270,7 +239,6 @@ all_inputs = queries + documents
270
  # vLLM embedding model
271
  llm = LLM(
272
  model="jinaai/jina-code-embeddings-0.5b",
273
- hf_overrides={"architectures": ["Qwen2ForCausalLM"]},
274
  task="embed"
275
  )
276
 
 
57
  </details>
58
 
59
  <details>
60
+ <summary>via <a href="https://huggingface.co/docs/transformers/en/index">transformers</a></summary>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  ```python
63
  # !pip install transformers>=4.53.0 torch>=2.7.1
 
65
  import torch
66
  import torch.nn.functional as F
67
 
68
+ from transformers import AutoModel, AutoTokenizer
 
69
 
70
  INSTRUCTION_CONFIG = {
71
  "nl2code": {
 
120
  ]
121
  all_inputs = queries + documents
122
 
123
+ tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-code-embeddings-0.5b')
124
+ model = AutoModel.from_pretrained('jinaai/jina-code-embeddings-0.5b')
125
 
126
  batch_dict = tokenizer(
127
  all_inputs,
 
160
  "torch_dtype": torch.bfloat16,
161
  "attn_implementation": "flash_attention_2",
162
  "device_map": "cuda"
163
+ },
164
+ tokenizer_kwargs={"padding_side": "left"},
165
  )
166
 
167
  # The queries and documents to embed
 
180
  # Compute the (cosine) similarity between the query and document embeddings
181
  similarity = model.similarity(query_embeddings, document_embeddings)
182
  print(similarity)
183
+ # tensor([[0.8169, 0.1214],
184
+ # [0.1190, 0.5500]])
185
  ```
186
  </details>
187
 
 
239
  # vLLM embedding model
240
  llm = LLM(
241
  model="jinaai/jina-code-embeddings-0.5b",
 
242
  task="embed"
243
  )
244