Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use johnyy212/moe-girl-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("johnyy212/moe-girl-v2")
sentences = [
"围裙、大叔、爸爸、抽烟、上门女婿",
"Royde咖啡店老板",
"角色:罗丽娜\n本名:罗丽娜\n别名:萝莉娜\n发色:黑\n瞳色:红\n萌点:萝莉、傲娇、孩子气",
"角色:Royde咖啡店老板\n别名:店长、老爸\n发色:银\n瞳色:琥珀\n年龄:50\n萌点:店长、大叔、爸爸、上门女婿、围裙、抽烟、妻管严"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-small-zh-v1.5 on the json dataset. It maps sentences & paragraphs to a 512-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': 'BertModel'})
(1): Pooling({'embedding_dimension': 512, 'pooling_mode': 'cls', '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("johnyy212/moe-girl-v2")
# Run inference
sentences = [
'熟女、A型、召唤能力者',
'角色:文豪野犬:尾崎红叶\n本名:尾崎、红叶、Ozaki Kouyou\n别名:红叶大姐、红叶君\n声优:小清水亚美\n发色:红\n瞳色:红\n生日:1月10日\n星座:摩羯\n血型:A\n萌点:和服、遮眼发、超能力者、熟女',
'文豪野犬:尾崎红叶',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 512]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.3878, -0.0819],
# [ 0.3878, 1.0000, 0.0236],
# [-0.0819, 0.0236, 1.0000]])
anchor, positive, and char_name| anchor | positive | char_name | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | char_name |
|---|---|---|
井上和彦、早水理沙 |
角色:黑田 |
黑田 |
平田裕香 |
角色:寺门卷子 |
寺门卷子 |
蝴蝶结、高跟鞋、麦克风、制服、伞、乙女 |
角色:瞳(LIVE A HERO) |
瞳(LIVE A HERO) |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
anchor, positive, and char_name| anchor | positive | char_name | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | char_name |
|---|---|---|
小天使、发珠、料理达人、傲娇、长直 |
角色:云雀丘琉璃 |
云雀丘琉璃 |
黑瞳、银发、特工、B型 |
角色:风间让二 |
风间让二 |
红发、机郎、傲娇、蓝瞳 |
角色:爱因兹希 |
爱因兹希 |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 64learning_rate: 2e-05num_train_epochs: 5warmup_steps: 0.1fp16: Trueload_best_model_at_end: Truebatch_sampler: no_duplicatesdo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 8gradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 5max_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: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_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 |
|---|---|---|---|
| 0.1131 | 100 | 2.4777 | - |
| 0.2262 | 200 | 1.2126 | - |
| 0.3394 | 300 | 0.9734 | - |
| 0.4525 | 400 | 0.8498 | - |
| 0.5656 | 500 | 0.8329 | - |
| 0.6787 | 600 | 0.7920 | - |
| 0.7919 | 700 | 0.7039 | - |
| 0.9050 | 800 | 0.7013 | - |
| 1.0 | 884 | - | 0.1582 |
| 1.0181 | 900 | 0.6741 | - |
| 1.1312 | 1000 | 0.6307 | - |
| 1.2443 | 1100 | 0.6224 | - |
| 1.3575 | 1200 | 0.6090 | - |
| 1.4706 | 1300 | 0.5913 | - |
| 1.5837 | 1400 | 0.5812 | - |
| 1.6968 | 1500 | 0.5711 | - |
| 1.8100 | 1600 | 0.5614 | - |
| 1.9231 | 1700 | 0.5973 | - |
| 2.0 | 1768 | - | 0.1351 |
| 2.0362 | 1800 | 0.5275 | - |
| 2.1493 | 1900 | 0.5139 | - |
| 2.2624 | 2000 | 0.4939 | - |
| 2.3756 | 2100 | 0.5008 | - |
| 2.4887 | 2200 | 0.5044 | - |
| 2.6018 | 2300 | 0.4932 | - |
| 2.7149 | 2400 | 0.5083 | - |
| 2.8281 | 2500 | 0.5151 | - |
| 2.9412 | 2600 | 0.4993 | - |
| 3.0 | 2652 | - | 0.1247 |
| 3.0543 | 2700 | 0.4770 | - |
| 3.1674 | 2800 | 0.4751 | - |
| 3.2805 | 2900 | 0.4676 | - |
| 3.3937 | 3000 | 0.4480 | - |
| 3.5068 | 3100 | 0.4579 | - |
| 3.6199 | 3200 | 0.4581 | - |
| 3.7330 | 3300 | 0.4524 | - |
| 3.8462 | 3400 | 0.4532 | - |
| 3.9593 | 3500 | 0.4493 | - |
| 4.0 | 3536 | - | 0.1188 |
| 4.0724 | 3600 | 0.4443 | - |
| 4.1855 | 3700 | 0.4296 | - |
| 4.2986 | 3800 | 0.4117 | - |
| 4.4118 | 3900 | 0.4397 | - |
| 4.5249 | 4000 | 0.4223 | - |
| 4.6380 | 4100 | 0.4448 | - |
| 4.7511 | 4200 | 0.4304 | - |
| 4.8643 | 4300 | 0.4494 | - |
| 4.9774 | 4400 | 0.4271 | - |
| 5.0 | 4420 | - | 0.1192 |
@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{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-small-zh-v1.5
from sentence_transformers import SentenceTransformer model = SentenceTransformer("johnyy212/moe-girl-v2") sentences = [ "围裙、大叔、爸爸、抽烟、上门女婿", "Royde咖啡店老板", "角色:罗丽娜\n本名:罗丽娜\n别名:萝莉娜\n发色:黑\n瞳色:红\n萌点:萝莉、傲娇、孩子气", "角色:Royde咖啡店老板\n别名:店长、老爸\n发色:银\n瞳色:琥珀\n年龄:50\n萌点:店长、大叔、爸爸、上门女婿、围裙、抽烟、妻管严" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4]