SentenceTransformer based on nreimers/TinyBERT_L-4_H-312_v2

This is a sentence-transformers model finetuned from nreimers/TinyBERT_L-4_H-312_v2. It maps sentences & paragraphs to a 312-dimensional dense vector space and can be used for retrieval.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: nreimers/TinyBERT_L-4_H-312_v2
  • Maximum Sequence Length: 512 tokens
  • Output Dimensionality: 312 dimensions
  • Similarity Function: Cosine Similarity
  • Supported Modality: Text

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
  (1): Pooling({'embedding_dimension': 312, 'pooling_mode': 'mean', 'include_prompt': True})
)

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("tomaarsen/TinyBERT_L-4_H-312_v2-distilled-from-stsb-roberta-base-v2-l2-projection-dim")
# Run inference
sentences = [
    'A small group of children are standing in a classroom and one of them has a foot in a trashcan, which also has a rope leading out of it.',
    'Some men with jerseys are in a bar, watching a soccer match.',
    'There are two people running around a track in lane three and the one wearing a blue shirt with a green thing over the eyes is just barely ahead of the guy wearing an orange shirt and sunglasses.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 312]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.0057, 0.1346],
#         [0.0057, 1.0000, 0.2356],
#         [0.1346, 0.2356, 1.0000]])

Evaluation

Metrics

Semantic Similarity

Metric sts-dev sts-test
pearson_cosine 0.8067 0.7519
spearman_cosine 0.8179 0.7527

Training Details

Training Dataset

Unnamed Dataset

  • Size: 200,000 training samples
  • Columns: sentence and label
  • Approximate statistics based on the first 100 samples:
    sentence label
    type string list
    modality text
    details
    • min: 8 tokens
    • mean: 17.05 tokens
    • max: 52 tokens
    • size: 768 elements
  • Samples:
    sentence label
    A person on a horse jumps over a broken down airplane. [-0.477225124835968, -0.027898235246539116, 0.6169318556785583, -1.6224359273910522, 0.7474681735038757, ...]
    Children smiling and waving at camera [-0.1697935163974762, 0.9077808856964111, -0.8368250727653503, -0.47047966718673706, -0.5604732036590576, ...]
    A boy is jumping on skateboard in the middle of a red bridge. [0.6267533898353577, 0.011438215151429176, 0.47103747725486755, 0.4887479841709137, -0.3095979690551758, ...]
  • Loss: EmbedDistillLoss with these parameters:
    {
        "distance_metric": "l2",
        "projection_dim": 768
    }
    

Evaluation Dataset

Unnamed Dataset

  • Size: 10,000 evaluation samples
  • Columns: sentence and label
  • Approximate statistics based on the first 100 samples:
    sentence label
    type string list
    modality text
    details
    • min: 7 tokens
    • mean: 17.97 tokens
    • max: 45 tokens
    • size: 768 elements
  • Samples:
    sentence label
    Two women are embracing while holding to go packages. [1.3980050086975098, 0.659657895565033, -0.671194851398468, -0.3568831980228424, 0.08937378972768784, ...]
    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. [0.08953701704740524, -0.16486810147762299, -0.5275247097015381, -0.13387243449687958, 0.3173069953918457, ...]
    A man selling donuts to a customer during a world exhibition event held in the city of Angeles [-0.18134362995624542, -0.27244624495506287, 0.6053312420845032, 0.4879472851753235, -0.4728725850582123, ...]
  • Loss: EmbedDistillLoss with these parameters:
    {
        "distance_metric": "l2",
        "projection_dim": 768
    }
    

Training Hyperparameters

Non-Default Hyperparameters

  • per_device_train_batch_size: 64
  • num_train_epochs: 1
  • learning_rate: 0.0001
  • warmup_steps: 0.1
  • fp16: True
  • per_device_eval_batch_size: 64
  • load_best_model_at_end: True

All Hyperparameters

Click to expand
  • per_device_train_batch_size: 64
  • num_train_epochs: 1
  • max_steps: -1
  • learning_rate: 0.0001
  • 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: False
  • fp16: True
  • 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: 64
  • prediction_loss_only: True
  • eval_on_start: False
  • eval_do_concat_batches: True
  • eval_use_gather_object: False
  • eval_accumulation_steps: None
  • include_for_metrics: []
  • batch_eval_metrics: False
  • save_only_model: False
  • save_on_each_node: False
  • enable_jit_checkpoint: False
  • push_to_hub: False
  • hub_private_repo: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_always_push: False
  • hub_revision: None
  • load_best_model_at_end: True
  • ignore_data_skip: False
  • restore_callback_states_from_checkpoint: False
  • full_determinism: False
  • seed: 42
  • data_seed: None
  • use_cpu: False
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
  • parallelism_config: None
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • dataloader_prefetch_factor: None
  • remove_unused_columns: True
  • label_names: None
  • train_sampling_strategy: random
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • ddp_static_graph: None
  • ddp_backend: None
  • ddp_timeout: 1800
  • fsdp: []
  • fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • deepspeed: None
  • debug: []
  • skip_memory_metrics: True
  • do_predict: False
  • resume_from_checkpoint: None
  • warmup_ratio: None
  • local_rank: -1
  • prompts: None
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: proportional
  • router_mapping: {}
  • learning_rate_mapping: {}

Training Logs

Epoch Step Training Loss Validation Loss sts-dev_spearman_cosine sts-test_spearman_cosine
0.032 100 17.0924 - - -
0.064 200 16.3837 - - -
0.096 300 15.4577 - - -
0.128 400 14.6605 - - -
0.16 500 14.0485 14.8161 0.7556 -
0.192 600 13.6083 - - -
0.224 700 13.2582 - - -
0.256 800 13.0273 - - -
0.288 900 12.7415 - - -
0.32 1000 12.4973 13.8560 0.7917 -
0.352 1100 12.3093 - - -
0.384 1200 12.1469 - - -
0.416 1300 11.9946 - - -
0.448 1400 11.8697 - - -
0.48 1500 11.8071 13.3636 0.8088 -
0.512 1600 11.6223 - - -
0.544 1700 11.5605 - - -
0.576 1800 11.4829 - - -
0.608 1900 11.3819 - - -
0.64 2000 11.3183 13.0767 0.8133 -
0.672 2100 11.2797 - - -
0.704 2200 11.2391 - - -
0.736 2300 11.1939 - - -
0.768 2400 11.1179 - - -
0.8 2500 11.0593 12.9171 0.8168 -
0.832 2600 11.0083 - - -
0.864 2700 11.0123 - - -
0.896 2800 10.9796 - - -
0.928 2900 10.9729 - - -
0.96 3000 10.9730 12.8228 0.8176 -
0.992 3100 10.9220 - - -
1.0 3125 - 12.8125 0.8179 -
-1 -1 - - - 0.7527
  • The bold row denotes the saved checkpoint.

Training Time

  • Training: 3.3 minutes
  • Evaluation: 1.0 minutes
  • Total: 4.3 minutes

Framework Versions

  • Python: 3.11.6
  • Sentence Transformers: 5.5.0.dev0
  • Transformers: 5.6.2
  • PyTorch: 2.10.0+cu128
  • Accelerate: 1.13.0.dev0
  • Datasets: 4.8.4
  • Tokenizers: 0.22.2

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",
}

EmbedDistillLoss

@article{kim2023embeddistill,
    title={EmbedDistill: A Geometric Knowledge Distillation for Information Retrieval},
    author={Kim, Seungyeon and Rawat, Ankit Singh and Zaheer, Manzil and Jayasumana, Sadeep and Sadhanala, Veeranjaneyulu and Jitkrittum, Wittawat and Menon, Aditya Krishna and Fergus, Rob and Kumar, Sanjiv},
    year={2023},
    eprint={2301.12005},
    archivePrefix={arXiv},
    primaryClass={cs.IR}
}
Downloads last month
28
Safetensors
Model size
14.4M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for tomaarsen/TinyBERT_L-4_H-312_v2-distilled-from-stsb-roberta-base-v2-l2-projection-dim

Finetuned
(9)
this model

Papers for tomaarsen/TinyBERT_L-4_H-312_v2-distilled-from-stsb-roberta-base-v2-l2-projection-dim

Evaluation results