Spaces:
Running
Running
arthurbr11
commited on
Commit
·
b07a96a
1
Parent(s):
4f75e8b
update
Browse files- .gitattributes +1 -0
- README.md +97 -4
- push-to-hub.png +3 -0
- sbert-hf.png +3 -0
- sbertLogo.png +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,10 +1,103 @@
|
|
1 |
---
|
2 |
title: README
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: README
|
3 |
+
emoji: ❤️
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
9 |
+
SentenceTransformers 🤗 is a Python framework for state-of-the-art sentence, text and image embeddings.
|
10 |
|
11 |
+
Install the [Sentence Transformers](https://www.sbert.net/) library.
|
12 |
+
```
|
13 |
+
pip install -U sentence-transformers
|
14 |
+
```
|
15 |
+
|
16 |
+
The usage is as simple as:
|
17 |
+
```python
|
18 |
+
from sentence_transformers import SparseEncoder
|
19 |
+
|
20 |
+
# 1. Load a pretrained SparseEncoder model
|
21 |
+
model = SparseEncoder("naver/splade-cocondenser-ensembledistil")
|
22 |
+
|
23 |
+
# The sentences to encode
|
24 |
+
sentences = [
|
25 |
+
"The weather is lovely today.",
|
26 |
+
"It's so sunny outside!",
|
27 |
+
"He drove to the stadium.",
|
28 |
+
]
|
29 |
+
|
30 |
+
# 2. Calculate sparse embeddings by calling model.encode()
|
31 |
+
embeddings = model.encode(sentences)
|
32 |
+
print(embeddings.shape)
|
33 |
+
# [3, 30522] - sparse representation with vocabulary size dimensions
|
34 |
+
|
35 |
+
# 3. Calculate the embedding similarities
|
36 |
+
similarities = model.similarity(embeddings, embeddings)
|
37 |
+
print(similarities)
|
38 |
+
# tensor([[ 35.629, 9.154, 0.098],
|
39 |
+
# [ 9.154, 27.478, 0.019],
|
40 |
+
# [ 0.098, 0.019, 29.553]])
|
41 |
+
|
42 |
+
# 4. Check sparsity stats
|
43 |
+
stats = SparseEncoder.sparsity(embeddings)
|
44 |
+
print(f"Sparsity: {stats['sparsity_ratio']:.2%}")
|
45 |
+
# Sparsity: 99.84%
|
46 |
+
```
|
47 |
+
|
48 |
+
Hugging Face makes it easy to collaboratively build and showcase your [Sentence Transformers](https://www.sbert.net/) models! You can collaborate with your organization, upload and showcase your own models in your profile ❤️
|
49 |
+
|
50 |
+
<div class="grid lg:grid-cols-3 gap-x-4 gap-y-7">
|
51 |
+
<a href="https://www.sbert.net/" class="block overflow-hidden group">
|
52 |
+
<div
|
53 |
+
class="w-full h-40 object-cover mb-2 rounded-lg flex items-center justify-center bg-[#FA8072]"
|
54 |
+
>
|
55 |
+
<img alt="" src="https://huggingface.co/spaces/sparse-encoder/README/resolve/main/sbertLogo.png" class="w-40" />
|
56 |
+
</div>
|
57 |
+
<div class="underline">Documentation</div>
|
58 |
+
</a>
|
59 |
+
<a
|
60 |
+
href="https://sbert.net/docs/package_reference/SentenceTransformer.html#sentence_transformers.SentenceTransformer.push_to_hub"
|
61 |
+
class="block overflow-hidden group"
|
62 |
+
>
|
63 |
+
<div
|
64 |
+
class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden"
|
65 |
+
>
|
66 |
+
<img
|
67 |
+
alt=""
|
68 |
+
src="https://huggingface.co/spaces/sparse-encoder/README/resolve/main/push-to-hub.png"
|
69 |
+
class="w-full h-40 object-cover overflow-hidden"
|
70 |
+
/>
|
71 |
+
</div>
|
72 |
+
<div class="underline">Push your Sentence Transformers models to the Hub ❤️ </div>
|
73 |
+
</a>
|
74 |
+
<a
|
75 |
+
href="https://huggingface.co/models?library=sentence-transformers&other=sparse&sort=downloads"
|
76 |
+
class="block overflow-hidden group"
|
77 |
+
>
|
78 |
+
<div
|
79 |
+
class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden"
|
80 |
+
>
|
81 |
+
<img
|
82 |
+
alt=""
|
83 |
+
src="https://huggingface.co/spaces/sparse-encoder/README/resolve/main/sbert-hf.png"
|
84 |
+
class="w-full h-40 object-cover overflow-hidden"
|
85 |
+
/>
|
86 |
+
</div>
|
87 |
+
<div class="underline">Find all SparseEncoder models on the 🤗 Hub</div>
|
88 |
+
</a>
|
89 |
+
</div>
|
90 |
+
|
91 |
+
To upload your SparseEncoder models to the Hugging Face Hub, log in with `huggingface-cli login` and use the [`push_to_hub`](https://sbert.net/docs/package_reference/sparse_encoder/SparseEncoder.html#sentence_transformers.sparse_encoder.SparseEncoder.push_to_hub) method within the Sentence Transformers library.
|
92 |
+
```python
|
93 |
+
from sentence_transformers import SparseEncoder
|
94 |
+
|
95 |
+
# Load or train a model
|
96 |
+
model = SparseEncoder(...)
|
97 |
+
# Push to Hub
|
98 |
+
model.push_to_hub("my_new_model")
|
99 |
+
```
|
100 |
+
|
101 |
+
Note that this repository hosts for now only examples of sparse-encoder models from the SentenceTransformers package that can be easily reproduced with the different training script examples.
|
102 |
+
|
103 |
+
More details at [Sparse Encoder > Training Examples](https://sbert.net/docs/sparse_encoder/training/examples.html) for the examples scripts and [Sparse Encoder > Pretrained Models](https://sbert.net/docs/sparse_encoder/pretrained_models.html) for the community pre-trained models, that you can also found for some of them in the following collections.
|
push-to-hub.png
ADDED
![]() |
Git LFS Details
|
sbert-hf.png
ADDED
![]() |
Git LFS Details
|
sbertLogo.png
ADDED
![]() |
Git LFS Details
|