Sentence Similarity
sentence-transformers
PyTorch
Transformers
xlm-roberta
feature-extraction
text-embeddings-inference
Instructions to use gnail/hamlet-distill-st with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use gnail/hamlet-distill-st with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("gnail/hamlet-distill-st") 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] - Transformers
How to use gnail/hamlet-distill-st with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("gnail/hamlet-distill-st") model = AutoModel.from_pretrained("gnail/hamlet-distill-st", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| #!/usr/bin/env python3 | |
| import sys | |
| from collections import OrderedDict | |
| import torch | |
| # Load and keep backup | |
| m_input = torch.load("2_Dense/pytorch_model.bin") | |
| torch.save(m_input, "2_Dense/pytorch_model.bin.bak") | |
| # Mappings | |
| rename = {"layer.weight": "linear.weight"} | |
| # Output | |
| m_output = OrderedDict() | |
| for key, params in m_input.items(): | |
| dst = key | |
| if key in rename: | |
| print(f"Mapping {key} to {rename[key]}", file=sys.stderr) | |
| dst = rename[key] | |
| m_output[dst] = params | |
| torch.save(m_output, "2_Dense/pytorch_model.bin") | |