Tom Aarsen
commited on
Commit
·
e64d277
1
Parent(s):
7dbeedb
move Usage, embeddings models -> embedding models
Browse files
README.md
CHANGED
@@ -45,9 +45,9 @@ from transformers import AutoTokenizer, AutoModel
|
|
45 |
import torch
|
46 |
|
47 |
|
48 |
-
#Mean Pooling - Take attention mask into account for correct averaging
|
49 |
def mean_pooling(model_output, attention_mask):
|
50 |
-
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
51 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
52 |
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
53 |
|
@@ -73,7 +73,31 @@ print("Sentence embeddings:")
|
|
73 |
print(sentence_embeddings)
|
74 |
```
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
## Full Model Architecture
|
79 |
```
|
@@ -99,29 +123,3 @@ If you find this model helpful, feel free to cite our publication [Sentence-BERT
|
|
99 |
url = "http://arxiv.org/abs/1908.10084",
|
100 |
}
|
101 |
```
|
102 |
-
|
103 |
-
## Usage (Text Embeddings Inference (TEI))
|
104 |
-
|
105 |
-
[Text Embeddings Inference (TEI)](https://github.com/huggingface/text-embeddings-inference) is a blazing fast inference solution for text embeddings models.
|
106 |
-
|
107 |
-
- CPU:
|
108 |
-
```bash
|
109 |
-
docker run -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-latest --model-id sentence-transformers/stsb-mpnet-base-v2 --pooling mean --dtype float16
|
110 |
-
```
|
111 |
-
|
112 |
-
- NVIDIA GPU:
|
113 |
-
```bash
|
114 |
-
docker run --gpus all -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cuda-latest --model-id sentence-transformers/stsb-mpnet-base-v2 --pooling mean --dtype float16
|
115 |
-
```
|
116 |
-
|
117 |
-
Send a request to `/v1/embeddings` to generate embeddings via the [OpenAI Embeddings API](https://platform.openai.com/docs/api-reference/embeddings/create):
|
118 |
-
```bash
|
119 |
-
curl http://localhost:8080/v1/embeddings \
|
120 |
-
-H "Content-Type: application/json" \
|
121 |
-
-d '{
|
122 |
-
"model": "sentence-transformers/stsb-mpnet-base-v2",
|
123 |
-
"input": ["This is an example sentence", "Each sentence is converted"]
|
124 |
-
}'
|
125 |
-
```
|
126 |
-
|
127 |
-
Or check the [Text Embeddings Inference API specification](https://huggingface.github.io/text-embeddings-inference/) instead.
|
|
|
45 |
import torch
|
46 |
|
47 |
|
48 |
+
# Mean Pooling - Take attention mask into account for correct averaging
|
49 |
def mean_pooling(model_output, attention_mask):
|
50 |
+
token_embeddings = model_output[0] # First element of model_output contains all token embeddings
|
51 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
52 |
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
53 |
|
|
|
73 |
print(sentence_embeddings)
|
74 |
```
|
75 |
|
76 |
+
## Usage (Text Embeddings Inference (TEI))
|
77 |
+
|
78 |
+
[Text Embeddings Inference (TEI)](https://github.com/huggingface/text-embeddings-inference) is a blazing fast inference solution for text embedding models.
|
79 |
+
|
80 |
+
- CPU:
|
81 |
+
```bash
|
82 |
+
docker run -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-latest --model-id sentence-transformers/stsb-mpnet-base-v2 --pooling mean --dtype float16
|
83 |
+
```
|
84 |
|
85 |
+
- NVIDIA GPU:
|
86 |
+
```bash
|
87 |
+
docker run --gpus all -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cuda-latest --model-id sentence-transformers/stsb-mpnet-base-v2 --pooling mean --dtype float16
|
88 |
+
```
|
89 |
+
|
90 |
+
Send a request to `/v1/embeddings` to generate embeddings via the [OpenAI Embeddings API](https://platform.openai.com/docs/api-reference/embeddings/create):
|
91 |
+
```bash
|
92 |
+
curl http://localhost:8080/v1/embeddings \
|
93 |
+
-H "Content-Type: application/json" \
|
94 |
+
-d '{
|
95 |
+
"model": "sentence-transformers/stsb-mpnet-base-v2",
|
96 |
+
"input": ["This is an example sentence", "Each sentence is converted"]
|
97 |
+
}'
|
98 |
+
```
|
99 |
+
|
100 |
+
Or check the [Text Embeddings Inference API specification](https://huggingface.github.io/text-embeddings-inference/) instead.
|
101 |
|
102 |
## Full Model Architecture
|
103 |
```
|
|
|
123 |
url = "http://arxiv.org/abs/1908.10084",
|
124 |
}
|
125 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|