Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
**This model is a neuron compiled version of https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 ***
|
5 |
+
|
6 |
+
It was compiled on version 2.20 of the Neuron SDK. You may need to run the compilation process again.
|
7 |
+
|
8 |
+
See https://huggingface.co/docs/optimum-neuron/en/inference_tutorials/sentence_transformers for more details
|
9 |
+
|
10 |
+
For information on how to run on SageMaker: https://huggingface.co/docs/optimum-neuron/en/inference_tutorials/sentence_transformers
|
11 |
+
|
12 |
+
To run:
|
13 |
+
|
14 |
+
```
|
15 |
+
from optimum.neuron import NeuronModelForSentenceTransformers
|
16 |
+
from transformers import AutoTokenizer
|
17 |
+
model_id = "jburtoft/all-MiniLM-L6-v2-neuron"
|
18 |
+
|
19 |
+
# Use the line below if you have to compile the model yourself
|
20 |
+
#model_id = "all-MiniLM-L6-v2-neuron"
|
21 |
+
|
22 |
+
|
23 |
+
model = NeuronModelForSentenceTransformers.from_pretrained(model_id)
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
25 |
+
|
26 |
+
# Run inference
|
27 |
+
prompt = "I like to eat apples"
|
28 |
+
encoded_input = tokenizer(prompt, return_tensors='pt')
|
29 |
+
outputs = model(**encoded_input)
|
30 |
+
|
31 |
+
token_embeddings = outputs.token_embeddings
|
32 |
+
sentence_embedding = outputs.sentence_embedding
|
33 |
+
|
34 |
+
print(f"token embeddings: {token_embeddings.shape}") # torch.Size([1, 7, 384])
|
35 |
+
print(f"sentence_embedding: {sentence_embedding.shape}") # torch.Size([1, 384])
|
36 |
+
```
|
37 |
+
|
38 |
+
To compile:
|
39 |
+
```
|
40 |
+
optimum-cli export neuron -m sentence-transformers/all-MiniLM-L6-v2 --sequence_length 512 --batch_size 1 --task feature-extraction all-MiniLM-L6-v2-neuron
|
41 |
+
```
|