Views
No views yet
SparseEncoder(
(0): MLMTransformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': 'DistilBertForMaskedLM'})
(1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
)pip install -U sentence-transformers1from sentence_transformers import SparseEncoder
2
3# Download from the 🤗 Hub
4model = SparseEncoder("tomaarsen/splade-distilbert-base-uncased-nq-16bs")
5# Run inference
6queries = [
7 "who is cornelius in the book of acts",
8]
9documents = [
10 'Cornelius the Centurion Cornelius (Greek: Κορνήλιος) was a Roman centurion who is considered by Christians to be one of the first Gentiles to convert to the faith, as related in Acts of the Apostles.',
11 "Joe Ranft Ranft reunited with Lasseter when he was hired by Pixar in 1991 as their head of story.[1] There he worked on all of their films produced up to 2006; this included Toy Story (for which he received an Academy Award nomination) and A Bug's Life, as the co-story writer and others as story supervisor. His final film was Cars. He also voiced characters in many of the films, including Heimlich the caterpillar in A Bug's Life, Wheezy the penguin in Toy Story 2, and Jacques the shrimp in Finding Nemo.[1]",
12 'Wonderful Tonight "Wonderful Tonight" is a ballad written by Eric Clapton. It was included on Clapton\'s 1977 album Slowhand. Clapton wrote the song about Pattie Boyd.[1] The female vocal harmonies on the song are provided by Marcella Detroit (then Marcy Levy) and Yvonne Elliman.',
13]
14query_embeddings = model.encode_query(queries)
15document_embeddings = model.encode_document(documents)
16print(query_embeddings.shape, document_embeddings.shape)
17# [1, 30522] [3, 30522]
18
19# Get the similarity scores for the embeddings
20similarities = model.similarity(query_embeddings, document_embeddings)
21print(similarities)
22# tensor([[29.2192, 2.4709, 1.7873]])NanoMSMARCO, NanoNFCorpus and NanoNQSparseInformationRetrievalEvaluator| Metric | NanoMSMARCO | NanoNFCorpus | NanoNQ |
|---|---|---|---|
| dot_accuracy@1 | 0.3 | 0.38 | 0.3 |
| dot_accuracy@3 | 0.44 | 0.44 | 0.64 |
| dot_accuracy@5 | 0.6 | 0.54 | 0.66 |
| dot_accuracy@10 | 0.68 | 0.56 | 0.74 |
| dot_precision@1 | 0.3 | 0.38 | 0.3 |
| dot_precision@3 | 0.1467 | 0.32 | 0.2133 |
| dot_precision@5 | 0.12 | 0.3 | 0.132 |
| dot_precision@10 | 0.068 | 0.236 | 0.076 |
| dot_recall@1 | 0.3 | 0.0239 | 0.29 |
| dot_recall@3 | 0.44 | 0.0538 | 0.6 |
| dot_recall@5 | 0.6 | 0.0714 | 0.61 |
| dot_recall@10 | 0.68 | 0.0957 | 0.7 |
| dot_ndcg@10 | 0.4717 | 0.28 | 0.5182 |
| dot_mrr@10 | 0.4068 | 0.4359 | 0.4727 |
| dot_map@100 | 0.4194 | 0.1135 | 0.4609 |
| query_active_dims | 70.78 | 97.02 | 49.68 |
| query_sparsity_ratio | 0.9977 | 0.9968 | 0.9984 |
| corpus_active_dims | 150.2397 | 163.3874 | 141.9744 |
| corpus_sparsity_ratio | 0.9951 | 0.9946 | 0.9953 |
| avg_flops | 6.0766 | 10.3436 | 3.9758 |
NanoBEIR_meanSparseNanoBEIREvaluator with these parameters:
1{
2 "dataset_names": [
3 "msmarco",
4 "nfcorpus",
5 "nq"
6 ],
7 "dataset_id": "sentence-transformers/NanoBEIR-en"
8}| Metric | Value |
|---|---|
| dot_accuracy@1 | 0.3267 |
| dot_accuracy@3 | 0.5067 |
| dot_accuracy@5 | 0.6 |
| dot_accuracy@10 | 0.66 |
| dot_precision@1 | 0.3267 |
| dot_precision@3 | 0.2267 |
| dot_precision@5 | 0.184 |
| dot_precision@10 | 0.1267 |
| dot_recall@1 | 0.2046 |
| dot_recall@3 | 0.3646 |
| dot_recall@5 | 0.4271 |
| dot_recall@10 | 0.4919 |
| dot_ndcg@10 | 0.4233 |
| dot_mrr@10 | 0.4384 |
| dot_map@100 | 0.3312 |
| query_active_dims | 72.4933 |
| query_sparsity_ratio | 0.9976 |
| corpus_active_dims | 150.0256 |
| corpus_sparsity_ratio | 0.9951 |
| avg_flops | 5.651 |
query and answer| query | answer | |
|---|---|---|
| type | string | string |
| details |
|
|
| query | answer |
|---|---|
who played the father in papa don't preach | Alex McArthur Alex McArthur (born March 6, 1957) is an American actor. |
where was the location of the battle of hastings | 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. |
how many puppies can a dog give birth to | 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:
1{
2 "loss": "SparseMultipleNegativesRankingLoss(scale=1.0, similarity_fct='dot_score', gather_across_devices=False, directions=('query_to_doc',), partition_mode='joint')",
3 "document_regularizer_weight": 3e-05,
4 "query_regularizer_weight": 5e-05
5}query and answer| query | answer | |
|---|---|---|
| type | string | string |
| details |
|
|
| query | answer |
|---|---|
where is the tiber river located in italy | 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. |
what kind of car does jay gatsby drive | 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. |
who sings if i can dream about you | 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:
1{
2 "loss": "SparseMultipleNegativesRankingLoss(scale=1.0, similarity_fct='dot_score', gather_across_devices=False, directions=('query_to_doc',), partition_mode='joint')",
3 "document_regularizer_weight": 3e-05,
4 "query_regularizer_weight": 5e-05
5}per_device_train_batch_size: 16num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1bf16: Trueeval_strategy: stepsper_device_eval_batch_size: 16load_best_model_at_end: Truebatch_sampler: no_duplicatesper_device_train_batch_size: 16num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: trackioeval_strategy: stepsper_device_eval_batch_size: 16prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | NanoMSMARCO_dot_ndcg@10 | NanoNFCorpus_dot_ndcg@10 | NanoNQ_dot_ndcg@10 | NanoBEIR_mean_dot_ndcg@10 |
|---|---|---|---|---|---|---|---|
| 0.0501 | 310 | 59.7460 | - | - | - | - | - |
| 0.1002 | 620 | 0.0927 | - | - | - | - | - |
| 0.1503 | 930 | 0.0513 | - | - | - | - | - |
| 0.2001 | 1238 | - | 0.0827 | 0.4945 | 0.2530 | 0.4913 | 0.4129 |
| 0.2004 | 1240 | 0.0474 | - | - | - | - | - |
| 0.2505 | 1550 | 0.0462 | - | - | - | - | - |
| 0.3006 | 1860 | 0.0313 | - | - | - | - | - |
| 0.3507 | 2170 | 0.0258 | - | - | - | - | - |
| 0.4001 | 2476 | - | 0.0427 | 0.4717 | 0.28 | 0.5182 | 0.4233 |
| 0.4008 | 2480 | 0.0414 | - | - | - | - | - |
| 0.4509 | 2790 | 0.0306 | - | - | - | - | - |
| 0.5010 | 3100 | 0.0316 | - | - | - | - | - |
| 0.5511 | 3410 | 0.0300 | - | - | - | - | - |
| 0.6002 | 3714 | - | 0.0652 | 0.4169 | 0.2041 | 0.5020 | 0.3743 |
| 0.6012 | 3720 | 0.0293 | - | - | - | - | - |
| 0.6513 | 4030 | 0.0257 | - | - | - | - | - |
| 0.7014 | 4340 | 0.0219 | - | - | - | - | - |
| 0.7515 | 4650 | 0.0242 | - | - | - | - | - |
| 0.8003 | 4952 | - | 0.0475 | 0.4366 | 0.2656 | 0.4988 | 0.4003 |
| 0.8016 | 4960 | 0.0215 | - | - | - | - | - |
| 0.8516 | 5270 | 0.0248 | - | - | - | - | - |
| 0.9017 | 5580 | 0.0230 | - | - | - | - | - |
| 0.9518 | 5890 | 0.0191 | - | - | - | - | - |
| -1 | -1 | - | - | 0.4717 | 0.2800 | 0.5182 | 0.4233 |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}1@misc{formal2022distillationhardnegativesampling,
2 title={From Distillation to Hard Negative Sampling: Making Sparse Neural IR Models More Effective},
3 author={Thibault Formal and Carlos Lassance and Benjamin Piwowarski and Stéphane Clinchant},
4 year={2022},
5 eprint={2205.04733},
6 archivePrefix={arXiv},
7 primaryClass={cs.IR},
8 url={https://arxiv.org/abs/2205.04733},
9}1@misc{oord2019representationlearningcontrastivepredictive,
2 title={Representation Learning with Contrastive Predictive Coding},
3 author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
4 year={2019},
5 eprint={1807.03748},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/1807.03748},
9}1@article{paria2020minimizing,
2 title={Minimizing flops to learn efficient sparse representations},
3 author={Paria, Biswajit and Yeh, Chih-Kuan and Yen, Ian EH and Xu, Ning and Ravikumar, Pradeep and P{'o}czos, Barnab{'a}s},
4 journal={arXiv preprint arXiv:2004.05665},
5 year={2020}
6}