CoolFace
Modelpublic

iammayur/bge-base-financial-matryoshka

sourceHugging Faceapache-2.0updated 15d agoView on Hugging Face
0likes35downloads
Model Card

BGE base Financial Matryoshka

This is a sentence-transformers model finetuned from BAAI/bge-base-en-v1.5 on the json dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.

Model Details

Model Description

  • —Model Type: Sentence Transformer
  • —Base model: BAAI/bge-base-en-v1.5 <!-- at revision a5beb1e3e68b9ab74eb54cfd186867f64f240e1a -->
  • —Maximum Sequence Length: 512 tokens
  • —Output Dimensionality: 768 dimensions
  • —Similarity Function: Cosine Similarity
  • —Supported Modality: Text
  • —Training Dataset:
  • —json
  • —Language: en
  • —License: apache-2.0

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': 768, 'pooling_mode': 'cls', 'include_prompt': True})
  (2): Normalize({})
)

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 SentenceTransformer

# Download from the 🤗 Hub
model = SentenceTransformer("iammayur/bge-base-financial-matryoshka")
# Run inference
queries = [
    'Cost of sales for the company was $5,920.5 million in 2022, up from $4,922.7 million in 2021, which represents a 20.3% increase. This included $767.7 million of unfavorable costs driven by higher sales volume and increased supply chain inflation costs, including logistics and labor.',
]
documents = [
    'What were the main components of the increased cost of sales in 2022 compared to 2021?',
    'How much is the service fee on client cash deposits held at the TD Depository Institutions under the 2023 IDA agreement?',
    'What is the primary method by which the company manages its cash, cash equivalents, and marketable securities?',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]

# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.8170, 0.1130, 0.1414]])

<!--

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

Information Retrieval
json
  {
      "truncate_dim": 768
  }
MetricValue
cosine_accuracy@10.7257
cosine_accuracy@30.8357
cosine_accuracy@50.8771
cosine_accuracy@100.9014
cosine_precision@10.7257
cosine_precision@30.2786
cosine_precision@50.1754
cosine_precision@100.0901
cosine_recall@10.7257
cosine_recall@30.8357
cosine_recall@50.8771
cosine_recall@100.9014
cosine_ndcg@100.8168
cosine_mrr@100.7892
cosine_map@1000.7928
Information Retrieval
json
  {
      "truncate_dim": 512
  }
MetricValue
cosine_accuracy@10.7229
cosine_accuracy@30.8357
cosine_accuracy@50.8729
cosine_accuracy@100.9029
cosine_precision@10.7229
cosine_precision@30.2786
cosine_precision@50.1746
cosine_precision@100.0903
cosine_recall@10.7229
cosine_recall@30.8357
cosine_recall@50.8729
cosine_recall@100.9029
cosine_ndcg@100.8158
cosine_mrr@100.7876
cosine_map@1000.7912
Information Retrieval
json
  {
      "truncate_dim": 256
  }
MetricValue
cosine_accuracy@10.7186
cosine_accuracy@30.8329
cosine_accuracy@50.8743
cosine_accuracy@100.9057
cosine_precision@10.7186
cosine_precision@30.2776
cosine_precision@50.1749
cosine_precision@100.0906
cosine_recall@10.7186
cosine_recall@30.8329
cosine_recall@50.8743
cosine_recall@100.9057
cosine_ndcg@100.8137
cosine_mrr@100.7839
cosine_map@1000.7872
Information Retrieval
json
  {
      "truncate_dim": 128
  }
MetricValue
cosine_accuracy@10.7043
cosine_accuracy@30.8257
cosine_accuracy@50.8586
cosine_accuracy@100.8986
cosine_precision@10.7043
cosine_precision@30.2752
cosine_precision@50.1717
cosine_precision@100.0899
cosine_recall@10.7043
cosine_recall@30.8257
cosine_recall@50.8586
cosine_recall@100.8986
cosine_ndcg@100.8034
cosine_mrr@100.7726
cosine_map@1000.7761
Information Retrieval
json
  {
      "truncate_dim": 64
  }
MetricValue
cosine_accuracy@10.6643
cosine_accuracy@30.7829
cosine_accuracy@50.8271
cosine_accuracy@100.8743
cosine_precision@10.6643
cosine_precision@30.261
cosine_precision@50.1654
cosine_precision@100.0874
cosine_recall@10.6643
cosine_recall@30.7829
cosine_recall@50.8271
cosine_recall@100.8743
cosine_ndcg@100.7682
cosine_mrr@100.7343
cosine_map@1000.7385

<!--

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

json
  • —Dataset: json
  • —Size: 6,300 training samples
  • —Columns: <code>positive</code> and <code>anchor</code>
  • —Approximate statistics based on the first 100 samples: | | positive | anchor | |:---------|:------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------| | type | string | string | | modality | text | text | | details | <ul><li>min: 14 tokens</li><li>mean: 42.72 tokens</li><li>max: 122 tokens</li></ul> | <ul><li>min: 10 tokens</li><li>mean: 20.15 tokens</li><li>max: 40 tokens</li></ul> |
  • —Samples: | positive | anchor | |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------| | <code>Alphabet is a collection of businesses, the largest of which is Google. Alphabet reports Google in two segments, Google Services and Google Cloud; all non-Google businesses are collectively reported as Other Bets.</code> | <code>What are Alphabet's primary business segments and how are they reported?</code> | | <code>The company has the option to redeem the Notes for cash between specific dates if the sale price of their common stock exceeds a set threshold relative to the conversion price over a specified number of trading days, including on the day immediately before the notice of redemption is sent.</code> | <code>What are the conditions under which the company may redeem the Notes for cash?</code> | | <code>Net earnings attributable to Hasbro, Inc. declined in 2022 to $203.5 million, compared to $428.7 million in 2021.</code> | <code>How much did Hasbro's net earnings attributable to Hasbro, Inc. decline in 2022 compared to 2021?</code> |
  • —Loss: <code>MatryoshkaLoss</code> with these parameters:
json
  {
      "loss": "MultipleNegativesRankingLoss",
      "matryoshka_dims": [
          768,
          512,
          256,
          128,
          64
      ],
      "matryoshka_weights": [
          1,
          1,
          1,
          1,
          1
      ],
      "n_dims_per_step": -1
  }

Training Hyperparameters

Non-Default Hyperparameters
  • —per_device_train_batch_size: 16
  • —num_train_epochs: 4
  • —learning_rate: 2e-05
  • —lr_scheduler_type: cosine
  • —warmup_steps: 0.1
  • —gradient_accumulation_steps: 16
  • —bf16: True
  • —per_device_eval_batch_size: 16
  • —load_best_model_at_end: True
  • —batch_sampler: no_duplicates
All Hyperparameters

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

  • —per_device_train_batch_size: 16
  • —num_train_epochs: 4
  • —max_steps: -1
  • —learning_rate: 2e-05
  • —lr_scheduler_type: cosine
  • —lr_scheduler_kwargs: None
  • —warmup_steps: 0.1
  • —optim: adamwtorchfused
  • —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: 16
  • —average_tokens_across_devices: True
  • —max_grad_norm: 1.0
  • —label_smoothing_factor: 0.0
  • —bf16: True
  • —fp16: False
  • —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: 16
  • —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: {'splitbatches': False, 'dispatchbatches': None, 'evenbatches': True, 'useseedablesampler': True, 'nonblocking': False, 'gradientaccumulationkwargs': None}
  • —parallelism_config: None
  • —dataloader_drop_last: False
  • —dataloader_num_workers: 0
  • —dataloader_pin_memory: True
  • —dataloader_persistent_workers: False
  • —dataloader_prefetch_factor: None
  • —dataloader_multiprocessing_context: None
  • —dataloader_in_order: True
  • —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: None
  • —fsdp_config: None
  • —deepspeed: None
  • —debug: []
  • —skip_memory_metrics: True
  • —do_predict: False
  • —resume_from_checkpoint: None
  • —local_rank: -1
  • —prompts: None
  • —batch_sampler: no_duplicates
  • —multi_dataset_batch_sampler: proportional
  • —router_mapping: {}
  • —learning_rate_mapping: {}
  • —warmup_ratio: None

</details>

Training Logs

EpochStepTraining Lossdim_768_cosine_ndcg@10dim_512_cosine_ndcg@10dim_256_cosine_ndcg@10dim_128_cosine_ndcg@10dim_64_cosine_ndcg@10
0.4061101.0226-----
0.8122200.4788-----
1.025-0.80820.80710.80530.78500.7460
1.2030300.3296-----
1.6091400.2549-----
2.0500.25310.81400.81470.81250.80130.7630
2.4061600.2018-----
2.8122700.2165-----
3.075-0.81720.81650.81260.80190.7680
3.2030800.1983-----
3.6091900.1817-----
4.01000.18990.81680.81580.81370.80340.7682
  • —The bold row denotes the saved checkpoint.

Training Time

  • —Training: 30.3 minutes

Framework Versions

  • —Python: 3.13.15
  • —Sentence Transformers: 5.7.0
  • —Transformers: 5.16.1
  • —PyTorch: 2.11.0+cu128
  • —Accelerate: 1.14.0
  • —Datasets: 4.8.5
  • —Tokenizers: 0.23.1

Additional Resources

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",
}
MatryoshkaLoss
bibtex
@misc{kusupati2024matryoshka,
    title={Matryoshka Representation Learning},
    author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
    year={2024},
    eprint={2205.13147},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}
MultipleNegativesRankingLoss
bibtex
@misc{oord2019representationlearningcontrastivepredictive,
      title={Representation Learning with Contrastive Predictive Coding},
      author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
      year={2019},
      eprint={1807.03748},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/1807.03748},
}

<!--

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