SentenceTransformer based on google/embeddinggemma-2
This is a sentence-transformers model finetuned from google/embeddinggemma-2 on the sentence-transformers/all-nli dataset. It maps inputs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
Model Details
Model Description
- Model Type: Sentence Transformer
- Base model: google/embeddinggemma-2
- Maximum Sequence Length: 1000000000000000019884624838656 tokens
- Output Dimensionality: 768 dimensions
- Similarity Function: Cosine Similarity
- Supported Modalities: Text, Image, Audio, Video, Message
- Training Dataset:
- sentence-transformers/all-nli
- Language: en
- License: apache-2.0
Model Sources
Full Model Architecture
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'image': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'audio': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'video': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'message': {'method': 'forward', 'method_output_name': 'last_hidden_state', 'format': 'structured'}}, 'module_output_name': 'token_embeddings', 'architecture': 'EmbeddingGemma2Model'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
(2): Normalize({'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)
Usage
Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("ML-Intern-lab/embeddinggemma-2-allnli-triplet")
# Run inference
queries = [
'Two women are embracing while holding to go packages.',
]
documents = [
'Two woman are holding packages.',
'Two kids in numbered jerseys wash their hands.',
'A man selling donuts to a customer.',
]
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 embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.8584, 0.3772, 0.3133]])
Evaluation
Metrics
Triplet
| Metric | Value |
|---|
| cosine_accuracy | 0.9459 |
Training Details
Training Dataset
sentence-transformers/all-nli
- Dataset: sentence-transformers/all-nli
- Size: 557,850 training samples
- Columns: anchor, positive, and negative
- Approximate statistics based on the first 100 samples:
| anchor | positive | negative |
|---|
| type | string | string | string |
| modality | text | text | text |
| details | min: 8 tokensmean: 14.08 tokensmax: 28 tokens | min: 6 tokensmean: 13.85 tokensmax: 28 tokens | min: 5 tokensmean: 14.85 tokensmax: 28 tokens |
- Samples:
| anchor | positive | negative |
|---|
| A person on a horse jumps over a broken down airplane. | A person is outdoors, on a horse. | A person is at a diner, ordering an omelette. |
| Children smiling and waving at camera | There are children present | The kids are frowning |
| A boy is jumping on skateboard in the middle of a red bridge. | The boy does a skateboarding trick. | The boy skates down the sidewalk. |
- Loss: CachedMultipleNegativesRankingLoss with these parameters:
{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 16,
"mini_batch_num_tokens": null,
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
Evaluation Dataset
sentence-transformers/all-nli
- Dataset: sentence-transformers/all-nli
- Size: 6,584 evaluation samples
- Columns: anchor, positive, and negative
- Approximate statistics based on the first 100 samples:
| anchor | positive | negative |
|---|
| type | string | string | string |
| modality | text | text | text |
| details | min: 7 tokensmean: 17.35 tokensmax: 38 tokens | min: 5 tokensmean: 9.86 tokensmax: 28 tokens | min: 5 tokensmean: 10.28 tokensmax: 18 tokens |
- Samples:
| anchor | positive | negative |
|---|
| Two women are embracing while holding to go packages. | Two woman are holding packages. | The men are fighting outside a deli. |
| Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink. | Two kids in numbered jerseys wash their hands. | Two kids in jackets walk to school. |
| A man selling donuts to a customer during a world exhibition event held in the city of Angeles | A man selling donuts to a customer. | A woman drinks her coffee in a small cafe. |
- Loss: CachedMultipleNegativesRankingLoss with these parameters:
{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 16,
"mini_batch_num_tokens": null,
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 128
num_train_epochs: 1
max_steps: 1500
learning_rate: 2e-05
warmup_steps: 0.1
bf16: True
per_device_eval_batch_size: 128
batch_sampler: no_duplicates
All Hyperparameters
per_device_train_batch_size: 128
num_train_epochs: 1
max_steps: 1500
learning_rate: 2e-05
lr_scheduler_type: linear
lr_scheduler_kwargs: None
warmup_steps: 0.1
optim: adamw_torch_fused
optim_args: None
weight_decay: 0.0
adam_beta1: 0.9
adam_beta2: 0.999
adam_epsilon: 1e-08
optim_target_modules: None
gradient_accumulation_steps: 1
average_tokens_across_devices: True
max_grad_norm: 1.0
label_smoothing_factor: 0.0
bf16: True
fp16: False
bf16_full_eval: False
fp16_full_eval: False
tf32: None
gradient_checkpointing: False
gradient_checkpointing_kwargs: None
torch_compile: False
torch_compile_backend: None
torch_compile_mode: None
use_liger_kernel: False
liger_kernel_config: None
use_cache: False
neftune_noise_alpha: None
torch_empty_cache_steps: None
auto_find_batch_size: False
log_on_each_node: True
logging_nan_inf_filter: True
include_num_input_tokens_seen: no
log_level: passive
log_level_replica: warning
disable_tqdm: False
project: huggingface
trackio_space_id: None
trackio_bucket_id: None
trackio_static_space_id: None
per_device_eval_batch_size: 128
- : True
Training Logs
| Epoch | Step | Training Loss | Validation Loss | all-nli-dev_cosine_accuracy |
|---|
| -1 | -1 | - | - | 0.9036 |
| 0.0046 | 20 | 1.6320 | - | - |
| 0.0092 | 40 | 1.5520 | - | - |
| 0.0138 | 60 | 1.4255 | - | - |
| 0.0184 | 80 | 1.2147 | - | - |
| 0.0229 | 100 | 1.0517 | - | - |
| 0.0275 | 120 | 0.8570 | - | - |
| 0.0321 | 140 | 0.8000 | - | - |
| 0.0367 | 160 | 0.7947 | - | - |
| 0.0413 | 180 | 0.7525 | - | - |
| 0.0459 | 200 | 0.6815 | - | - |
| 0.0505 | 220 | 0.6914 | - | - |
| 0.0551 | 240 |
Training Time
- Training: 2.1 hours
- Evaluation: 12.4 minutes
- Total: 2.3 hours
Framework Versions
- Python: 3.12.12
- Sentence Transformers: 6.1.0
- Transformers: 5.19.0
- PyTorch: 2.14.1+cu130
- Accelerate: 1.15.0
- Datasets: 5.1.0
- Tokenizers: 0.23.3
Additional Resources
Citation
BibTeX
Sentence Transformers
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
CachedMultipleNegativesRankingLoss
@misc{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
MultipleNegativesRankingLoss
@misc{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}