Update README code snippet
#1
by
tomaarsen HF Staff - opened
- README.md +22 -7
- config_sentence_transformers.json +1 -1
README.md
CHANGED
|
@@ -38,15 +38,30 @@ Since we're a small company, this model is only released under a non-commercial
|
|
| 38 |
```python
|
| 39 |
from sentence_transformers import SentenceTransformer
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
]
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
The model can also be used through ZeroEntropy's [/models/embed](https://docs.zeroentropy.dev/api-reference/models/embed) endpoint.
|
|
|
|
| 38 |
```python
|
| 39 |
from sentence_transformers import SentenceTransformer
|
| 40 |
|
| 41 |
+
# Initialize model
|
| 42 |
+
model = SentenceTransformer(
|
| 43 |
+
"zeroentropy/zembed-1",
|
| 44 |
+
trust_remote_code=True,
|
| 45 |
+
# truncate_dim=640, # Optional: Reduce dimensionality from 2560 to {1280, 640, 320, 160, 80, 40}
|
| 46 |
+
model_kwargs={"torch_dtype": "bfloat16"},
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Define query and documents
|
| 50 |
+
query = "What is backpropagation?"
|
| 51 |
+
documents = [
|
| 52 |
+
"Backpropagation is a fundamental algorithm for training neural networks by computing gradients.",
|
| 53 |
+
"Gradient descent is used to optimize model parameters during the training process.",
|
| 54 |
+
"Neural network training relies on efficient computation of derivatives through backpropagation.",
|
| 55 |
]
|
| 56 |
|
| 57 |
+
# Encode query and documents (uses task-specific prompts automatically)
|
| 58 |
+
query_embeddings = model.encode_query(query)
|
| 59 |
+
document_embeddings = model.encode_document(documents)
|
| 60 |
+
# (2560,) (3, 2560)
|
| 61 |
+
|
| 62 |
+
# Compute cosine similarities
|
| 63 |
+
similarities = model.similarity(query_embeddings, document_embeddings)
|
| 64 |
+
# tensor([[0.7525, 0.5670, 0.6835]])
|
| 65 |
```
|
| 66 |
|
| 67 |
The model can also be used through ZeroEntropy's [/models/embed](https://docs.zeroentropy.dev/api-reference/models/embed) endpoint.
|
config_sentence_transformers.json
CHANGED
|
@@ -5,6 +5,6 @@
|
|
| 5 |
"document": "<|im_start|>system\ndocument<|im_end|>\n<|im_start|>user\n"
|
| 6 |
},
|
| 7 |
"suffix": "<|im_end|>\n",
|
| 8 |
-
"default_prompt_name":
|
| 9 |
"similarity_fn_name": "cosine"
|
| 10 |
}
|
|
|
|
| 5 |
"document": "<|im_start|>system\ndocument<|im_end|>\n<|im_start|>user\n"
|
| 6 |
},
|
| 7 |
"suffix": "<|im_end|>\n",
|
| 8 |
+
"default_prompt_name": "document",
|
| 9 |
"similarity_fn_name": "cosine"
|
| 10 |
}
|