dariakryvosheieva commited on
Commit
9a08200
·
verified ·
1 Parent(s): f733cc1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +40 -0
README.md CHANGED
@@ -85,6 +85,46 @@ passage_embeddings = model.encode(
85
  ```
86
  </details>
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  ## Training & Evaluation
89
 
90
  Please refer to our technical report of jina-embeddings-c1 for training details and benchmarks.
 
85
  ```
86
  </details>
87
 
88
+ <details>
89
+ <summary>via <a href="https://sbert.net/">sentence-transformers</a></summary>
90
+
91
+ ```python
92
+ # !pip install sentence_transformers>=5.0.0 torch>=2.7.1
93
+
94
+ import torch
95
+ from sentence_transformers import SentenceTransformer
96
+
97
+ # Load the model
98
+ model = SentenceTransformer(
99
+ "jinaai/jina-embeddings-c1-0.5B",
100
+ model_kwargs={
101
+ "torch_dtype": torch.bfloat16,
102
+ "attn_implementation": "flash_attention_2",
103
+ "device_map": "auto"
104
+ }
105
+ )
106
+
107
+ # The queries and documents to embed
108
+ queries = [
109
+ "print hello world in python",
110
+ "initialize array of 5 zeros in c++"
111
+ ]
112
+ documents = [
113
+ "print('Hello World!')",
114
+ "int arr[5] = {0, 0, 0, 0, 0};"
115
+ ]
116
+
117
+ query_embeddings = model.encode(queries, prompt_name="nl2code_query")
118
+ document_embeddings = model.encode(documents, prompt_name="nl2code_document")
119
+
120
+ # Compute the (cosine) similarity between the query and document embeddings
121
+ similarity = model.similarity(query_embeddings, document_embeddings)
122
+ print(similarity)
123
+ # tensor([[0.8157, 0.1222],
124
+ # [0.1201, 0.5500]])
125
+ ```
126
+ </details>
127
+
128
  ## Training & Evaluation
129
 
130
  Please refer to our technical report of jina-embeddings-c1 for training details and benchmarks.