Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 20
How to use PerRing/e5_ko with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("PerRing/e5_ko")
sentences = [
"query: 잡지는 인종차별적이고 성차별적인 유머를 제공했다.",
"passage: 잡지는 인종과 성별에 대해 편견적인 농담을 실었다.",
"passage: 잡지는 모든 사람을 존중하는 유머를 제공했다.",
"passage: 그들은 중요하지만 활용도가 낮은 데이터를 보유하고 있었다."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from intfloat/multilingual-e5-large. 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.
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 1024, '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})
(2): Normalize()
)
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("PerRing/e5_ko")
# Run inference
sentences = [
'query: 그의 사망 약 30년 후에 극장들은 파괴되었다.',
'passage: 그가 사망한 지 약 30년 후에 극장들이 무너졌다.',
'passage: 그의 사망 약 30년 후에 극장들은 번창했다.',
]
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]
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
query: 사람들이 기억하면 당신은 다음 수준으로 물건을 잃게 됩니다. |
passage: 사람들이 상기하면 당신은 다음 단계로 물건을 잃습니다. |
passage: 사람들이 기억하지 않으면 당신은 물건을 잃지 않고 유지합니다. |
query: 제 팀의 한 멤버가 당신의 명령을 매우 정확하게 수행할 것입니다. |
passage: 제 팀원 중 한 명이 당신의 지시를 철저히 이행할 것입니다. |
passage: 제 팀의 누구도 당신의 명령을 정확히 수행하지 않을 것입니다. |
query: 이 정보는 그들의 것입니다. |
passage: 이 정보는 그들 소유입니다. |
passage: 이 정보는 우리 것입니다. |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 2048per_device_eval_batch_size: 2048num_train_epochs: 2warmup_ratio: 0.1gradient_checkpointing: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 2048per_device_eval_batch_size: 2048per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_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: 2max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Falsehub_always_push: Falsegradient_checkpointing: Truegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falsebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss |
|---|---|---|
| 0.04 | 1 | 5.7804 |
| 0.08 | 2 | 5.7809 |
| 0.12 | 3 | 4.8376 |
| 0.16 | 4 | 3.6166 |
| 0.2 | 5 | 2.4258 |
| 0.24 | 6 | 1.2571 |
| 0.28 | 7 | 0.7152 |
| 0.32 | 8 | 0.5181 |
| 0.36 | 9 | 0.359 |
| 0.4 | 10 | 0.3295 |
| 0.44 | 11 | 0.2502 |
| 0.48 | 12 | 0.2256 |
| 0.52 | 13 | 0.1842 |
| 0.56 | 14 | 0.1588 |
| 0.6 | 15 | 0.1614 |
| 0.64 | 16 | 0.1535 |
| 0.68 | 17 | 0.14 |
| 0.72 | 18 | 0.152 |
| 0.76 | 19 | 0.1221 |
| 0.8 | 20 | 0.1179 |
| 0.84 | 21 | 0.1354 |
| 0.88 | 22 | 0.1349 |
| 0.92 | 23 | 0.1364 |
| 0.96 | 24 | 0.1169 |
| 1.0 | 25 | 0.0863 |
| 1.04 | 26 | 0.1161 |
| 1.08 | 27 | 0.1105 |
| 1.12 | 28 | 0.1067 |
| 1.16 | 29 | 0.1087 |
| 1.2 | 30 | 0.1165 |
| 1.24 | 31 | 0.1082 |
| 1.28 | 32 | 0.0866 |
| 1.32 | 33 | 0.0854 |
| 1.3600 | 34 | 0.0905 |
| 1.4 | 35 | 0.0809 |
| 1.44 | 36 | 0.079 |
| 1.48 | 37 | 0.0665 |
| 1.52 | 38 | 0.0542 |
| 1.56 | 39 | 0.06 |
| 1.6 | 40 | 0.0624 |
| 1.6400 | 41 | 0.0671 |
| 1.6800 | 42 | 0.0721 |
| 1.72 | 43 | 0.0781 |
| 1.76 | 44 | 0.0531 |
| 1.8 | 45 | 0.0556 |
| 1.8400 | 46 | 0.0732 |
| 1.88 | 47 | 0.0748 |
| 1.92 | 48 | 0.0773 |
| 1.96 | 49 | 0.068 |
| 2.0 | 50 | 0.0347 |
@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{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}
}
Base model
intfloat/multilingual-e5-large
from sentence_transformers import SentenceTransformer model = SentenceTransformer("PerRing/e5_ko") sentences = [ "query: 잡지는 인종차별적이고 성차별적인 유머를 제공했다.", "passage: 잡지는 인종과 성별에 대해 편견적인 농담을 실었다.", "passage: 잡지는 모든 사람을 존중하는 유머를 제공했다.", "passage: 그들은 중요하지만 활용도가 낮은 데이터를 보유하고 있었다." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4]