CoolFace
Modelpublic

sparse-encoder-testing/splade-bert-tiny-nq

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes104kdownloads
Model Card

SPLADE BERT-tiny trained on Natural-Questions tuples

This is a SPLADE Sparse Encoder model trained on the natural-questions dataset using the sentence-transformers library. It maps sentences & paragraphs to a 30522-dimensional sparse vector space and can be used for semantic search and sparse retrieval.

This model was trained using train_script.py.

Model Details

Model Description

  • Model Type: SPLADE Sparse Encoder <!-- - Base model: Unknown -->
  • Maximum Sequence Length: 512 tokens
  • Output Dimensionality: 30522 dimensions
  • Similarity Function: Dot Product
  • Training Dataset:
  • natural-questions
  • Language: en
  • License: apache-2.0

Model Sources

Full Model Architecture

SparseEncoder(
  (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
  (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)

Usage

Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

bash
pip install -U sentence-transformers

Then you can load this model and run inference.

python
from sentence_transformers import SparseEncoder

# Download from the 🤗 Hub
model = SparseEncoder("sparse-encoder-testing/splade-bert-tiny-nq")
# Run inference
sentences = [
    'is send in the clowns from a musical',
    'Send In the Clowns "Send In the Clowns" is a song written by Stephen Sondheim for the 1973 musical A Little Night Music, an adaptation of Ingmar Bergman\'s film Smiles of a Summer Night. It is a ballad from Act Two, in which the character Desirée reflects on the ironies and disappointments of her life. Among other things, she looks back on an affair years earlier with the lawyer Fredrik, who was deeply in love with her but whose marriage proposals she had rejected. Meeting him after so long, she realizes she is in love with him and finally ready to marry him, but now it is he who rejects her: he is in an unconsummated marriage with a much younger woman. Desirée proposes marriage to rescue him from this situation, but he declines, citing his dedication to his bride. Reacting to his rejection, Desirée sings this song. The song is later reprised as a coda after Fredrik\'s young wife runs away with his son, and Fredrik is finally free to accept Desirée\'s offer.[1]',
    'The Suite Life on Deck The Suite Life on Deck is an American sitcom that aired on Disney Channel from September 26, 2008 to May 6, 2011. It is a sequel/spin-off of the Disney Channel Original Series The Suite Life of Zack & Cody. The series follows twin brothers Zack and Cody Martin and hotel heiress London Tipton in a new setting, the SS Tipton, where they attend classes at "Seven Seas High School" and meet Bailey Pickett while Mr. Moseby manages the ship. The ship travels around the world to nations such as Italy, France, Greece, India, Sweden and the United Kingdom where the characters experience different cultures, adventures, and situations.[1]',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# (3, 30522)

# Get the similarity scores for the embeddings
similarities = 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. -->

Evaluation

Metrics

Sparse Information Retrieval
MetricNanoMSMARCONanoNFCorpusNanoNQ
dot_accuracy@10.220.240.1
dot_accuracy@30.360.380.24
dot_accuracy@50.40.480.34
dot_accuracy@100.540.580.44
dot_precision@10.220.240.1
dot_precision@30.120.21330.08
dot_precision@50.080.1840.068
dot_precision@100.0540.160.046
dot_recall@10.220.01910.09
dot_recall@30.360.03650.22
dot_recall@50.40.04330.32
dot_recall@100.540.06240.41
dot_ndcg@100.35710.18250.2484
dot_mrr@100.30110.33090.2051
dot_map@1000.3160.0640.2087
Sparse Nano BEIR
json
  {
      "dataset_names": [
          "msmarco",
          "nfcorpus",
          "nq"
      ]
  }
MetricValue
dot_accuracy@10.1867
dot_accuracy@30.3267
dot_accuracy@50.4067
dot_accuracy@100.52
dot_precision@10.1867
dot_precision@30.1378
dot_precision@50.1107
dot_precision@100.0867
dot_recall@10.1097
dot_recall@30.2055
dot_recall@50.2544
dot_recall@100.3375
dot_ndcg@100.2627
dot_mrr@100.2791
dot_map@1000.1962

<!--

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

Training Dataset

natural-questions
  • Dataset: natural-questions at f9e894e
  • Size: 99,000 training samples
  • Columns: <code>query</code> and <code>answer</code>
  • Approximate statistics based on the first 1000 samples: | | query | answer | |:--------|:-----------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------| | type | string | string | | details | <ul><li>min: 29 characters</li><li>mean: 46.96 characters</li><li>max: 93 characters</li></ul> | <ul><li>min: 10 characters</li><li>mean: 582.13 characters</li><li>max: 2141 characters</li></ul> |
  • Samples: | query | answer | |:--------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | <code>who played the father in papa don't preach</code> | <code>Alex McArthur Alex McArthur (born March 6, 1957) is an American actor.</code> | | <code>where was the location of the battle of hastings</code> | <code>Battle of Hastings The Battle of Hastings[a] was fought on 14 October 1066 between the Norman-French army of William, the Duke of Normandy, and an English army under the Anglo-Saxon King Harold Godwinson, beginning the Norman conquest of England. It took place approximately 7 miles (11 kilometres) northwest of Hastings, close to the present-day town of Battle, East Sussex, and was a decisive Norman victory.</code> | | <code>how many puppies can a dog give birth to</code> | <code>Canine reproduction The largest litter size to date was set by a Neapolitan Mastiff in Manea, Cambridgeshire, UK on November 29, 2004; the litter was 24 puppies.[22]</code> |
  • Loss: <code>SpladeLoss</code> with these parameters:
json
  {'loss': SparseMultipleNegativesRankingLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
    (cross_entropy_loss): CrossEntropyLoss()
  ), 'lambda_corpus': 3e-05, 'lambda_query': 5e-05, 'corpus_regularizer': FlopsLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
  ), 'query_regularizer': FlopsLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
  )}

Evaluation Dataset

natural-questions
  • Dataset: natural-questions at f9e894e
  • Size: 1,000 evaluation samples
  • Columns: <code>query</code> and <code>answer</code>
  • Approximate statistics based on the first 1000 samples: | | query | answer | |:--------|:----------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------| | type | string | string | | details | <ul><li>min: 30 characters</li><li>mean: 47.2 characters</li><li>max: 96 characters</li></ul> | <ul><li>min: 58 characters</li><li>mean: 598.96 characters</li><li>max: 2480 characters</li></ul> |
  • Samples: | query | answer | |:-------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | <code>where is the tiber river located in italy</code> | <code>Tiber The Tiber (/ˈtaɪbər/, Latin: Tiberis,[1] Italian: Tevere [ˈteːvere])[2] is the third-longest river in Italy, rising in the Apennine Mountains in Emilia-Romagna and flowing 406 kilometres (252 mi) through Tuscany, Umbria and Lazio, where it is joined by the river Aniene, to the Tyrrhenian Sea, between Ostia and Fiumicino.[3] It drains a basin estimated at 17,375 square kilometres (6,709 sq mi). The river has achieved lasting fame as the main watercourse of the city of Rome, founded on its eastern banks.</code> | | <code>what kind of car does jay gatsby drive</code> | <code>Jay Gatsby At the Buchanan home, Jordan Baker, Nick, Jay, and the Buchanans decide to visit New York City. Tom borrows Gatsby's yellow Rolls Royce to drive up to the city. On the way to New York City, Tom makes a detour at a gas station in "the Valley of Ashes", a run-down part of Long Island. The owner, George Wilson, shares his concern that his wife, Myrtle, may be having an affair. This unnerves Tom, who has been having an affair with Myrtle, and he leaves in a hurry.</code> | | <code>who sings if i can dream about you</code> | <code>I Can Dream About You "I Can Dream About You" is a song performed by American singer Dan Hartman on the soundtrack album of the film Streets of Fire. Released in 1984 as a single from the soundtrack, and included on Hartman's album I Can Dream About You, it reached number 6 on the Billboard Hot 100.[1]</code> |
  • Loss: <code>SpladeLoss</code> with these parameters:
json
  {'loss': SparseMultipleNegativesRankingLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
    (cross_entropy_loss): CrossEntropyLoss()
  ), 'lambda_corpus': 3e-05, 'lambda_query': 5e-05, 'corpus_regularizer': FlopsLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
  ), 'query_regularizer': FlopsLoss(
    (model): SparseEncoder(
      (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM 
      (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
    )
  )}

Training Hyperparameters

Non-Default Hyperparameters
  • eval_strategy: steps
  • per_device_train_batch_size: 64
  • per_device_eval_batch_size: 64
  • learning_rate: 2e-05
  • num_train_epochs: 1
  • warmup_ratio: 0.1
  • fp16: True
  • batch_sampler: no_duplicates
All Hyperparameters

<details><summary>Click to expand</summary>

  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: steps
  • prediction_loss_only: True
  • per_device_train_batch_size: 64
  • per_device_eval_batch_size: 64
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 2e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1.0
  • num_train_epochs: 1
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.1
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 42
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: False
  • fp16: True
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: False
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'minnumparams': 0, 'xla': False, 'xlafsdpv2': False, 'xlafsdpgrad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'splitbatches': False, 'dispatchbatches': None, 'evenbatches': True, 'useseedablesampler': True, 'nonblocking': False, 'gradientaccumulationkwargs': None}
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: False
  • resume_from_checkpoint: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_private_repo: None
  • hub_always_push: False
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • include_for_metrics: []
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • dispatch_batches: None
  • split_batches: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • use_liger_kernel: False
  • eval_use_gather_object: False
  • average_tokens_across_devices: False
  • prompts: None
  • batch_sampler: no_duplicates
  • multi_dataset_batch_sampler: proportional

</details>

Training Logs

EpochStepTraining LossValidation LossNanoMSMARCO_dot_ndcg@10NanoNFCorpus_dot_ndcg@10NanoNQ_dot_ndcg@10NanoBEIR_mean_dot_ndcg@10
0.0129201688.0217-----
0.0259401557.9103-----
0.0388601205.4178-----
0.051780692.3048-----
0.0646100297.4244-----
0.0776120144.2392-----
0.090514075.7438-----
0.103416035.3506-----
0.116418020.7095-----
0.129320012.54466.90480.15240.07840.05740.0961
0.14222208.1351-----
0.15512406.1495-----
0.16812604.4986-----
0.18102803.5353-----
0.19393003.0714-----
0.20693202.4237-----
0.21983401.9325-----
0.23273601.8585-----
0.24563801.491-----
0.25864001.45030.85410.22480.13220.10450.1538
0.27154201.3789-----
0.28444401.3195-----
0.29734601.198-----
0.31034801.1532-----
0.32325001.1931-----
0.33615201.1989-----
0.34915401.008-----
0.36205600.9798-----
0.37495800.9551-----
0.38786000.96870.43560.27090.14380.15190.1888
0.40086200.8331-----
0.41376400.6947-----
0.42666600.7768-----
0.43966800.7101-----
0.45257000.6902-----
0.46547200.6766-----
0.47837400.6001-----
0.49137600.6231-----
0.50427800.5953-----
0.51718000.68460.30680.29580.15430.20710.2190
0.53018200.5851-----
0.54308400.579-----
0.55598600.5659-----
0.56888800.553-----
0.58189000.4812-----
0.59479200.5389-----
0.60769400.4658-----
0.62069600.5309-----
0.63359800.484-----
0.646410000.46550.25270.31310.16600.22940.2362
0.659310200.5617-----
0.672310400.4786-----
0.685210600.5561-----
0.698110800.4869-----
0.711111000.5134-----
0.724011200.4702-----
0.736911400.4481-----
0.749811600.4758-----
0.762811800.4625-----
0.775712000.47330.23300.34980.17480.23570.2534
0.788612200.4527-----
0.801612400.4735-----
0.814512600.3818-----
0.827412800.4546-----
0.840313000.4724-----
0.853313200.4194-----
0.866213400.4352-----
0.879113600.3926-----
0.892013800.397-----
0.905014000.41570.22060.35580.17850.24950.2613
0.917914200.4426-----
0.930814400.4077-----
0.943814600.4227-----
0.956714800.4184-----
0.969615000.4838-----
0.982515200.4991-----
0.995515400.3889-----
-1-1--0.35710.18250.24840.2627

Environmental Impact

Carbon emissions were measured using CodeCarbon.

  • Energy Consumed: 0.027 kWh
  • Carbon Emitted: 0.011 kg of CO2
  • Hours Used: 0.082 hours

Training Hardware

  • On Cloud: No
  • GPU Model: 1 x NVIDIA GeForce RTX 3090
  • CPU Model: 13th Gen Intel(R) Core(TM) i7-13700K
  • RAM Size: 31.78 GB

Framework Versions

  • Python: 3.11.6
  • Sentence Transformers: 4.2.0.dev0
  • Transformers: 4.49.0
  • PyTorch: 2.6.0+cu124
  • Accelerate: 1.5.1
  • Datasets: 2.21.0
  • Tokenizers: 0.21.1

Citation

BibTeX

Sentence Transformers
bibtex
@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",
}
SpladeLoss
bibtex
@misc{formal2022distillationhardnegativesampling,
      title={From Distillation to Hard Negative Sampling: Making Sparse Neural IR Models More Effective},
      author={Thibault Formal and Carlos Lassance and Benjamin Piwowarski and Stéphane Clinchant},
      year={2022},
      eprint={2205.04733},
      archivePrefix={arXiv},
      primaryClass={cs.IR},
      url={https://arxiv.org/abs/2205.04733},
}

<!--

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. -->