Edit model card

BERT base trained on Natural Questions pairs

This is a sentence-transformers model finetuned from google-bert/bert-base-uncased on the natural-questions dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

This model was trained using the script from the Training with Prompts Sentence Transformers documentation.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: google-bert/bert-base-uncased
  • Maximum Sequence Length: 512 tokens
  • Output Dimensionality: 768 dimensions
  • Similarity Function: Cosine Similarity
  • Training Dataset:
  • Language: en
  • License: apache-2.0

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel 
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, '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/bert-base-nq-prompts")
# Run inference
sentences = [
    'query: where does the last name francisco come from',
    'document: Francisco Francisco is the Spanish and Portuguese form of the masculine given name Franciscus (corresponding to English Francis).',
    'document: Book of Esther The Book of Esther, also known in Hebrew as "the Scroll" (Megillah), is a book in the third section (Ketuvim, "Writings") of the Jewish Tanakh (the Hebrew Bible) and in the Christian Old Testament. It is one of the five Scrolls (Megillot) in the Hebrew Bible. It relates the story of a Hebrew woman in Persia, born as Hadassah but known as Esther, who becomes queen of Persia and thwarts a genocide of her people. The story forms the core of the Jewish festival of Purim, during which it is read aloud twice: once in the evening and again the following morning. The books of Esther and Song of Songs are the only books in the Hebrew Bible that do not explicitly mention God.[2]',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]

Evaluation

Metrics

Information Retrieval

  • Datasets: NanoClimateFEVER, NanoDBPedia, NanoFEVER, NanoFiQA2018, NanoHotpotQA, NanoMSMARCO, NanoNFCorpus, NanoNQ, NanoQuoraRetrieval, NanoSCIDOCS, NanoArguAna, NanoSciFact and NanoTouche2020
  • Evaluated with InformationRetrievalEvaluator
Metric NanoClimateFEVER NanoDBPedia NanoFEVER NanoFiQA2018 NanoHotpotQA NanoMSMARCO NanoNFCorpus NanoNQ NanoQuoraRetrieval NanoSCIDOCS NanoArguAna NanoSciFact NanoTouche2020
cosine_accuracy@1 0.28 0.62 0.52 0.2 0.54 0.22 0.36 0.44 0.8 0.32 0.18 0.38 0.4694
cosine_accuracy@3 0.42 0.78 0.68 0.32 0.68 0.48 0.44 0.58 0.92 0.48 0.62 0.54 0.7755
cosine_accuracy@5 0.52 0.82 0.68 0.38 0.72 0.54 0.5 0.64 0.96 0.54 0.72 0.56 0.898
cosine_accuracy@10 0.6 0.92 0.78 0.44 0.8 0.72 0.58 0.72 0.98 0.64 0.86 0.6 0.9796
cosine_precision@1 0.28 0.62 0.52 0.2 0.54 0.22 0.36 0.44 0.8 0.32 0.18 0.38 0.4694
cosine_precision@3 0.1733 0.4867 0.2267 0.1267 0.2733 0.16 0.2733 0.1933 0.36 0.2333 0.2067 0.1933 0.4422
cosine_precision@5 0.136 0.436 0.136 0.112 0.192 0.108 0.204 0.128 0.232 0.196 0.144 0.124 0.4408
cosine_precision@10 0.08 0.408 0.082 0.07 0.114 0.072 0.174 0.074 0.132 0.15 0.086 0.068 0.3796
cosine_recall@1 0.1433 0.0654 0.51 0.1031 0.27 0.22 0.0244 0.43 0.704 0.0677 0.18 0.345 0.0364
cosine_recall@3 0.2283 0.1216 0.65 0.1607 0.41 0.48 0.0705 0.56 0.8687 0.1457 0.62 0.51 0.1028
cosine_recall@5 0.2757 0.1586 0.65 0.2197 0.48 0.54 0.0785 0.62 0.906 0.2027 0.72 0.54 0.1638
cosine_recall@10 0.3207 0.2691 0.77 0.2817 0.57 0.72 0.0938 0.7 0.9667 0.3097 0.86 0.585 0.2589
cosine_ndcg@10 0.2878 0.4934 0.633 0.2266 0.5034 0.4571 0.228 0.5664 0.8785 0.2843 0.5152 0.4802 0.42
cosine_mrr@10 0.3809 0.7205 0.5985 0.2786 0.6131 0.3756 0.4164 0.5322 0.862 0.4187 0.405 0.457 0.6389
cosine_map@100 0.2429 0.3576 0.5919 0.1922 0.4306 0.3858 0.0884 0.5288 0.845 0.2157 0.4131 0.4494 0.3258

Nano BEIR

Metric Value
cosine_accuracy@1 0.41
cosine_accuracy@3 0.5935
cosine_accuracy@5 0.6522
cosine_accuracy@10 0.74
cosine_precision@1 0.41
cosine_precision@3 0.2576
cosine_precision@5 0.1991
cosine_precision@10 0.1454
cosine_recall@1 0.2384
cosine_recall@3 0.3791
cosine_recall@5 0.4273
cosine_recall@10 0.5158
cosine_ndcg@10 0.4595
cosine_mrr@10 0.5152
cosine_map@100 0.3898

Training Details

Training Dataset

natural-questions

  • Dataset: natural-questions at f9e894e
  • Size: 100,231 training samples
  • Columns: query and answer
  • Approximate statistics based on the first 1000 samples:
    query answer
    type string string
    details
    • min: 12 tokens
    • mean: 13.74 tokens
    • max: 26 tokens
    • min: 17 tokens
    • mean: 139.2 tokens
    • max: 510 tokens
  • Samples:
    query answer
    query: who is required to report according to the hmda document: Home Mortgage Disclosure Act US financial institutions must report HMDA data to their regulator if they meet certain criteria, such as having assets above a specific threshold. The criteria is different for depository and non-depository institutions and are available on the FFIEC website.[4] In 2012, there were 7,400 institutions that reported a total of 18.7 million HMDA records.[5]
    query: what is the definition of endoplasmic reticulum in biology document: Endoplasmic reticulum The endoplasmic reticulum (ER) is a type of organelle in eukaryotic cells that forms an interconnected network of flattened, membrane-enclosed sacs or tube-like structures known as cisternae. The membranes of the ER are continuous with the outer nuclear membrane. The endoplasmic reticulum occurs in most types of eukaryotic cells, but is absent from red blood cells and spermatozoa. There are two types of endoplasmic reticulum: rough and smooth. The outer (cytosolic) face of the rough endoplasmic reticulum is studded with ribosomes that are the sites of protein synthesis. The rough endoplasmic reticulum is especially prominent in cells such as hepatocytes. The smooth endoplasmic reticulum lacks ribosomes and functions in lipid manufacture and metabolism, the production of steroid hormones, and detoxification.[1] The smooth ER is especially abundant in mammalian liver and gonad cells. The lacy membranes of the endoplasmic reticulum were first seen in 1945 u...
    query: what does the ski mean in polish names document: Polish name Since the High Middle Ages, Polish-sounding surnames ending with the masculine -ski suffix, including -cki and -dzki, and the corresponding feminine suffix -ska/-cka/-dzka were associated with the nobility (Polish szlachta), which alone, in the early years, had such suffix distinctions.[1] They are widely popular today.
  • Loss: CachedMultipleNegativesRankingLoss with these parameters:
    {
        "scale": 20.0,
        "similarity_fct": "cos_sim"
    }
    

Evaluation Dataset

natural-questions

  • Dataset: natural-questions at f9e894e
  • Size: 100,231 evaluation samples
  • Columns: query and answer
  • Approximate statistics based on the first 1000 samples:
    query answer
    type string string
    details
    • min: 12 tokens
    • mean: 13.78 tokens
    • max: 24 tokens
    • min: 13 tokens
    • mean: 137.63 tokens
    • max: 512 tokens
  • Samples:
    query answer
    query: difference between russian blue and british blue cat document: Russian Blue The coat is known as a "double coat", with the undercoat being soft, downy and equal in length to the guard hairs, which are an even blue with silver tips. However, the tail may have a few very dull, almost unnoticeable stripes. The coat is described as thick, plush and soft to the touch. The feeling is softer than the softest silk. The silver tips give the coat a shimmering appearance. Its eyes are almost always a dark and vivid green. Any white patches of fur or yellow eyes in adulthood are seen as flaws in show cats.[3] Russian Blues should not be confused with British Blues (which are not a distinct breed, but rather a British Shorthair with a blue coat as the British Shorthair breed itself comes in a wide variety of colors and patterns), nor the Chartreux or Korat which are two other naturally occurring breeds of blue cats, although they have similar traits.
    query: who played the little girl on mrs doubtfire document: Mara Wilson Mara Elizabeth Wilson[2] (born July 24, 1987) is an American writer and former child actress. She is known for playing Natalie Hillard in Mrs. Doubtfire (1993), Susan Walker in Miracle on 34th Street (1994), Matilda Wormwood in Matilda (1996) and Lily Stone in Thomas and the Magic Railroad (2000). Since retiring from film acting, Wilson has focused on writing.
    query: what year did the movie the sound of music come out document: The Sound of Music (film) The film was released on March 2, 1965 in the United States, initially as a limited roadshow theatrical release. Although critical response to the film was widely mixed, the film was a major commercial success, becoming the number one box office movie after four weeks, and the highest-grossing film of 1965. By November 1966, The Sound of Music had become the highest-grossing film of all-time—surpassing Gone with the Wind—and held that distinction for five years. The film was just as popular throughout the world, breaking previous box-office records in twenty-nine countries. Following an initial theatrical release that lasted four and a half years, and two successful re-releases, the film sold 283 million admissions worldwide and earned a total worldwide gross of $286,000,000.
  • Loss: CachedMultipleNegativesRankingLoss with these parameters:
    {
        "scale": 20.0,
        "similarity_fct": "cos_sim"
    }
    

Training Hyperparameters

Non-Default Hyperparameters

  • eval_strategy: steps
  • per_device_train_batch_size: 256
  • per_device_eval_batch_size: 256
  • learning_rate: 2e-05
  • num_train_epochs: 1
  • warmup_ratio: 0.1
  • seed: 12
  • bf16: True
  • prompts: {'query': 'query: ', 'answer': 'document: '}
  • batch_sampler: no_duplicates

All Hyperparameters

Click to expand
  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: steps
  • prediction_loss_only: True
  • per_device_train_batch_size: 256
  • per_device_eval_batch_size: 256
  • 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: 12
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: True
  • fp16: False
  • 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: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': 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: False
  • 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: {'query': 'query: ', 'answer': 'document: '}
  • batch_sampler: no_duplicates
  • multi_dataset_batch_sampler: proportional

Training Logs

Epoch Step Training Loss Validation Loss NanoClimateFEVER_cosine_ndcg@10 NanoDBPedia_cosine_ndcg@10 NanoFEVER_cosine_ndcg@10 NanoFiQA2018_cosine_ndcg@10 NanoHotpotQA_cosine_ndcg@10 NanoMSMARCO_cosine_ndcg@10 NanoNFCorpus_cosine_ndcg@10 NanoNQ_cosine_ndcg@10 NanoQuoraRetrieval_cosine_ndcg@10 NanoSCIDOCS_cosine_ndcg@10 NanoArguAna_cosine_ndcg@10 NanoSciFact_cosine_ndcg@10 NanoTouche2020_cosine_ndcg@10 NanoBEIR_mean_cosine_ndcg@10
0 0 - - 0.1042 0.1641 0.1239 0.0397 0.2320 0.1682 0.0526 0.0678 0.7440 0.1153 0.2443 0.1516 0.1010 0.1776
0.0026 1 3.2174 - - - - - - - - - - - - - - -
0.0129 5 3.2181 - - - - - - - - - - - - - - -
0.0258 10 2.9101 - - - - - - - - - - - - - - -
0.0387 15 2.2308 - - - - - - - - - - - - - - -
0.0515 20 1.5687 - - - - - - - - - - - - - - -
0.0644 25 1.1955 - - - - - - - - - - - - - - -
0.0773 30 0.9679 - - - - - - - - - - - - - - -
0.0902 35 0.787 - - - - - - - - - - - - - - -
0.1031 40 0.6266 - - - - - - - - - - - - - - -
0.1160 45 0.4877 - - - - - - - - - - - - - - -
0.1289 50 0.344 0.3217 0.2374 0.4663 0.6383 0.2397 0.4848 0.4183 0.2096 0.4839 0.8519 0.2619 0.4823 0.4781 0.4308 0.4372
0.1418 55 0.3294 - - - - - - - - - - - - - - -
0.1546 60 0.2493 - - - - - - - - - - - - - - -
0.1675 65 0.257 - - - - - - - - - - - - - - -
0.1804 70 0.1839 - - - - - - - - - - - - - - -
0.1933 75 0.2339 - - - - - - - - - - - - - - -
0.2062 80 0.2095 - - - - - - - - - - - - - - -
0.2191 85 0.2052 - - - - - - - - - - - - - - -
0.2320 90 0.199 - - - - - - - - - - - - - - -
0.2448 95 0.1867 - - - - - - - - - - - - - - -
0.2577 100 0.1959 0.1771 0.2796 0.4858 0.6150 0.2331 0.4745 0.4345 0.2158 0.5154 0.8756 0.2827 0.5131 0.4839 0.4315 0.4493
0.2706 105 0.1759 - - - - - - - - - - - - - - -
0.2835 110 0.1727 - - - - - - - - - - - - - - -
0.2964 115 0.1773 - - - - - - - - - - - - - - -
0.3093 120 0.1708 - - - - - - - - - - - - - - -
0.3222 125 0.1881 - - - - - - - - - - - - - - -
0.3351 130 0.1465 - - - - - - - - - - - - - - -
0.3479 135 0.1583 - - - - - - - - - - - - - - -
0.3608 140 0.1658 - - - - - - - - - - - - - - -
0.3737 145 0.1547 - - - - - - - - - - - - - - -
0.3866 150 0.1262 0.1482 0.2755 0.4955 0.6403 0.2358 0.4871 0.4548 0.2329 0.5372 0.8873 0.2821 0.5173 0.4658 0.4217 0.4564
0.3995 155 0.1522 - - - - - - - - - - - - - - -
0.4124 160 0.1486 - - - - - - - - - - - - - - -
0.4253 165 0.1277 - - - - - - - - - - - - - - -
0.4381 170 0.1491 - - - - - - - - - - - - - - -
0.4510 175 0.1308 - - - - - - - - - - - - - - -
0.4639 180 0.102 - - - - - - - - - - - - - - -
0.4768 185 0.117 - - - - - - - - - - - - - - -
0.4897 190 0.1748 - - - - - - - - - - - - - - -
0.5026 195 0.1431 - - - - - - - - - - - - - - -
0.5155 200 0.1684 0.1378 0.3042 0.4804 0.6335 0.2329 0.5004 0.4184 0.2284 0.5609 0.8885 0.2742 0.5192 0.4788 0.4193 0.4569
0.5284 205 0.1593 - - - - - - - - - - - - - - -
0.5412 210 0.1331 - - - - - - - - - - - - - - -
0.5541 215 0.1498 - - - - - - - - - - - - - - -
0.5670 220 0.1467 - - - - - - - - - - - - - - -
0.5799 225 0.139 - - - - - - - - - - - - - - -
0.5928 230 0.1346 - - - - - - - - - - - - - - -
0.6057 235 0.1738 - - - - - - - - - - - - - - -
0.6186 240 0.146 - - - - - - - - - - - - - - -
0.6314 245 0.1685 - - - - - - - - - - - - - - -
0.6443 250 0.1327 0.1318 0.2967 0.4921 0.6348 0.2225 0.4917 0.4437 0.2301 0.5628 0.8889 0.2769 0.5166 0.4754 0.4135 0.4573
0.6572 255 0.1517 - - - - - - - - - - - - - - -
0.6701 260 0.1521 - - - - - - - - - - - - - - -
0.6830 265 0.1349 - - - - - - - - - - - - - - -
0.6959 270 0.1127 - - - - - - - - - - - - - - -
0.7088 275 0.1141 - - - - - - - - - - - - - - -
0.7216 280 0.1273 - - - - - - - - - - - - - - -
0.7345 285 0.1168 - - - - - - - - - - - - - - -
0.7474 290 0.1223 - - - - - - - - - - - - - - -
0.7603 295 0.1444 - - - - - - - - - - - - - - -
0.7732 300 0.1153 0.1242 0.2892 0.4960 0.6431 0.2189 0.5059 0.4589 0.2280 0.5635 0.8784 0.2847 0.5048 0.4788 0.4157 0.4589
0.7861 305 0.1337 - - - - - - - - - - - - - - -
0.7990 310 0.0992 - - - - - - - - - - - - - - -
0.8119 315 0.1206 - - - - - - - - - - - - - - -
0.8247 320 0.1272 - - - - - - - - - - - - - - -
0.8376 325 0.1354 - - - - - - - - - - - - - - -
0.8505 330 0.1298 - - - - - - - - - - - - - - -
0.8634 335 0.1289 - - - - - - - - - - - - - - -
0.8763 340 0.1291 - - - - - - - - - - - - - - -
0.8892 345 0.1187 - - - - - - - - - - - - - - -
0.9021 350 0.1173 0.1196 0.2891 0.4945 0.6421 0.2191 0.5113 0.4600 0.2289 0.5667 0.8785 0.2835 0.5134 0.4804 0.4201 0.4606
0.9149 355 0.1197 - - - - - - - - - - - - - - -
0.9278 360 0.1257 - - - - - - - - - - - - - - -
0.9407 365 0.1242 - - - - - - - - - - - - - - -
0.9536 370 0.1479 - - - - - - - - - - - - - - -
0.9665 375 0.1298 - - - - - - - - - - - - - - -
0.9794 380 0.143 - - - - - - - - - - - - - - -
0.9923 385 0.1026 - - - - - - - - - - - - - - -
1.0 388 - - 0.2878 0.4934 0.6330 0.2266 0.5034 0.4571 0.2280 0.5664 0.8785 0.2843 0.5152 0.4802 0.4200 0.4595

Environmental Impact

Carbon emissions were measured using CodeCarbon.

  • Energy Consumed: 0.269 kWh
  • Carbon Emitted: 0.104 kg of CO2
  • Hours Used: 0.777 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: 3.3.0.dev0
  • Transformers: 4.46.2
  • PyTorch: 2.5.0+cu121
  • Accelerate: 1.0.0
  • Datasets: 2.20.0
  • Tokenizers: 0.20.3

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}
}
Downloads last month
12
Safetensors
Model size
109M params
Tensor type
F32
·
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.

Model tree for tomaarsen/bert-base-nq-prompts

Finetuned
(2058)
this model

Dataset used to train tomaarsen/bert-base-nq-prompts

Collection including tomaarsen/bert-base-nq-prompts

Evaluation results