Sentence Similarity
sentence-transformers
ONNX
Safetensors
Transformers
Transformers.js
English
bert
feature-extraction
text-embeddings-inference
information-retrieval
knowledge-distillation
Instructions to use MongoDB/mdbr-leaf-ir with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use MongoDB/mdbr-leaf-ir with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("MongoDB/mdbr-leaf-ir") 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 MongoDB/mdbr-leaf-ir with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("MongoDB/mdbr-leaf-ir") model = AutoModel.from_pretrained("MongoDB/mdbr-leaf-ir", device_map="auto") - Transformers.js
How to use MongoDB/mdbr-leaf-ir with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('feature-extraction', 'MongoDB/mdbr-leaf-ir'); - Inference
- Notebooks
- Google Colab
- Kaggle
Upload 13 files
Browse filesFiles changed (13)
- 1_Pooling/config.jsonAdded+10
- 2_Dense/config.jsonAdded+6
- 2_Dense/model.safetensorsAdded+3
- README.md+146-1
- config.jsonAdded+25
- config_sentence_transformers.jsonAdded+14
- model.safetensorsAdded+3
- modules.jsonAdded+26
- sentence_bert_config.jsonAdded+7
- special_tokens_map.jsonAdded+37
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+65
- vocab.txtAdded
12345678910{
"word_embedding_dimension": 384,
"pooling_mode_cls_token": false,
"pooling_mode_mean_tokens": true,
"pooling_mode_max_tokens": false,
"pooling_mode_mean_sqrt_len_tokens": false,
"pooling_mode_weightedmean_tokens": false,
"pooling_mode_lasttoken": false,
"include_prompt": true
}123456{
"in_features": 384,
"out_features": 768,
"bias": true,
"activation_function": "torch.nn.modules.linear.Identity"
}123version https://git-lfs.github.com/spec/v1oid sha256:9f00416089539f4eeee06a1e6cdcfabd075243c208e0d995beb2f7c516e08c4dsize 1182880123---license: apache-2.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148---tags:- sentence-transformers- sentence-similarity- feature-extraction- densebase_model: sentence-transformers/all-MiniLM-L6-v2pipeline_tag: sentence-similaritylibrary_name: sentence-transformers---# SentenceTransformer based on sentence-transformers/all-MiniLM-L6-v2This is a [sentence-transformers](https://www.SBERT.net) model finetuned from [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2). 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:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) <!-- at revision c9745ed1d9f207416be6d2e6f8de32d1f16199bf -->- **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, 'architecture': 'BertModel'})(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})(2): Dense({'in_features': 384, 'out_features': 768, 'bias': True, 'activation_function': 'torch.nn.modules.linear.Identity'})(3): Normalize())```## 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 inferencequeries = ["Which planet is known as the Red Planet?",]documents = ["Venus is often called Earth's twin because of its similar size and proximity.",'Mars, known for its reddish appearance, is often referred to as the Red Planet.','Saturn, famous for its rings, is sometimes mistaken for the Red Planet.',]query_embeddings = model.encode_query(queries)document_embeddings = model.encode_document(documents)print(query_embeddings.shape, document_embeddings.shape)# [1, 768] [3, 768]# Get the similarity scores for the embeddingssimilarities = model.similarity(query_embeddings, document_embeddings)print(similarities)# tensor([[0.4166, 0.6312, 0.5094]])```<!--### 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.12.7- Sentence Transformers: 5.1.0- Transformers: 4.52.4- PyTorch: 2.6.0+cu126- Accelerate: 1.2.1- Datasets: 3.1.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.*-->
12345678910111213141516171819202122232425{
"architectures": [
"BertModel"
],
"attention_probs_dropout_prob": 0.1,
"classifier_dropout": null,
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 384,
"initializer_range": 0.02,
"intermediate_size": 1536,
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"num_attention_heads": 12,
"num_hidden_layers": 6,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"torch_dtype": "float32",
"transformers_version": "4.52.4",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}1234567891011121314{
"model_type": "SentenceTransformer",
"__version__": {
"sentence_transformers": "5.1.0",
"transformers": "4.52.4",
"pytorch": "2.6.0+cu126"
},
"prompts": {
"query": "Represent this sentence for searching relevant passages: ",
"document": ""
},
"default_prompt_name": null,
"similarity_fn_name": "cosine"
}123version https://git-lfs.github.com/spec/v1oid sha256:c09fb7428e9fd30cb4fbf3c3b0a7a7146723e04eb5a8aee5826ba7788dc3c5f0size 902726561234567891011121314151617181920212223242526[
{
"idx": 0,
"name": "0",
"path": "",
"type": "sentence_transformers.models.Transformer"
},
{
"idx": 1,
"name": "1",
"path": "1_Pooling",
"type": "sentence_transformers.models.Pooling"
},
{
"idx": 2,
"name": "2",
"path": "2_Dense",
"type": "sentence_transformers.models.Dense"
},
{
"idx": 3,
"name": "3",
"path": "3_Normalize",
"type": "sentence_transformers.models.Normalize"
}
]1234567{
"max_seq_length": 512,
"do_lower_case": false,
"model_args": {
"add_pooling_layer": false
}
}12345678910111213141516171819202122232425262728293031323334353637{
"cls_token": {
"content": "[CLS]",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"mask_token": {
"content": "[MASK]",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "[PAD]",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"sep_token": {
"content": "[SEP]",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "[UNK]",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465{
"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_basic_tokenize": true,
"do_lower_case": true,
"extra_special_tokens": {},
"mask_token": "[MASK]",
"max_length": 128,
"model_max_length": 512,
"never_split": null,
"pad_to_multiple_of": null,
"pad_token": "[PAD]",
"pad_token_type_id": 0,
"padding_side": "right",
"sep_token": "[SEP]",
"stride": 0,
"strip_accents": null,
"tokenize_chinese_chars": true,
"tokenizer_class": "BertTokenizer",
"truncation_side": "right",
"truncation_strategy": "longest_first",
"unk_token": "[UNK]"
}1_Pooling/config.jsonAdded+10
2_Dense/config.jsonAdded+6
2_Dense/model.safetensorsAdded+3
README.md+146-1
config.jsonAdded+25
config_sentence_transformers.jsonAdded+14
model.safetensorsAdded+3
modules.jsonAdded+26
sentence_bert_config.jsonAdded+7
special_tokens_map.jsonAdded+37
tokenizer.jsonAdded
tokenizer_config.jsonAdded+65
vocab.txtAdded