Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 17
How to use Mosofriends/paraphrase-multilingual-korean-finetuned with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Mosofriends/paraphrase-multilingual-korean-finetuned")
sentences = [
"& aque.\n\n \n\n4 spazHe oO] Wao. Ad Aa AS Bary at Ado &\nazjar AZo] ALS Ao] Sepepy) AA) Azhe ASEAIAWE...”\nFa ASAD VSURBWAAVEAA AOS AA). F215 0] 9} 20] DW\n\nalelo) AAS weedy seyre Agee -Ay lao Ae aad\n\n \n\n \n\nAMAT. o]e4YSt ulSS Wyo} lop Balzyel Apeeley o}o gayAay 7\n\ny &\nA7\\zHel OPA Aso) Sept ol WBA Ay] lS MoS ae\n\nAe MAES ol WAAA MBS AABS spas cleo] Ba\n3} BAIAS SABA] ASs} GS ASe aa dey. aA\nsayz AAAS Ia AS gow adi\n\n=\nAoyypsD.. FIA WuIs Feor GAA dojus Ws wwery\n\n \n\n \n\nHs) AnoA +4) GRE S Desa Wed. sz) 2 YA",
"SMe SB4s AA SA slerqok S AMY AA 2017. 1. 25.\n\nS}A]U B Apo} lo} SOV gaze] ASS SSE ups}go}\nHea Ie mast + US AES sale] dst sa Bae\nSAZ UIs AS] AYIo) Bola B Zojm, 3 yo] Ge\nSAS L384 BAIs BSA H49] YS4RZ AE ¥\n\nU4. Baltes] 22ztBa SHAS 1S AVS] Vat S AMT.\n\n@) BA B SAA Oe $319] JAA SAE malrps] aeel\nFVqUF. 2B waits] ASs $49] SAB rw] MANE I a\n20] Eels} AYYA| 7lso] Sao] Bae Aas Ys = WE\nAALS] AABN WW BYU YRS mA = olok F AVIA",
"<ul § 6 . a | | Oe op eS op\nxz jo} x ojo —| XK ~<A zx DY NI\nzo YH Tr) ® m4 oft ie A <x ¥ “ote m = ®e\n1 = | 2 o + oJ 7 |\nfeu Se PSF se we eeeegee Fs\nVos] s| & xi =F & tae k ag @ » . a\nrosy op es — > ® a NR) | FB = x F is o om\n. —s| old KR Um RR ® xX| x) 3} mp F ay ty NE S\n* TA] OX x lu} Se or X ez jo i BD mo\ner Tae Sots ee FR\n= = 4 9) = x RX —_ 4\n2S yy se HR ao Ae Sy Vo ® a,\neng 2 5 = sl ge a) RS op 3 - &\nye e th yo TT t Oo) fo oF Ky nN ‘oa\nzo mH & eo © as rl yw we A ©",
"Hs) AnoA +4) GRE S Desa Wed. sz) 2 YA\n\nAAS Bare] AAS Seyret. ASSAY] Ao} o] Bsx- B\n\naso Rad = Fe] Ss] Gow zz) sta\n\n27) SStth.. #°) F SAE GER.\" AW ASID VSuUAE\n\n2” AOe F4), SF BAAR Barelo] AIS See} 72] FE 4\naL\n\nUs Me Mblass ase aad.\n\n \n\n \n\n \n\n]\n\na °\nwh Mm\n\nrr\nrr\nZl] A]\n\n22 Ap 71 HOH\nJE wy\n\nCc\n=z,\n\n& ah\ngow Ae] Vous\n\na\n\nAAS AO 2H), °] 8Voll\n\nSr Fle UA 4\n\nga WAS\n\ngata sels gay zhlel\n\nEAA,\n\n|\n\nz\nct\n\n \n\n1\n\n70\n\nH At\n\nOo\n\nZe ve o] Wey a\n\nw UMA. Asoe wy\n\n|\n\nE\nUL\n\niH\n\noO\nma»"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/paraphrase-multilingual-mpnet-base-v2. It maps sentences & paragraphs to a 768-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': 128, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 768, '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})
)
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
sentences = [
'서도 다른 미용실에서 근무를 하다 피고인이 새로 미용실을 오픈하자\n다시 와서 근무를 하기도 했습니다.\n- 고소인의 남자친구가 신문고에 올린 내용 중 일부(수사기록 제ㅌㅌ쪽 참조) -\n즉 고소인은 피고인과 수차례 합의 하에 성관계를 한 사이이며 그와같\n은 관계가 중단되었다하더라도 어느정도 친밀한 관계를 유지하고 있었\n던 관계라할 것입니다. 이에 당시 고소인을 데리러 왔던 남자친구가 고\n소인의 상태나 분위기가 뭔가 조금 이상하다고 생각하여 추궁을 하며\n혼자 있을 때 블랙박스 영상을 들었는데, 공교롭게도 녹음된 내용이 다\n소 두사람 사이의 관계에 대하여 오인 소지가 있는듯한 대화와 혀차는\n소리가 섞여있자 서로간에 합의 하에 뽀뽀를 한 것 아니냐 강압적인\n몰아가기를 하고 이에 고소인이 강제로 당한 것이라고 변명을 하였고\n이후에는 어쩔 수 없이 추행을 주장하고 있는 것이라 할 것입니다.\n3. 결론\n이상 본 바와같이 이 사건 블랙박스에서 들리는 소리는 뽀뽀 소리가 아닐',
'3. 결론\n이상 본 바와같이 이 사건 블랙박스에서 들리는 소리는 뽀뽀 소리가 아닐\n가능성이 상당하며 나아가 그 어떤 부분에도 고소인이 주장하는 바와같은\n고소인이 입을 막거나 거부하거나 머리채를 잡는 소리나 상황은 없고 또한\n피고인도 앞좌석에서 대화를 나눈 것으로 보이는 바, 이는 고소인이 거짓말\n을 하고 있는 것으로 고소인의 남자친구가 블랙박스를 들으며 서로 합의하\n에 뽀뽀를 한 것 아니냐고 하니 강제로 당한 것이라 만연히 진술하고 고소\n까지 이르게 되었을 의심을 배제할 수 없다할 것입니다.\n이에 본 사건은 피고인이 강제추행범이라 인정할만큼 합리적 의심의 여지\n없이 확실하다고 볼 수는 없다할 것으로 이와같은 사정을 고려하여 피고인\n에게 무죄를 선고하여 주실 것을 요청드립니다.\n2024. 10.\n위 피고인의 변호인\n법무법인 내일파트너스\n담당변호사 오 명 근\n담당변호사 손 정 미\n의정부지방법원 제 1 형사부 귀 중\n2.',
'(2) Ba SA warele] Maze Alo] Wow ypyat 1B We Ava\nol sahz} YA] SRS] APS AA] Yo) ZW +H esos Wat\n\nSPSL HA Tael2] Yo weps} wpwelo] BS Ax 2rE WA Woh',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
습니다(’증인 ㅊ에 대한 증인신문조서‘ 0쪽 참조). |
피고인을 설득해 몸을 일으켜세운 뒤 정신없이 황급히 뛰쳐 나갔다는 |
또한 피고인은 현장에서 경찰이 출동한 영문을 몰랐고 그 상태에서 고 |
고소인은 경찰조사에서 옥상 문 앞에서 있었던 일에 대하여 상당히 상 |
려고 하자 ‘피곤하니까 나중에 하자’고 하였고 이에 피고인은 알겠다고 |
어가 물2병을 사서 나누어 마신 뒤 ㅁ을 만나 인사를 나누고 헤어졌습 |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 4per_device_eval_batch_size: 4num_train_epochs: 1multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_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: 1num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: Nonehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_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: 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: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin@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}
}