CoolFace
Modelpublic

dariolopez/bge-m3-es-legal-tmp-2

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes72downloads
Model Card

BGE large Legal Spanish

This is a sentence-transformers model finetuned from BAAI/bge-m3. It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

Model Details

Model Description

  • —Model Type: Sentence Transformer
  • —Base model: BAAI/bge-m3 <!-- at revision 5617a9f61b028005a4858fdac845db406aefb181 -->
  • —Maximum Sequence Length: 8192 tokens
  • —Output Dimensionality: 1024 tokens
  • —Similarity Function: Cosine Similarity <!-- - Training Dataset: Unknown -->
  • —Language: es
  • —License: apache-2.0

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 8192, 'do_lower_case': False}) with Transformer model: XLMRobertaModel 
  (1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, '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("dariolopez/bge-m3-es-legal-tmp-2")
# Run inference
sentences = [
    'Artículo 6. Definiciones. 1. Discriminación directa e indirecta. b) La discriminación indirecta se produce cuando una disposición, criterio o práctica aparentemente neutros ocasiona o puede ocasionar a una o varias personas una desventaja particular con respecto a otras por razón de las causas previstas en el apartado 1 del artículo 2.',
    '¿Qué se considera discriminación indirecta?',
    '¿Qué tipo de información se considera veraz?',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]

# 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

Information Retrieval
MetricValue
cosine_accuracy@10.5427
cosine_accuracy@30.7988
cosine_accuracy@50.8384
cosine_accuracy@100.8872
cosine_precision@10.5427
cosine_precision@30.2663
cosine_precision@50.1677
cosine_precision@100.0887
cosine_recall@10.5427
cosine_recall@30.7988
cosine_recall@50.8384
cosine_recall@100.8872
cosine_ndcg@100.7233
cosine_mrr@100.6696
cosine_map@1000.6746
Information Retrieval
MetricValue
cosine_accuracy@10.5396
cosine_accuracy@30.8049
cosine_accuracy@50.8445
cosine_accuracy@100.8902
cosine_precision@10.5396
cosine_precision@30.2683
cosine_precision@50.1689
cosine_precision@100.089
cosine_recall@10.5396
cosine_recall@30.8049
cosine_recall@50.8445
cosine_recall@100.8902
cosine_ndcg@100.7246
cosine_mrr@100.6702
cosine_map@1000.6749
Information Retrieval
MetricValue
cosine_accuracy@10.5488
cosine_accuracy@30.8018
cosine_accuracy@50.8354
cosine_accuracy@100.8933
cosine_precision@10.5488
cosine_precision@30.2673
cosine_precision@50.1671
cosine_precision@100.0893
cosine_recall@10.5488
cosine_recall@30.8018
cosine_recall@50.8354
cosine_recall@100.8933
cosine_ndcg@100.7304
cosine_mrr@100.6771
cosine_map@1000.6811
Information Retrieval
MetricValue
cosine_accuracy@10.5457
cosine_accuracy@30.7774
cosine_accuracy@50.8293
cosine_accuracy@100.872
cosine_precision@10.5457
cosine_precision@30.2591
cosine_precision@50.1659
cosine_precision@100.0872
cosine_recall@10.5457
cosine_recall@30.7774
cosine_recall@50.8293
cosine_recall@100.872
cosine_ndcg@100.7183
cosine_mrr@100.6678
cosine_map@1000.6733
Information Retrieval
MetricValue
cosine_accuracy@10.5335
cosine_accuracy@30.7622
cosine_accuracy@50.814
cosine_accuracy@100.8659
cosine_precision@10.5335
cosine_precision@30.2541
cosine_precision@50.1628
cosine_precision@100.0866
cosine_recall@10.5335
cosine_recall@30.7622
cosine_recall@50.814
cosine_recall@100.8659
cosine_ndcg@100.708
cosine_mrr@100.6563
cosine_map@1000.6617
Information Retrieval
MetricValue
cosine_accuracy@10.5122
cosine_accuracy@30.7317
cosine_accuracy@50.7896
cosine_accuracy@100.8659
cosine_precision@10.5122
cosine_precision@30.2439
cosine_precision@50.1579
cosine_precision@100.0866
cosine_recall@10.5122
cosine_recall@30.7317
cosine_recall@50.7896
cosine_recall@100.8659
cosine_ndcg@100.6908
cosine_mrr@100.6347
cosine_map@1000.6394

<!--

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 Hyperparameters

Non-Default Hyperparameters
  • —eval_strategy: epoch
  • —per_device_train_batch_size: 16
  • —per_device_eval_batch_size: 16
  • —gradient_accumulation_steps: 16
  • —learning_rate: 2e-05
  • —num_train_epochs: 16
  • —lr_scheduler_type: cosine
  • —warmup_ratio: 0.1
  • —bf16: True
  • —tf32: True
  • —load_best_model_at_end: True
  • —optim: adamwtorchfused
  • —batch_sampler: no_duplicates
All Hyperparameters

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

  • —overwrite_output_dir: False
  • —do_predict: False
  • —eval_strategy: epoch
  • —prediction_loss_only: True
  • —per_device_train_batch_size: 16
  • —per_device_eval_batch_size: 16
  • —per_gpu_train_batch_size: None
  • —per_gpu_eval_batch_size: None
  • —gradient_accumulation_steps: 16
  • —eval_accumulation_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: 16
  • —max_steps: -1
  • —lr_scheduler_type: cosine
  • —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: True
  • —fp16: False
  • —fp16_opt_level: O1
  • —half_precision_backend: auto
  • —bf16_full_eval: False
  • —fp16_full_eval: False
  • —tf32: True
  • —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: True
  • —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: adamwtorchfused
  • —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
  • —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
  • —batch_sampler: no_duplicates
  • —multi_dataset_batch_sampler: proportional

</details>

Training Logs

EpochStepTraining Losslossdim_1024_cosine_map@100dim_128_cosine_map@100dim_256_cosine_map@100dim_512_cosine_map@100dim_64_cosine_map@100dim_768_cosine_map@100
0.8649101.4359-------
0.951411-0.66850.67080.63000.66760.67160.55600.6781
1.7297200.7913-------
1.989223-0.44580.67340.65330.67730.67700.61740.6657
2.5946300.3416-------
2.940534-0.42390.67490.65910.67250.67520.61880.6784
3.4595400.1327-------
3.978446-0.39340.68200.65940.68620.68560.62930.6777
4.3243500.0563-------
4.929757-0.36900.67470.65820.67600.68520.63750.6774
5.1892600.0324-------
5.967669-0.3620.67520.66430.67840.68090.63120.6799
6.0541700.0205-------
6.9189800.01360.36080.67800.65820.67690.67850.63660.6769
7.7838900.0102-------
7.956892-0.33070.68040.65110.67740.68230.63550.6747
8.64861000.0076-------
8.9946104-0.33870.67780.65180.67510.67870.63130.6693
9.51351100.0069-------
9.9459115-0.32220.67760.65710.67450.68100.63970.6722
10.37841200.0055-------
10.9838127-0.33250.67600.65950.67140.68070.63990.6729
11.24321300.0055-------
11.9351138-0.33660.67700.65980.67300.68130.63600.6733
12.10811400.0049-------
12.97301500.00450.32630.67590.65990.67430.68160.63940.6759
13.83781600.0044-------
13.9243161-0.32310.67470.65930.67290.68040.64070.6746
14.70271700.0045-------
14.9622173-0.32380.67430.65970.67200.68280.63950.6759
15.2216176-0.32440.67460.66170.67330.68110.63940.6749
  • —The bold row denotes the saved checkpoint.

Framework Versions

  • —Python: 3.10.12
  • —Sentence Transformers: 3.0.1
  • —Transformers: 4.42.3
  • —PyTorch: 2.2.0+cu121
  • —Accelerate: 0.32.1
  • —Datasets: 2.20.0
  • —Tokenizers: 0.19.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",
}
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{henderson2017efficient,
    title={Efficient Natural Language Response Suggestion for Smart Reply}, 
    author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
    year={2017},
    eprint={1705.00652},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

<!--

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