Sentence Similarity
sentence-transformers
Safetensors
English
distilbert
feature-extraction
mteb
Eval Results (legacy)
text-embeddings-inference
Run this model with HF Jobs
Run prdev/mini-gte on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/prdev/mini-gte. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/prdev/mini-gte on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use prdev/mini-gte with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use prdev/mini-gte with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("prdev/mini-gte") 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] - Inference
- Notebooks
- Google Colab
- Kaggle
Upload 14 files
Browse filesFiles changed (14)
- .ipynb_checkpoints/mteb_eval-checkpoint.pyAdded+71
- 1_Pooling/config.jsonAdded+10
- README.md+141-3
- config.jsonAdded+24
- config_sentence_transformers.jsonAdded+10
- model.safetensorsAdded+3
- model_card.mdAdded
- modules.jsonAdded+14
- mteb_eval.pyAdded+71
- sentence_bert_config.jsonAdded+4
- special_tokens_map.jsonAdded+7
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+56
- vocab.txtAdded
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import mtebfrom mteb.encoder_interface import PromptTypefrom sentence_transformers import SentenceTransformer, modelsimport numpy as npimport torchimport osimport math
model_save_path = "./" #REPLACE WITH YOUR PATH
# Reload the prepared SentenceTransformer modelmodel = SentenceTransformer(model_save_path)
# -------- Step 3: Define Custom Model Interface for MTEB --------class CustomModel: def __init__(self, model): self.model = model
def encode( self, sentences, task_name: str, prompt_type = None, max_batch_size: int = 32, # Set default max batch size **kwargs ) -> np.ndarray: """ Encodes the given sentences using the model with a maximum batch size.
Args: sentences (List[str]): The sentences to encode. task_name (str): The name of the task. prompt_type (Optional[PromptType]): The prompt type to use. max_batch_size (int): The maximum number of sentences to process in a single batch. **kwargs: Additional arguments to pass to the encoder.
Returns: np.ndarray: Encoded sentences as a numpy array. """
sentences = [str(sentence) for sentence in sentences] total_sentences = len(sentences) num_batches = math.ceil(total_sentences / max_batch_size) embeddings_list = []
for batch_idx in range(num_batches): start_idx = batch_idx * max_batch_size end_idx = min(start_idx + max_batch_size, total_sentences) batch_sentences = sentences[start_idx:end_idx] batch_embeddings = self.model.encode(batch_sentences, convert_to_tensor=True)
if not isinstance(batch_embeddings, torch.Tensor): batch_embeddings = torch.tensor(batch_embeddings)
embeddings_list.append(batch_embeddings.cpu().numpy())
return np.vstack(embeddings_list)
# Wrap the SentenceTransformer model in the CustomModel classcustom_model = CustomModel(model)
# Select the MTEB tasks to evaluatetasks = mteb.get_benchmark("MTEB(eng, classic)")
# Initialize the evaluation frameworkevaluation = mteb.MTEB(tasks=tasks)
# Run evaluation and save resultsresults = evaluation.run(custom_model, output_folder="results/model_results")12345678910{ "word_embedding_dimension": 768, "pooling_mode_cls_token": true, "pooling_mode_mean_tokens": false, "pooling_mode_max_tokens": false, "pooling_mode_mean_sqrt_len_tokens": false, "pooling_mode_weightedmean_tokens": false, "pooling_mode_lasttoken": false, "include_prompt": true}123---license: apache-2.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141---tags:- sentence-transformers- sentence-similarity- feature-extractionbase_model: distilbert/distilbert-base-uncasedpipeline_tag: sentence-similaritylibrary_name: sentence-transformers---# SentenceTransformer based on distilbert/distilbert-base-uncasedThis is a [sentence-transformers](https://www.SBERT.net) model finetuned from [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased). It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.## Model Details### Model Description- **Model Type:** Sentence Transformer- **Base model:** [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased) <!-- at revision 12040accade4e8a0f71eabdb258fecc2e7e948be -->- **Maximum Sequence Length:** 512 tokens- **Output Dimensionality:** 768 dimensions- **Similarity Function:** Cosine Similarity<!-- - **Training Dataset:** Unknown --><!-- - **Language:** Unknown --><!-- - **License:** Unknown -->### Model Sources- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)- **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)- **Hugging Face:** [Sentence Transformers on Hugging Face](https://huggingface.co/models?library=sentence-transformers)### Full Model Architecture```SentenceTransformer((0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: DistilBertModel(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True}))```## Usage### Direct Usage (Sentence Transformers)First install the Sentence Transformers library:```bashpip install -U sentence-transformers```Then you can load this model and run inference.```pythonfrom sentence_transformers import SentenceTransformer# Download from the 🤗 Hubmodel = SentenceTransformer("sentence_transformers_model_id")# Run inferencesentences = ['The weather is lovely today.',"It's so sunny outside!",'He drove to the stadium.',]embeddings = model.encode(sentences)print(embeddings.shape)# [3, 768]# Get the similarity scores for the embeddingssimilarities = model.similarity(embeddings, embeddings)print(similarities.shape)# [3, 3]```<!--### Direct Usage (Transformers)<details><summary>Click to see the direct usage in Transformers</summary></details>--><!--### Downstream Usage (Sentence Transformers)You can finetune this model on your own dataset.<details><summary>Click to expand</summary></details>--><!--### Out-of-Scope Use*List how the model may foreseeably be misused and address what users ought not to do with the model.*--><!--## Bias, Risks and Limitations*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*--><!--### Recommendations*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*-->## Training Details### Framework Versions- Python: 3.10.12- Sentence Transformers: 3.3.1- Transformers: 4.48.0.dev0- PyTorch: 2.1.0a0+32f93b1- Accelerate: 1.2.0- Datasets: 2.21.0- Tokenizers: 0.21.0## Citation### BibTeX<!--## Glossary*Clearly define terms in order to be accessible across audiences.*--><!--## Model Card Authors*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*--><!--## Model Card Contact*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*-->
123456789101112131415161718192021222324{ "_name_or_path": "distilbert-base-uncased", "activation": "gelu", "architectures": [ "DistilBertModel" ], "attention_dropout": 0.1, "dim": 768, "dropout": 0.1, "hidden_dim": 3072, "initializer_range": 0.02, "max_position_embeddings": 512, "model_type": "distilbert", "n_heads": 12, "n_layers": 6, "pad_token_id": 0, "qa_dropout": 0.1, "seq_classif_dropout": 0.2, "sinusoidal_pos_embds": false, "tie_weights_": true, "torch_dtype": "float32", "transformers_version": "4.48.0.dev0", "vocab_size": 30522}12345678910{ "__version__": { "sentence_transformers": "3.3.1", "transformers": "4.48.0.dev0", "pytorch": "2.1.0a0+32f93b1" }, "prompts": {}, "default_prompt_name": null, "similarity_fn_name": "cosine"}123version https://git-lfs.github.com/spec/v1oid sha256:abaa3ca6ba670db88b0d70cf33d5545e3b45f7cb03d620accf05c7bc8974ea51size 2654626081234567891011121314[ { "idx": 0, "name": "0", "path": "", "type": "sentence_transformers.models.Transformer" }, { "idx": 1, "name": "1", "path": "1_Pooling", "type": "sentence_transformers.models.Pooling" }]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import mtebfrom mteb.encoder_interface import PromptTypefrom sentence_transformers import SentenceTransformer, modelsimport numpy as npimport torchimport osimport math
model_save_path = "./" #REPLACE WITH YOUR PATH
# Reload the prepared SentenceTransformer modelmodel = SentenceTransformer(model_save_path)
# -------- Step 3: Define Custom Model Interface for MTEB --------class CustomModel: def __init__(self, model): self.model = model
def encode( self, sentences, task_name: str, prompt_type = None, max_batch_size: int = 32, # Set default max batch size **kwargs ) -> np.ndarray: """ Encodes the given sentences using the model with a maximum batch size.
Args: sentences (List[str]): The sentences to encode. task_name (str): The name of the task. prompt_type (Optional[PromptType]): The prompt type to use. max_batch_size (int): The maximum number of sentences to process in a single batch. **kwargs: Additional arguments to pass to the encoder.
Returns: np.ndarray: Encoded sentences as a numpy array. """
sentences = [str(sentence) for sentence in sentences] total_sentences = len(sentences) num_batches = math.ceil(total_sentences / max_batch_size) embeddings_list = []
for batch_idx in range(num_batches): start_idx = batch_idx * max_batch_size end_idx = min(start_idx + max_batch_size, total_sentences) batch_sentences = sentences[start_idx:end_idx] batch_embeddings = self.model.encode(batch_sentences, convert_to_tensor=True)
if not isinstance(batch_embeddings, torch.Tensor): batch_embeddings = torch.tensor(batch_embeddings)
embeddings_list.append(batch_embeddings.cpu().numpy())
return np.vstack(embeddings_list)
# Wrap the SentenceTransformer model in the CustomModel classcustom_model = CustomModel(model)
# Select the MTEB tasks to evaluatetasks = mteb.get_benchmark("MTEB(eng, classic)")
# Initialize the evaluation frameworkevaluation = mteb.MTEB(tasks=tasks)
# Run evaluation and save resultsresults = evaluation.run(custom_model, output_folder="results/model_results")1234{ "max_seq_length": 512, "do_lower_case": false}1234567{ "cls_token": "[CLS]", "mask_token": "[MASK]", "pad_token": "[PAD]", "sep_token": "[SEP]", "unk_token": "[UNK]"}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556{ "added_tokens_decoder": { "0": { "content": "[PAD]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "100": { "content": "[UNK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "101": { "content": "[CLS]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "102": { "content": "[SEP]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "103": { "content": "[MASK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "clean_up_tokenization_spaces": false, "cls_token": "[CLS]", "do_lower_case": true, "extra_special_tokens": {}, "mask_token": "[MASK]", "model_max_length": 512, "pad_token": "[PAD]", "sep_token": "[SEP]", "strip_accents": null, "tokenize_chinese_chars": true, "tokenizer_class": "DistilBertTokenizer", "unk_token": "[UNK]"}.ipynb_checkpoints/mteb_eval-checkpoint.pyAdded+71
1_Pooling/config.jsonAdded+10
README.md+141-3
config.jsonAdded+24
config_sentence_transformers.jsonAdded+10
model.safetensorsAdded+3
model_card.mdAdded
modules.jsonAdded+14
mteb_eval.pyAdded+71
sentence_bert_config.jsonAdded+4
special_tokens_map.jsonAdded+7
tokenizer.jsonAdded
tokenizer_config.jsonAdded+56
vocab.txtAdded