Spaces:
Running
Running
title: README | |
emoji: ❤️ | |
colorFrom: red | |
colorTo: red | |
sdk: static | |
pinned: false | |
SentenceTransformers 🤗 is a Python framework for state-of-the-art sentence, text and image embeddings. | |
Install the [Sentence Transformers](https://www.sbert.net/) library. | |
``` | |
pip install -U sentence-transformers | |
``` | |
The usage is as simple as: | |
```python | |
from sentence_transformers import SentenceTransformer | |
# 1. Load a pretrained Sentence Transformer model | |
model = SentenceTransformer("all-MiniLM-L6-v2") | |
# The sentences to encode | |
sentences = [ | |
"The weather is lovely today.", | |
"It's so sunny outside!", | |
"He drove to the stadium.", | |
] | |
# 2. Calculate embeddings by calling model.encode() | |
embeddings = model.encode(sentences) | |
print(embeddings.shape) | |
# [3, 384] | |
# 3. Calculate the embedding similarities | |
similarities = model.similarity(embeddings, embeddings) | |
print(similarities) | |
# tensor([[1.0000, 0.6660, 0.1046], | |
# [0.6660, 1.0000, 0.1411], | |
# [0.1046, 0.1411, 1.0000]]) | |
``` | |
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 ❤️ | |
<div class="grid lg:grid-cols-3 gap-x-4 gap-y-7"> | |
<a href="https://www.sbert.net/" class="block overflow-hidden group"> | |
<div | |
class="w-full h-40 object-cover mb-2 rounded-lg flex items-center justify-center bg-[#FA8072]" | |
> | |
<img alt="" src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/sbertLogo.png" class="w-40" /> | |
</div> | |
<div class="underline">Documentation</div> | |
</a> | |
<a | |
href="https://sbert.net/docs/package_reference/SentenceTransformer.html#sentence_transformers.SentenceTransformer.push_to_hub" | |
class="block overflow-hidden group" | |
> | |
<div | |
class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden" | |
> | |
<img | |
alt="" | |
src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/push-to-hub.png" | |
class="w-full h-40 object-cover overflow-hidden" | |
/> | |
</div> | |
<div class="underline">Push your Sentence Transformers models to the Hub ❤️ </div> | |
</a> | |
<a | |
href="https://huggingface.co/models?library=sentence-transformers&sort=downloads" | |
class="block overflow-hidden group" | |
> | |
<div | |
class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden" | |
> | |
<img | |
alt="" | |
src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/sbert-hf.png" | |
class="w-full h-40 object-cover overflow-hidden" | |
/> | |
</div> | |
<div class="underline">Find all Sentence Transformers models on the 🤗 Hub</div> | |
</a> | |
</div> | |
To upload your Sentence Transformers models to the Hugging Face Hub, log in with `huggingface-cli login` and use the [`push_to_hub`](https://sbert.net/docs/package_reference/SentenceTransformer.html#sentence_transformers.SentenceTransformer.push_to_hub) method within the Sentence Transformers library. | |
```python | |
from sentence_transformers import SentenceTransformer | |
# Load or train a model | |
model = SentenceTransformer(...) | |
# Push to Hub | |
model.push_to_hub("my_new_model") | |
``` |