Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
This is a part of the [MTEB test](https://huggingface.co/spaces/mteb/leaderboard).
|
| 3 |
+
|
| 4 |
+
```
|
| 5 |
+
# !pip install tensorflow_text
|
| 6 |
+
|
| 7 |
+
import tensorflow_hub as hub
|
| 8 |
+
from tensorflow_text import SentencepieceTokenizer
|
| 9 |
+
import tensorflow as tf
|
| 10 |
+
|
| 11 |
+
embedder=hub.load("https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3")
|
| 12 |
+
|
| 13 |
+
class USE():
|
| 14 |
+
def encode(self, sentences, batch_size=32, **kwargs):
|
| 15 |
+
embeddings = []
|
| 16 |
+
for i in range(0, len(sentences), batch_size):
|
| 17 |
+
batch_sentences = sentences[i:i+batch_size]
|
| 18 |
+
batch_embeddings = embedder(batch_sentences)
|
| 19 |
+
embeddings.extend(batch_embeddings)
|
| 20 |
+
return embeddings
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
model = USE()
|
| 24 |
+
```
|