Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper • 2101.06983 • Published • 3
How to use Dathq12/bge-m3-tool-retrieval-vi with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Dathq12/bge-m3-tool-retrieval-vi")
sentences = [
"I'm feeling a bit down, can you tell me a joke to cheer me up?",
"generate_random_joke. Generate a random joke",
"get_joke. Get a random joke",
"get_random_joke. Get a random joke",
"get_joke. Get a random joke",
"generate_random_joke. Generate a random joke"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [6, 6]This is a sentence-transformers model finetuned from BAAI/bge-m3. It maps inputs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 1024, 'pooling_mode': 'cls', 'include_prompt': True})
(2): Normalize({'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)
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("sentence_transformers_model_id")
# Run inference
queries = [
"Hi, I'm feeling a bit bored. Can you tell me something interesting?",
]
documents = [
'get_random_fact. Get a random fact',
'get_random_trivia. Get a random piece of trivia',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [2, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.3718, 0.4430]])
custom_valInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.4588 |
| cosine_accuracy@3 | 0.662 |
| cosine_accuracy@5 | 0.7302 |
| cosine_accuracy@10 | 0.7961 |
| cosine_precision@1 | 0.4588 |
| cosine_precision@3 | 0.2207 |
| cosine_precision@5 | 0.146 |
| cosine_precision@10 | 0.0796 |
| cosine_recall@1 | 0.4588 |
| cosine_recall@3 | 0.662 |
| cosine_recall@5 | 0.7302 |
| cosine_recall@10 | 0.7961 |
| cosine_ndcg@10 | 0.6287 |
| cosine_mrr@10 | 0.575 |
| cosine_map@100 | 0.581 |
anchor, positive, negative_1, negative_2, negative_3, and negative_4| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 | |
|---|---|---|---|---|---|---|
| type | string | string | string | string | string | string |
| modality | text | text | text | text | text | text |
| details |
|
|
|
|
|
|
| anchor | positive | negative_1 | negative_2 | negative_3 | negative_4 |
|---|---|---|---|---|---|
Is the email 'john.doe@example.com' part of any known data breaches? |
data_breach_checker_endpoint. Checks if the given email has been compromised in any known data breaches using the Data Breach Checker API.. Tham số: email |
emailvalidation. Validates if an email address exists using the RapidAPI Whois Lookup service.. Tham số: email |
mailcheck. Validates the given email address against specified domain(s) using an external API.. Tham số: email, domain |
emailvalidation. Validates an email address using an API service.. Tham số: email |
bouncer_email_checker. Validates an email address using the Bouncer Email Checker API.. Tham số: email |
Search for movies and TV shows with the title 'The Dark Knight' without any limit on the number of results. |
search_by_title. Search for Movies or TV Shows by title, with optional filters for year, media type, and limit on the number of results.. Tham số: s, l, y, m |
search_movies. Search for movies based on a query. Tham số: query, limit |
search. Searches for a movie or TV show based on the given title.. Tham số: title, page |
search_movie. Search for a movie by title or genre. Tham số: query, max_results |
search_movies. Search for movies based on title. Tham số: title |
Hi, I need to calculate the volume of a rectangular prism. The length is 5, width is 3 and height is 2. |
calculate_volume. Calculate the volume of a rectangular prism. Tham số: length, width, height |
calculate_cylinder_volume. Calculate the volume of a cylinder. Tham số: radius, height |
calculate_cylinder_volume. Calculate the volume of a cylinder. Tham số: radius, height |
calculate_area_volume. Calculate the area and volume of a three-dimensional object. Tham số: object_type, dimensions |
calculate_area_volume. Calculate the area and volume of a 3D shape. Tham số: shape, dimensions |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 32,
"mini_batch_num_tokens": null,
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 256learning_rate: 2e-05lr_scheduler_type: cosinewarmup_steps: 0.1fp16: Trueper_device_train_batch_size: 256num_train_epochs: 3max_steps: -1learning_rate: 2e-05lr_scheduler_type: cosinelr_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: Falsefp16: Truebf16_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 8prediction_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: Falseignore_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: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss | custom_val_cosine_ndcg@10 |
|---|---|---|---|
| 0.1799 | 50 | 3.7251 | - |
| 0.3597 | 100 | 2.7619 | - |
| 0.5396 | 150 | 2.1278 | - |
| 0.7194 | 200 | 1.9997 | - |
| 0.8993 | 250 | 1.8913 | - |
| 1.0791 | 300 | 1.8380 | 0.5842 |
| 1.2590 | 350 | 1.7996 | - |
| 1.4388 | 400 | 1.7590 | - |
| 1.6187 | 450 | 1.7098 | - |
| 1.7986 | 500 | 1.6860 | - |
| 1.9784 | 550 | 1.6494 | - |
| 2.1583 | 600 | 1.6049 | 0.6243 |
| 2.3381 | 650 | 1.6211 | - |
| 2.5180 | 700 | 1.6014 | - |
| 2.6978 | 750 | 1.5894 | - |
| 2.8777 | 800 | 1.6079 | - |
| 3.0 | 834 | - | 0.6287 |
@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{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}
}
@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},
}
Base model
BAAI/bge-m3