Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use Miya67/aiq-scoring-e5-small-wiki-absolute with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("Miya67/aiq-scoring-e5-small-wiki-absolute")
query = "Which planet is known as the Red Planet?"
passages = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
]
scores = model.predict([(query, passage) for passage in passages])
print(scores)This is a Cross Encoder model finetuned from hotchpotch/japanese-reranker-cross-encoder-small-v1 using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("Miya67/aiq-scoring-e5-small-wiki-absolute")
# Get scores for pairs of texts
pairs = [
['問題: 俳優の哀川翔、女優の小西真奈美、歌手の長渕剛の出身都道府県はどこでしょう? / 想定解: 鹿児島県', '熊毛地域'],
['問題: 和名を「トウショウブ」や「オランダショウブ」という、剣のように尖った葉が特徴的なアヤメ科の植物は何でしょう? / 想定解: グラジオラス', 'グラジオラス属'],
['問題: 月見そばで、卵の黄身が表しているものは月ですが、白身が表しているものは何でしょう? / 想定解: 雲', '分子雲'],
['問題: 1950年に第1回日本シリーズの第1戦が行われた、現在はヤクルトスワローズが本拠地とする野球場はどこでしょう? / 想定解: 明治神宮野球場', '明治神宮野球大会'],
['問題: オーストラリアの6つの州の中で、最も面積が大きいのは西オーストラリア州ですが、最も面積が小さいのは何州でしょう? / 想定解: タスマニア州', 'たすまにあしゅうそうとく'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'問題: 俳優の哀川翔、女優の小西真奈美、歌手の長渕剛の出身都道府県はどこでしょう? / 想定解: 鹿児島県',
[
'熊毛地域',
'グラジオラス属',
'分子雲',
'明治神宮野球大会',
'たすまにあしゅうそうとく',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
問題: 俳優の哀川翔、女優の小西真奈美、歌手の長渕剛の出身都道府県はどこでしょう? / 想定解: 鹿児島県 |
熊毛地域 |
1.0 |
問題: 和名を「トウショウブ」や「オランダショウブ」という、剣のように尖った葉が特徴的なアヤメ科の植物は何でしょう? / 想定解: グラジオラス |
グラジオラス属 |
1.0 |
問題: 月見そばで、卵の黄身が表しているものは月ですが、白身が表しているものは何でしょう? / 想定解: 雲 |
分子雲 |
0.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
per_device_train_batch_size: 32num_train_epochs: 4per_device_eval_batch_size: 32per_device_train_batch_size: 32num_train_epochs: 4max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: trackioeval_strategy: noper_device_eval_batch_size: 32prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.1528 | 500 | 0.6662 |
| 0.3056 | 1000 | 0.6092 |
| 0.4584 | 1500 | 0.5728 |
| 0.6112 | 2000 | 0.5385 |
| 0.7641 | 2500 | 0.5165 |
| 0.9169 | 3000 | 0.4984 |
| 1.0697 | 3500 | 0.4844 |
| 1.2225 | 4000 | 0.4681 |
| 1.3753 | 4500 | 0.4557 |
| 1.5281 | 5000 | 0.4539 |
| 1.6809 | 5500 | 0.4460 |
| 1.8337 | 6000 | 0.4402 |
| 1.9866 | 6500 | 0.4317 |
| 2.1394 | 7000 | 0.4071 |
| 2.2922 | 7500 | 0.3955 |
| 2.4450 | 8000 | 0.3957 |
| 2.5978 | 8500 | 0.3874 |
| 2.7506 | 9000 | 0.3996 |
| 2.9034 | 9500 | 0.3933 |
| 3.0562 | 10000 | 0.3788 |
| 3.2090 | 10500 | 0.3635 |
| 3.3619 | 11000 | 0.3613 |
| 3.5147 | 11500 | 0.3633 |
| 3.6675 | 12000 | 0.3584 |
| 3.8203 | 12500 | 0.3592 |
| 3.9731 | 13000 | 0.3555 |
@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",
}