Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use micky1625/finetuned with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("micky1625/finetuned")
sentences = [
"성인은 왜 욕심이 없는 것으로 설명되는가?",
"정하\n여 자신의 욕심에 미칠 겨를이 없는 사람은 반드시 배우기를 싫어하지 않고 가르치기를 게을리 하\n지 않으니 배우기를 싫어하지 않고 가르치기를 게을리 하지 않으므로 성인은 욕심이 없는 것이다. \n자신에게 터럭만큼이라도 욕심이 있은 즉 요순의 마음이 아니오, 잠시라도 천하를 걱정하지 않은 \n즉 공맹의 마음이 아니다. \n 태양인은 슬픈 성품이 멀리 흩어지지만 화내는 성품은 지극히 급하니 슬픈 성질이 멀리 흩어지면 \n기가 폐로 들어가서 폐가 더욱 성해지고, 화내는 성질이 지극히 급하면 기가 간을 격동시켜 간은 \n더욱 깎이니 태양인의 장부가 폐가 크고 간이 작은 것으로 형성되는 까닭이다. 소양인은 화내는 성\n품이 크게 화를 내지만 슬픈 성품이 매우 급하니 화내는 성품이 크게 화를 내면 기가 비로 들어가\n서 비가 더욱 성해지고, 슬픈 성품이 매우 급하면 기가 신을 격동시켜서 신은 더욱 깎이니 소양인\n의 장부가 비가 크고 신이 작은 것으로 형성되는 까닭이다. 음인은 기쁜 성품이 넓고 크지만 즐거\n운 성품이 지극히 급하니 기쁜 성품이 많아지면 기가 간으로 가서 간이 더욱 성해지고, 즐기는 성\n품이 지극히 급하면 기가 폐를 격동시켜 폐는 더욱 깎일 것이니 태음인의 장부가 간이 크고 폐가 \n작은 것으로 형성되는 까닭이다. 소음인은 즐기는 성품이 매우 확실하고 기쁜 성품이 매우 급하니 \n즐기는 성품이 깊이 확실하면 기가 신으로 가서 신이 더욱 성해지",
"민을 나실 때 지혜로운 깨달음으로 성(性)을 주니 만인이 태어남에 지혜로운 깨달음이 \n있으면 살고 없으면 죽는다. 지혜로운 깨달음이란 덕이 생겨나게 하는 바이다. \n 하늘의 만민을 나실 때 자업으로 명(命)을 주니 만인이 태어남에 자업이 있으면 살고 없으면 죽는\n다. 자업이란 도가 생겨나게 하는 바이다. \n 어질고, 의롭고, 예의있고, 지혜있고, 충성스럽고, 효도하고, 우애있고 공경하는 모든 선행은 다 혜\n각에서 나오고, 선비, 농사, 공업, 상업, 밭갈기, 주택, 국토, 나라의 모든 용은 다 자업에서 나온다. \n 혜각은 남을 겸하고자 해야 가르침이 있고, 자업은 내가 청렴하고자 해야 공이 있으니 혜각이 사\n소한 자로 비록 호걸이 있더라도 조조처럼 교활하면 가르칠 수가 없다. 자업을 마음대로 휘두른 자\n는 비록 영웅이 있으나 진시황처럼 사나우면 공을 세울 수 없다. \n 남의 선을 좋아하고 나도 선을 아는 것은 지극한 성의 덕이오, 남의 악을 싫어하고 나도 반드시 악\n을 행하지 않는 것은 바른 명의 도이다. 지행이 쌓인 즉 도덕이오, 도덕이 이루어진 즉 인(仁), 성(\n聖)이니 도덕은 다른 것이 아니라 지행이오, 성명이 다른 것이 아니라 지행이다.\n 어느 사람이 묻기를 “지를 가지고 성을 논하는 것은 가능하지만 행을 가지고 명을 논하는 것은 무\n슨 뜻인가?” 라고 하니 이르기를 “명은 명수니 선행을 하면 명수는 저절로 아름답고, 악행을",
"이미지황탕을 쓸 것이다.\n 부종은 그 증세를 급히 치료하면 살고 급히 치료하지 않으면 위태하다. 약을 빨리 쓰면 쉽게 낫고 \n약을 빨리 쓰지 않으면 맹랑하게 죽는다. 이 병은 겉으로 보기에는 아무렇지도 않아서 속히 죽을 \n것 같지 않다. 때문에 사람들은 별로 대수롭지 않게 여긴다. 그러나 이 병은 실제로는 급한 증세인 \n것이다. 4,5일 이내에 반드시 다스려야 할 병이요 늦어도 열흘을 넘겨서는 안 된다.\n 부종이 처음 생겼을 때에 마땅히 목통대안탕(木通大安湯)이나 혹 형방지황탕(荊防地黃湯)에 목통\n을 가미해서 하루에 두 첩씩 쓰면 6,7일 이내에 부종이 반드시 풀릴 것이다. 부종이 풀린 뒤에 백일\n이내는 반드시 형방지황탕에 목통(木通) 2,3돈쭝을 가입해서 날마다 1,2첩씩 써야 한다. 이리하여 \n소변을 맑게 하여 재발을 막아야 할 것이니 재발되면 고치기 어렵다.\n 부종이 처음 풀렸을 때에 음식은 더욱 배고픈 것을 참고 조금씩 먹어야 한다. 만일 보통 사람과 같\n이 많이 먹으면 반드시 재발하는 것을 면치 못할 것이다. 이 병은 오줌이 붉은 것이 제일 두려운 것\n이다. 오줌이 맑으면 부종이 풀리고 오줌이 붉으민 더 맺혀진다.\n 소양인의 중소증에 배가 부으면 반드시 고창(鼓脹)이 된다. 고창은 고치지 못하는 병이다. 소양인\n의 고창병은 소음인의 장결병(臟結病)과 같아서 모두 5,6개월이나 7,8개월 혹은 1년 만이면 죽고 만\n다. 대개 "
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from upskyy/e5-small-korean. It maps sentences & paragraphs to a 384-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: BertModel
(1): Pooling({'word_embedding_dimension': 384, '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("micky1625/finetuned")
# Run inference
sentences = [
'왜 수은을 쓰는 사람은 소금이나 간장을 먹지 말라고 하는지 이유는 무엇인가요?',
' 첫날 2대 다음날 1\n대를 피웠다. 그런데 그날 밤에 더운 방에서 찬바람을 쐬고서 갑자기 죽었다. 세속의 말에 의하면 \n수은을 쓰는 사람은 소금이나 간장을 먹지 말라고 한다. 그것은 간장 속에는 콩이 들어 있어서 수\n은의 독기를 풀어 버리기 때문이다. 그러나 독한 약은 약간의 독을 풀어 주는 것도 무방하기 때문\n에 구태여 소금과 간장을 금할 필요는 없다.\n東醫壽世保元 卷之四\n 太陰人 胃脘受寒表寒病論\n장중경이 말하기를 태양병 상한에 머리가 아프고 열이 오르며, 온몸과 허리가 아프고 골절이 쑤시\n며 오한이 나고 땀이 없어 숨이 찬 데에는 마황탕을 주로 써야 한다. 주에 말하기를 상한에 두통이 \n나고 온몸이 아프며 허리가 아프고 골절이 모두 쑤시기에 이르는 것은 태양병 상한에 영혈이 고르\n지 못하기 문이다. \n 내가 말하기를 이는 곧 태음인이 한기에 배추 표병이니 가벼운 증세이다. 이와 같은 증세에 마황\n탕을 쓸 수 없는 것은 아니나 계지와 감초는 필요치 않은 약이니 마땅히 마황발표탕을 쓸 것이다. \n 장중경이 말하기를 상한이 된지 4,5 일에 궐이 되는 자는 반드시 열이 오른다. 궐이 심한 자는 열\n도 심하고 궐이 경미한 자는 열도 또한 경미하다. 상한에 궐이 된 지 4일만에 다시 열이 오르고 3일\n만에 다시 궐이 되어 5일에 궐이 많고 열이 적으면 이는 그 병이 진행하고 있는 것이며 상한에 열\n이 있은 지 4일에 다시 궐로 돌아오고,',
'성이 지극하면 로정이 움직이고, 로성이 지극하면 애정\n이 움직이며, 락성이 지극하면 희정이 움직이고, 희성이 지극하면 락정이 움직인다. 태양인이 애성\n이 지극하여 그치지 못하면 분노가 밖으로 나오고, 소양인이 로성이 지극하여 이기지 못하면 비애\n가 가슴속으로 움직이고, 소음인이 락성이 지극하여 이루지 못하면 기쁘고 좋아하는 것이 정할 수 \n없고, 태음인이 희성이 지극하여 가라앉지 않으면 치락이 끝이 없을 것이다. 이와 같이 움직이는 것\n은 칼날로 장부를 자르는 것과 다름이 없다. 한번 크게 움직이면 10년이 지나도 회복하기 어려우니\n이는 죽과 사는 것과 수(壽), 요(夭)의 기관이니 몰라서는 안되는 것이다. \n 태소음양의 장부의 짧고 김은 음양의 변화니 천품이 이미 결정된 것은 두말할 나위도 없거니와 천\n품이 이미 정해진 것 이외에 또한 짧고 김이 있으니 천품이 완전하지 못한 자는 사람일의 닦음과 \n닦지 않음에 운명이 좌우되니 삼가지 않으면 안된다.\n 태양인의 로는 한사람의 로로써 천만인을 노하게 하니 그 로가 천만인을 다룰 방법이 없다면 반드\n시 천만인을 감당하기 어려울 것이다. 소음인의 희는 한사람의 희로써 천만인을 희하게 하니 그 희\n가 천만인을 다룰 방법이 없다면 반드시 천만인을 감당하기 어려울 것이다. 소양인의 애는 한 사람\n의 애로써 천만인을 애하게 하니 그 애가 천만인을 다룰 방법이 없다면 반드시 천만인을 감당하기 \n어려',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5625 |
| cosine_accuracy@3 | 0.7812 |
| cosine_accuracy@5 | 0.8438 |
| cosine_accuracy@10 | 0.9062 |
| cosine_precision@1 | 0.5625 |
| cosine_precision@3 | 0.2604 |
| cosine_precision@5 | 0.1688 |
| cosine_precision@10 | 0.0906 |
| cosine_recall@1 | 0.5625 |
| cosine_recall@3 | 0.7812 |
| cosine_recall@5 | 0.8438 |
| cosine_recall@10 | 0.9062 |
| cosine_ndcg@10 | 0.7476 |
| cosine_mrr@10 | 0.6958 |
| cosine_map@100 | 0.7024 |
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
태음인의 성품과 기질에 대한 내용을 바탕으로, 왜 소양인은 항상 일을 하려고 하지만 그만두려 하지 않는 것일까요? |
지만 거처는 애로써 다스릴 수 없 |
환자가 어떤 증상을 보일 때 대체로 효과적인 약물을 사용할 수 있는지에 대한 정보는 무엇인가요? |
병이 풀리지 않으며 불통이 5, 6일에서 10여 일에 이르고 오 |
성인과 보통 사람의 마음의 차이에 대해 어떻게 설명되고 있나요? |
하늘을 |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 5per_device_eval_batch_size: 5num_train_epochs: 2multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 5per_device_eval_batch_size: 5per_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: 2max_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: 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: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | cosine_ndcg@10 |
|---|---|---|
| 1.0 | 25 | 0.7457 |
| 2.0 | 50 | 0.7476 |
@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}
}