GISTEmbed: Guided In-sample Selection of Training Negatives for Text Embedding Fine-tuning
Paper • 2402.16829 • Published • 1
How to use kwondw/distilroberta-base-nli-v3 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("kwondw/distilroberta-base-nli-v3")
sentences = [
"A man is jumping unto his filthy bed.",
"A young male is looking at a newspaper while 2 females walks past him.",
"The bed is dirty.",
"The man is on the moon."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from distilbert/distilroberta-base on the all-nli dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for retrieval.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'RobertaModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
)
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("kwondw/distilroberta-base-nli-v3")
# Run inference
sentences = [
'A construction worker peeking out of a manhole while his coworker sits on the sidewalk smiling.',
'A worker is looking out of a manhole.',
'The workers are both inside the manhole.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.8880, 0.8289],
# [0.8880, 1.0000, 0.8330],
# [0.8289, 0.8330, 1.0000]])
sts-dev and sts-testEmbeddingSimilarityEvaluator| Metric | sts-dev | sts-test |
|---|---|---|
| pearson_cosine | 0.8534 | 0.8196 |
| spearman_cosine | 0.865 | 0.8417 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
A person on a horse jumps over a broken down airplane. |
A person is outdoors, on a horse. |
A person is at a diner, ordering an omelette. |
Children smiling and waving at camera |
There are children present |
The kids are frowning |
A boy is jumping on skateboard in the middle of a red bridge. |
The boy does a skateboarding trick. |
The boy skates down the sidewalk. |
GISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')",
"temperature": 0.01,
"margin_strategy": "absolute",
"margin": 0.0,
"contrast_anchors": true,
"contrast_positives": true,
"gather_across_devices": false
}
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Two women are embracing while holding to go packages. |
Two woman are holding packages. |
The men are fighting outside a deli. |
Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink. |
Two kids in numbered jerseys wash their hands. |
Two kids in jackets walk to school. |
A man selling donuts to a customer during a world exhibition event held in the city of Angeles |
A man selling donuts to a customer. |
A woman drinks her coffee in a small cafe. |
GISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')",
"temperature": 0.01,
"margin_strategy": "absolute",
"margin": 0.0,
"contrast_anchors": true,
"contrast_positives": true,
"gather_across_devices": false
}
per_device_train_batch_size: 128per_device_eval_batch_size: 128num_train_epochs: 1warmup_steps: 0.1fp16: Truebatch_sampler: no_duplicatesdo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 128per_device_eval_batch_size: 128gradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: Nonewarmup_steps: 0.1log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 42data_seed: Nonebf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Truedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Nonegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Truepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueuse_cache: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | sts-dev_spearman_cosine | sts-test_spearman_cosine |
|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.6375 | - |
| 0.0459 | 100 | 2.6151 | - | - | - |
| 0.0918 | 200 | 0.9547 | - | - | - |
| 0.1000 | 218 | - | 0.4238 | 0.8506 | - |
| 0.1377 | 300 | 0.7757 | - | - | - |
| 0.1836 | 400 | 0.6931 | - | - | - |
| 0.2001 | 436 | - | 0.3255 | 0.8574 | - |
| 0.2295 | 500 | 0.6120 | - | - | - |
| 0.2754 | 600 | 0.5767 | - | - | - |
| 0.3001 | 654 | - | 0.2981 | 0.8574 | - |
| 0.3212 | 700 | 0.5447 | - | - | - |
| 0.3671 | 800 | 0.5181 | - | - | - |
| 0.4002 | 872 | - | 0.2737 | 0.8615 | - |
| 0.4130 | 900 | 0.4807 | - | - | - |
| 0.4589 | 1000 | 0.4621 | - | - | - |
| 0.5002 | 1090 | - | 0.2580 | 0.8658 | - |
| 0.5048 | 1100 | 0.4520 | - | - | - |
| 0.5507 | 1200 | 0.4306 | - | - | - |
| 0.5966 | 1300 | 0.4080 | - | - | - |
| 0.6003 | 1308 | - | 0.2488 | 0.8638 | - |
| 0.6425 | 1400 | 0.3964 | - | - | - |
| 0.6884 | 1500 | 0.3792 | - | - | - |
| 0.7003 | 1526 | - | 0.2322 | 0.8657 | - |
| 0.7343 | 1600 | 0.3849 | - | - | - |
| 0.7802 | 1700 | 0.3791 | - | - | - |
| 0.8004 | 1744 | - | 0.2213 | 0.8668 | - |
| 0.8261 | 1800 | 0.3551 | - | - | - |
| 0.8720 | 1900 | 0.3617 | - | - | - |
| 0.9004 | 1962 | - | 0.2186 | 0.8650 | - |
| 0.9179 | 2000 | 0.3492 | - | - | - |
| 0.9637 | 2100 | 0.3473 | - | - | - |
| -1 | -1 | - | - | - | 0.8417 |
@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{solatorio2024gistembed,
title={GISTEmbed: Guided In-sample Selection of Training Negatives for Text Embedding Fine-tuning},
author={Aivin V. Solatorio},
year={2024},
eprint={2402.16829},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
Base model
distilbert/distilroberta-base