Sentence Similarity
sentence-transformers
PyTorch
ONNX
xlm-roberta
feature-extraction
text-embeddings-inference
Instructions to use p0x0q-dev/bge-m3-sparse-experimental with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use p0x0q-dev/bge-m3-sparse-experimental with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("p0x0q-dev/bge-m3-sparse-experimental") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Commit ·
ae99f99
1
Parent(s): 9aae34a
Refactor handler.py to remove unnecessary code and return dense vectors as a list
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- handler.py +5 -0
__pycache__/handler.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/handler.cpython-311.pyc and b/__pycache__/handler.cpython-311.pyc differ
|
|
|
handler.py
CHANGED
|
@@ -27,6 +27,8 @@ class EndpointHandler():
|
|
| 27 |
result = self.model.encode(inputs, return_dense=True, return_sparse=False)
|
| 28 |
# print(result)
|
| 29 |
dense_vectors = result["dense_vecs"]
|
|
|
|
|
|
|
| 30 |
# sparse_vectors = result["lexical_weights"]
|
| 31 |
# defaultdict(<class 'int'>, {'6': 0.09546, '192661': 0.3323})
|
| 32 |
|
|
@@ -40,6 +42,9 @@ class EndpointHandler():
|
|
| 40 |
# レスポンスをの型をkey=str, value=floatのdictにする。なお、numpy.float16はjsonに変換できないので、floatに変換する。
|
| 41 |
# sparse_vectors = {str(k): float(v) for k, v in sparse_vectors.items()}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
return [
|
| 44 |
[
|
| 45 |
{ "outputs": dense_vectors}
|
|
|
|
| 27 |
result = self.model.encode(inputs, return_dense=True, return_sparse=False)
|
| 28 |
# print(result)
|
| 29 |
dense_vectors = result["dense_vecs"]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
# sparse_vectors = result["lexical_weights"]
|
| 33 |
# defaultdict(<class 'int'>, {'6': 0.09546, '192661': 0.3323})
|
| 34 |
|
|
|
|
| 42 |
# レスポンスをの型をkey=str, value=floatのdictにする。なお、numpy.float16はjsonに変換できないので、floatに変換する。
|
| 43 |
# sparse_vectors = {str(k): float(v) for k, v in sparse_vectors.items()}
|
| 44 |
|
| 45 |
+
# レスポンスの型をnumpy.ndarrayから、通常のarrayに変更する
|
| 46 |
+
dense_vectors = dense_vectors.tolist()
|
| 47 |
+
|
| 48 |
return [
|
| 49 |
[
|
| 50 |
{ "outputs": dense_vectors}
|