sentence-transformers/natural-questions
Viewer • Updated • 100k • 4.82k • 50
How to use tomaarsen/inference-free-splade-bert-tiny-nq-3e-6-lambda-corpus with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("tomaarsen/inference-free-splade-bert-tiny-nq-3e-6-lambda-corpus")
sentences = [
"where is the tiber river located in italy",
"Sales taxes in British Columbia On 1 July 2010, the PST and GST were combined into the Harmonized Sales Tax (HST) levied according to the provisions of the GST. The conversion to HST was controversial. Popular opposition led to a referendum on the tax system, the first such referendum in the Commonwealth of Nations, resulting in the province reverting to the former PST/GST model on 1 April 2013.",
"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.",
"Water in California California's limited water supply comes from two main sources: surface water, or water that travels or gathers on the ground, like rivers, streams, and lakes; and groundwater, which is water that is pumped out from the ground. California has also begun producing a small amount of desalinated water, water that was once sea water, but has been purified."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a Asymmetric Inference-free 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.
SparseEncoder(
(0): Asym(
(query_0_IDF): IDF ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
(corpus_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
(corpus_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SparseEncoder
# Download from the 🤗 Hub
model = SparseEncoder("tomaarsen/inference-free-splade-bert-tiny-nq-3e-6-lambda-corpus")
# Run inference
sentences = [
'when did the american civil rights movement end',
'African-American civil rights movement (1954–1968) The Civil Rights Movement (also known as the American civil rights movement, African-American civil rights movement, and other terms,[b]) was a human rights movement from 1954–1968 that encompassed strategies, groups, and social movements to accomplish its goal of ending legalized racial segregation and discrimination laws in the United States. The movement secured the legal recognition and federal protection of black Americans in the United States Constitution and federal law.',
'Paleolithic Paleolithic humans made tools of stone, bone, and wood.[23] The early paleolithic hominins, Australopithecus, were the first users of stone tools. Excavations in Gona, Ethiopia have produced thousands of artifacts, and through radioisotopic dating and magnetostratigraphy, the sites can be firmly dated to 2.6Â\xa0million years ago. Evidence shows these early hominins intentionally selected raw materials with good flaking qualities and chose appropriate sized stones for their needs to produce sharp-edged tools for cutting.[29]',
]
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]
NanoMSMARCO, NanoNFCorpus and NanoNQSparseInformationRetrievalEvaluator| Metric | NanoMSMARCO | NanoNFCorpus | NanoNQ |
|---|---|---|---|
| dot_accuracy@1 | 0.28 | 0.44 | 0.28 |
| dot_accuracy@3 | 0.54 | 0.58 | 0.6 |
| dot_accuracy@5 | 0.68 | 0.58 | 0.7 |
| dot_accuracy@10 | 0.74 | 0.64 | 0.78 |
| dot_precision@1 | 0.28 | 0.44 | 0.28 |
| dot_precision@3 | 0.18 | 0.3867 | 0.2 |
| dot_precision@5 | 0.136 | 0.296 | 0.14 |
| dot_precision@10 | 0.074 | 0.248 | 0.078 |
| dot_recall@1 | 0.28 | 0.0433 | 0.27 |
| dot_recall@3 | 0.54 | 0.077 | 0.58 |
| dot_recall@5 | 0.68 | 0.0882 | 0.66 |
| dot_recall@10 | 0.74 | 0.1144 | 0.72 |
| dot_ndcg@10 | 0.5067 | 0.3143 | 0.5073 |
| dot_mrr@10 | 0.4317 | 0.5101 | 0.4507 |
| dot_map@100 | 0.4433 | 0.1363 | 0.4421 |
NanoBEIR_meanSparseNanoBEIREvaluator with these parameters:{
"dataset_names": [
"msmarco",
"nfcorpus",
"nq"
]
}
| Metric | Value |
|---|---|
| dot_accuracy@1 | 0.3333 |
| dot_accuracy@3 | 0.5733 |
| dot_accuracy@5 | 0.6533 |
| dot_accuracy@10 | 0.72 |
| dot_precision@1 | 0.3333 |
| dot_precision@3 | 0.2556 |
| dot_precision@5 | 0.1907 |
| dot_precision@10 | 0.1333 |
| dot_recall@1 | 0.1978 |
| dot_recall@3 | 0.399 |
| dot_recall@5 | 0.4761 |
| dot_recall@10 | 0.5248 |
| dot_ndcg@10 | 0.4428 |
| dot_mrr@10 | 0.4642 |
| dot_map@100 | 0.3406 |
query and corpus| query | corpus | |
|---|---|---|
| type | dict | dict |
| details |
| query | corpus |
|---|---|
{'query': "who played the father in papa don't preach"} |
{'corpus': 'Alex McArthur Alex McArthur (born March 6, 1957) is an American actor.'} |
{'query': 'where was the location of the battle of hastings'} |
{'corpus': '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.'} |
{'query': 'how many puppies can a dog give birth to'} |
{'corpus': '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]'} |
SpladeLoss with these parameters:{'loss': SparseMultipleNegativesRankingLoss(
(model): SparseEncoder(
(0): Asym(
(query_0_IDF): IDF ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
(corpus_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
(corpus_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)
)
(cross_entropy_loss): CrossEntropyLoss()
), 'lambda_corpus': 3e-06, 'lambda_query': 0, 'corpus_regularizer': FlopsLoss(
(model): SparseEncoder(
(0): Asym(
(query_0_IDF): IDF ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
(corpus_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
(corpus_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)
)
), 'query_regularizer': None}
query and corpus| query | corpus | |
|---|---|---|
| type | dict | dict |
| details |
| query | corpus |
|---|---|
{'query': 'where is the tiber river located in italy'} |
{'corpus': '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\xa0mi) 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\xa0sq\xa0mi). The river has achieved lasting fame as the main watercourse of the city of Rome, founded on its eastern banks.'} |
{'query': 'what kind of car does jay gatsby drive'} |
{'corpus': '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.'} |
{'query': 'who sings if i can dream about you'} |
{'corpus': '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]'} |
SpladeLoss with these parameters:{'loss': SparseMultipleNegativesRankingLoss(
(model): SparseEncoder(
(0): Asym(
(query_0_IDF): IDF ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
(corpus_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
(corpus_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)
)
(cross_entropy_loss): CrossEntropyLoss()
), 'lambda_corpus': 3e-06, 'lambda_query': 0, 'corpus_regularizer': FlopsLoss(
(model): SparseEncoder(
(0): Asym(
(query_0_IDF): IDF ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
(corpus_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
(corpus_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)
)
), 'query_regularizer': None}
eval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | Validation Loss | NanoMSMARCO_dot_ndcg@10 | NanoNFCorpus_dot_ndcg@10 | NanoNQ_dot_ndcg@10 | NanoBEIR_mean_dot_ndcg@10 |
|---|---|---|---|---|---|---|---|
| 0.0129 | 20 | 1.5408 | - | - | - | - | - |
| 0.0259 | 40 | 1.4811 | - | - | - | - | - |
| 0.0388 | 60 | 1.2964 | - | - | - | - | - |
| 0.0517 | 80 | 0.9822 | - | - | - | - | - |
| 0.0646 | 100 | 0.6764 | - | - | - | - | - |
| 0.0776 | 120 | 0.547 | - | - | - | - | - |
| 0.0905 | 140 | 0.4755 | - | - | - | - | - |
| 0.1034 | 160 | 0.4212 | - | - | - | - | - |
| 0.1164 | 180 | 0.4562 | - | - | - | - | - |
| 0.1293 | 200 | 0.4057 | 0.3378 | 0.4848 | 0.3101 | 0.4742 | 0.4230 |
| 0.1422 | 220 | 0.3772 | - | - | - | - | - |
| 0.1551 | 240 | 0.3516 | - | - | - | - | - |
| 0.1681 | 260 | 0.3768 | - | - | - | - | - |
| 0.1810 | 280 | 0.3357 | - | - | - | - | - |
| 0.1939 | 300 | 0.3209 | - | - | - | - | - |
| 0.2069 | 320 | 0.3221 | - | - | - | - | - |
| 0.2198 | 340 | 0.3183 | - | - | - | - | - |
| 0.2327 | 360 | 0.3182 | - | - | - | - | - |
| 0.2456 | 380 | 0.333 | - | - | - | - | - |
| 0.2586 | 400 | 0.2946 | 0.2770 | 0.5115 | 0.3062 | 0.4842 | 0.4340 |
| 0.2715 | 420 | 0.295 | - | - | - | - | - |
| 0.2844 | 440 | 0.3019 | - | - | - | - | - |
| 0.2973 | 460 | 0.2882 | - | - | - | - | - |
| 0.3103 | 480 | 0.3203 | - | - | - | - | - |
| 0.3232 | 500 | 0.3215 | - | - | - | - | - |
| 0.3361 | 520 | 0.3018 | - | - | - | - | - |
| 0.3491 | 540 | 0.2918 | - | - | - | - | - |
| 0.3620 | 560 | 0.3365 | - | - | - | - | - |
| 0.3749 | 580 | 0.2847 | - | - | - | - | - |
| 0.3878 | 600 | 0.3382 | 0.2605 | 0.5192 | 0.3093 | 0.5002 | 0.4429 |
| 0.4008 | 620 | 0.2845 | - | - | - | - | - |
| 0.4137 | 640 | 0.2529 | - | - | - | - | - |
| 0.4266 | 660 | 0.2885 | - | - | - | - | - |
| 0.4396 | 680 | 0.2853 | - | - | - | - | - |
| 0.4525 | 700 | 0.2711 | - | - | - | - | - |
| 0.4654 | 720 | 0.2331 | - | - | - | - | - |
| 0.4783 | 740 | 0.2612 | - | - | - | - | - |
| 0.4913 | 760 | 0.2751 | - | - | - | - | - |
| 0.5042 | 780 | 0.2458 | - | - | - | - | - |
| 0.5171 | 800 | 0.2829 | 0.2475 | 0.5167 | 0.3117 | 0.5019 | 0.4434 |
| 0.5301 | 820 | 0.2698 | - | - | - | - | - |
| 0.5430 | 840 | 0.2455 | - | - | - | - | - |
| 0.5559 | 860 | 0.2769 | - | - | - | - | - |
| 0.5688 | 880 | 0.2569 | - | - | - | - | - |
| 0.5818 | 900 | 0.2404 | - | - | - | - | - |
| 0.5947 | 920 | 0.2538 | - | - | - | - | - |
| 0.6076 | 940 | 0.2449 | - | - | - | - | - |
| 0.6206 | 960 | 0.2649 | - | - | - | - | - |
| 0.6335 | 980 | 0.271 | - | - | - | - | - |
| 0.6464 | 1000 | 0.2081 | 0.2382 | 0.5087 | 0.3114 | 0.5082 | 0.4427 |
| 0.6593 | 1020 | 0.2627 | - | - | - | - | - |
| 0.6723 | 1040 | 0.2519 | - | - | - | - | - |
| 0.6852 | 1060 | 0.2463 | - | - | - | - | - |
| 0.6981 | 1080 | 0.2565 | - | - | - | - | - |
| 0.7111 | 1100 | 0.2586 | - | - | - | - | - |
| 0.7240 | 1120 | 0.2521 | - | - | - | - | - |
| 0.7369 | 1140 | 0.2441 | - | - | - | - | - |
| 0.7498 | 1160 | 0.2595 | - | - | - | - | - |
| 0.7628 | 1180 | 0.2612 | - | - | - | - | - |
| 0.7757 | 1200 | 0.2623 | 0.2324 | 0.5019 | 0.3129 | 0.5073 | 0.4407 |
| 0.7886 | 1220 | 0.2393 | - | - | - | - | - |
| 0.8016 | 1240 | 0.2606 | - | - | - | - | - |
| 0.8145 | 1260 | 0.2328 | - | - | - | - | - |
| 0.8274 | 1280 | 0.271 | - | - | - | - | - |
| 0.8403 | 1300 | 0.2556 | - | - | - | - | - |
| 0.8533 | 1320 | 0.2468 | - | - | - | - | - |
| 0.8662 | 1340 | 0.2389 | - | - | - | - | - |
| 0.8791 | 1360 | 0.2354 | - | - | - | - | - |
| 0.8920 | 1380 | 0.2331 | - | - | - | - | - |
| 0.9050 | 1400 | 0.2345 | 0.2303 | 0.5073 | 0.3139 | 0.5072 | 0.4428 |
| 0.9179 | 1420 | 0.2364 | - | - | - | - | - |
| 0.9308 | 1440 | 0.2125 | - | - | - | - | - |
| 0.9438 | 1460 | 0.2634 | - | - | - | - | - |
| 0.9567 | 1480 | 0.259 | - | - | - | - | - |
| 0.9696 | 1500 | 0.2496 | - | - | - | - | - |
| 0.9825 | 1520 | 0.2563 | - | - | - | - | - |
| 0.9955 | 1540 | 0.2475 | - | - | - | - | - |
| -1 | -1 | - | - | 0.5067 | 0.3143 | 0.5073 | 0.4428 |
Carbon emissions were measured using CodeCarbon.
@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",
}
@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},
}