Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use tomaarsen/reranker-japanese-tiny-auto-wiki-qa with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("tomaarsen/reranker-japanese-tiny-auto-wiki-qa")
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 ku-nlp/deberta-v2-tiny-japanese using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'DebertaV2ForSequenceClassification'})
)
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("tomaarsen/reranker-japanese-tiny-auto-wiki-qa")
# Get scores for pairs of inputs
pairs = [
['『「されどわれらが日々」より別れの詩』はどんな小説?', 'ゲームとしては、音声連動ゲームの特徴に合わせた若干の変更が細部にあるものの、シリーズ1作目であるディスクシステム版『ゼルダの伝説』をスーパーファミコン向け、かつ限られた放送時間に則したリメイクをした内容になっている。'],
['日本で最初にコンタクトレンズが完成したのはいつ?', 'クレーシーズンに入り、セルビア・オープンでは決勝でノバク・ジョコビッチから初白星を挙げ、今季3勝目、通算ツアー11勝目を挙げた。全仏オープンでは準4回戦でヤニック・シナーを下して、準々決勝でマリン・チリッチにフルセットの末敗れた。'],
['2007年4月にデビュー20周年を迎えたKANのベスト・アルバムは何?', '2020年8月24日、ヴォルフスベルガーACと2年契約を締結。加入1年目の2020-21シーズンに22試合に出場すると、翌2021-22シーズンも29試合1ゴールを記録するなど、チームの中心選手に定着。'],
['フリーカンパニーとは何でしょう?', '「ファミリー・アフェアー」(Family Affair)はメアリー・J. ブライジのシングル。5thアルバム『ノー・モア・ドラマ』(No More Drama)からの先行シングルとして2001年6月に発売された。'],
['西江の流域面積はどれくらい?', '次に、開水路を流れ方向に平行に切った断面図が図3である。先と同じように、青色で示された線は自由水面、茶色で描かれたものが水路床あるいは河床(bed)である。この図では、河床に平行に x {\\displaystyle x} 軸を取り、それに垂直方向に y {\\displaystyle y} 軸をとっている。この河床から y {\\displaystyle y} 軸に測った時の水面までの距離が水深と定義され、 h {\\displaystyle h} で表される。このy軸とは別に、重力 g {\\displaystyle g} に対して垂直な基準線あるいは基準レベル(base level)から測った高さ z {\\displaystyle z} も定義される。例えば、河床までの高さは z b {\\displaystyle z_{b}} で表される。また、基準線から水面までの距離を水位と言う。そして、この基準線と河床のなす角を θ {\\displaystyle \\theta } とした時、河床勾配(bed gradient)は I b = sin θ {\\displaystyle I_{b}=\\sin \\theta } で定義される。ただし、一般的に河床勾配は小さいと考えられるため、 sin θ = θ , cos θ = 1 {\\displaystyle \\sin \\theta =\\theta ,\\cos \\theta =1} とすることがあり、この場合は θ {\\displaystyle \\theta } 自身を河床勾配と呼ぶこともある。このような流れの状態の時、主流速は水色の矢印で示したような分布をしていると考えられる。ある高さ z {\\displaystyle z} の点での主流速は U {\\displaystyle U} 、圧力は p {\\displaystyle p} で表される。この主流速を断面平均したものが断面平均流速 v {\\displaystyle v} である。一次元解析では単に流速(velocity)と呼ばれることもある。'],
]
scores = model.predict(pairs)
print(scores)
# [0.0091 0.0124 0.0083 0.0117 0.0117]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'『「されどわれらが日々」より別れの詩』はどんな小説?',
[
'ゲームとしては、音声連動ゲームの特徴に合わせた若干の変更が細部にあるものの、シリーズ1作目であるディスクシステム版『ゼルダの伝説』をスーパーファミコン向け、かつ限られた放送時間に則したリメイクをした内容になっている。',
'クレーシーズンに入り、セルビア・オープンでは決勝でノバク・ジョコビッチから初白星を挙げ、今季3勝目、通算ツアー11勝目を挙げた。全仏オープンでは準4回戦でヤニック・シナーを下して、準々決勝でマリン・チリッチにフルセットの末敗れた。',
'2020年8月24日、ヴォルフスベルガーACと2年契約を締結。加入1年目の2020-21シーズンに22試合に出場すると、翌2021-22シーズンも29試合1ゴールを記録するなど、チームの中心選手に定着。',
'「ファミリー・アフェアー」(Family Affair)はメアリー・J. ブライジのシングル。5thアルバム『ノー・モア・ドラマ』(No More Drama)からの先行シングルとして2001年6月に発売された。',
'次に、開水路を流れ方向に平行に切った断面図が図3である。先と同じように、青色で示された線は自由水面、茶色で描かれたものが水路床あるいは河床(bed)である。この図では、河床に平行に x {\\displaystyle x} 軸を取り、それに垂直方向に y {\\displaystyle y} 軸をとっている。この河床から y {\\displaystyle y} 軸に測った時の水面までの距離が水深と定義され、 h {\\displaystyle h} で表される。このy軸とは別に、重力 g {\\displaystyle g} に対して垂直な基準線あるいは基準レベル(base level)から測った高さ z {\\displaystyle z} も定義される。例えば、河床までの高さは z b {\\displaystyle z_{b}} で表される。また、基準線から水面までの距離を水位と言う。そして、この基準線と河床のなす角を θ {\\displaystyle \\theta } とした時、河床勾配(bed gradient)は I b = sin θ {\\displaystyle I_{b}=\\sin \\theta } で定義される。ただし、一般的に河床勾配は小さいと考えられるため、 sin θ = θ , cos θ = 1 {\\displaystyle \\sin \\theta =\\theta ,\\cos \\theta =1} とすることがあり、この場合は θ {\\displaystyle \\theta } 自身を河床勾配と呼ぶこともある。このような流れの状態の時、主流速は水色の矢印で示したような分布をしていると考えられる。ある高さ z {\\displaystyle z} の点での主流速は U {\\displaystyle U} 、圧力は p {\\displaystyle p} で表される。この主流速を断面平均したものが断面平均流速 v {\\displaystyle v} である。一次元解析では単に流速(velocity)と呼ばれることもある。',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
auto-wiki-qa-jaCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10
}
| Metric | Value |
|---|---|
| map | 0.9817 |
| mrr@10 | 0.9817 |
| ndcg@10 | 0.9856 |
query, answer, and label| query | answer | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| query | answer | label |
|---|---|---|
ベニート・ムッソリーニを2回演じた俳優は誰? |
2022年、オーガスト・ウィルソン・シアターにてブロードウェイ再演が上演されることとなり、3月26日にプレビュー公演、4月24日に本公演が開幕した。ハーヴェイ・ファイアスタインの改訂脚本にてマイケル・メイヤーが演出を担当した。ビーニー・フェルドスタインがファニー役、ラミン・カリムルーがニック役、ジャレッド・グリムズがエディ役、ジェーン・リンチがミセス・ブライス役に配役された。批評家からの評価は低いものが多かったが、トニー賞においてグリムズがミュージカル助演男優賞にノミネートされた。2022年7月10日、フェルドスタインが9月までの予定に関わらず7月末で降板することを発表した。翌日、9月6日よりフェルドスタインの後継にリア・ミシェルが、リンチの後継にトヴァー・フェルドシャーが配役され、それまでの間、ファニー役はジュリー・ベンコが演じることが発表された。2022年8月9日、リンチは9月までの予定に関わらず、8月14日で降板することを発表し、フェルドシャーの出演が始まるまでスタンドバイのリズ・マッカートニーがミセス・ブライス役を演じることとなった。 |
0 |
佐々木敢一は何歳で亡くなった? |
スイスの最西端の都市ジュネーヴで生まれ、2歳までフランスに滞在。帰国後は埼玉県三郷市で育った。将棋は帰国後の5歳から始めている。きっかけは水泳で罹患していた中耳炎を悪化させて1週間ほど入院し、退院後も安静が必要だったため屋内で遊べるものをと母親が将棋セットを与えたことであった。佐々木家では祖父がもっぱら囲碁に親しんでいたが、5歳児では碁石を食べ物と間違えて誤飲しかねないため、将棋を選んだという。 |
0 |
『Newsリアルタイムふくい』の通称は何? |
地区名の「ラ・リヴィエール・アングレーズ」はフランス語名で、同じく公用語の英語ではイングリッシュ・リバー(English River)と呼ばれる。なお、もうひとつの公用語であるセーシェル・クレオール語では「Larivyer Anglez」と呼ばれる。 |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 4.962394714355469
}
query, answer, and label| query | answer | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| query | answer | label |
|---|---|---|
『「されどわれらが日々」より別れの詩』はどんな小説? |
ゲームとしては、音声連動ゲームの特徴に合わせた若干の変更が細部にあるものの、シリーズ1作目であるディスクシステム版『ゼルダの伝説』をスーパーファミコン向け、かつ限られた放送時間に則したリメイクをした内容になっている。 |
0 |
日本で最初にコンタクトレンズが完成したのはいつ? |
クレーシーズンに入り、セルビア・オープンでは決勝でノバク・ジョコビッチから初白星を挙げ、今季3勝目、通算ツアー11勝目を挙げた。全仏オープンでは準4回戦でヤニック・シナーを下して、準々決勝でマリン・チリッチにフルセットの末敗れた。 |
0 |
2007年4月にデビュー20周年を迎えたKANのベスト・アルバムは何? |
2020年8月24日、ヴォルフスベルガーACと2年契約を締結。加入1年目の2020-21シーズンに22試合に出場すると、翌2021-22シーズンも29試合1ゴールを記録するなど、チームの中心選手に定着。 |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 4.962394714355469
}
per_device_train_batch_size: 64num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1weight_decay: 0.01bf16: Trueper_device_eval_batch_size: 64load_best_model_at_end: Trueseed: 12per_device_train_batch_size: 64num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: 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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_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: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 12data_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_static_graph: Noneddp_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 | Validation Loss | auto-wiki-qa-ja_ndcg@10 |
|---|---|---|---|---|
| -1 | -1 | - | - | 0.4858 |
| 0.0001 | 1 | 1.2118 | - | - |
| 0.0101 | 94 | 1.1810 | - | - |
| 0.0202 | 188 | 1.1507 | - | - |
| 0.0303 | 282 | 1.1372 | - | - |
| 0.0404 | 376 | 1.1215 | - | - |
| 0.0505 | 470 | 0.9716 | - | - |
| 0.0606 | 564 | 0.8534 | - | - |
| 0.0707 | 658 | 0.7374 | - | - |
| 0.0808 | 752 | 0.6243 | - | - |
| 0.0909 | 846 | 0.5548 | - | - |
| 0.1000 | 931 | - | 0.4113 | 0.9760 |
| 0.1010 | 940 | 0.4759 | - | - |
| 0.1111 | 1034 | 0.4161 | - | - |
| 0.1212 | 1128 | 0.3947 | - | - |
| 0.1313 | 1222 | 0.3773 | - | - |
| 0.1414 | 1316 | 0.3509 | - | - |
| 0.1515 | 1410 | 0.3211 | - | - |
| 0.1616 | 1504 | 0.3057 | - | - |
| 0.1717 | 1598 | 0.3120 | - | - |
| 0.1818 | 1692 | 0.2968 | - | - |
| 0.1919 | 1786 | 0.2753 | - | - |
| 0.2001 | 1862 | - | 0.2601 | 0.9814 |
| 0.2020 | 1880 | 0.3227 | - | - |
| 0.2121 | 1974 | 0.2671 | - | - |
| 0.2222 | 2068 | 0.2845 | - | - |
| 0.2323 | 2162 | 0.2707 | - | - |
| 0.2424 | 2256 | 0.2851 | - | - |
| 0.2525 | 2350 | 0.2591 | - | - |
| 0.2626 | 2444 | 0.2515 | - | - |
| 0.2727 | 2538 | 0.2665 | - | - |
| 0.2828 | 2632 | 0.2669 | - | - |
| 0.2929 | 2726 | 0.2379 | - | - |
| 0.3001 | 2793 | - | 0.2304 | 0.9825 |
| 0.3030 | 2820 | 0.2657 | - | - |
| 0.3131 | 2914 | 0.2238 | - | - |
| 0.3232 | 3008 | 0.2424 | - | - |
| 0.3333 | 3102 | 0.2431 | - | - |
| 0.3434 | 3196 | 0.2418 | - | - |
| 0.3535 | 3290 | 0.2289 | - | - |
| 0.3636 | 3384 | 0.2393 | - | - |
| 0.3737 | 3478 | 0.2282 | - | - |
| 0.3838 | 3572 | 0.2293 | - | - |
| 0.3939 | 3666 | 0.2396 | - | - |
| 0.4002 | 3724 | - | 0.2098 | 0.9835 |
| 0.4040 | 3760 | 0.2443 | - | - |
| 0.4141 | 3854 | 0.2465 | - | - |
| 0.4242 | 3948 | 0.2224 | - | - |
| 0.4343 | 4042 | 0.2228 | - | - |
| 0.4444 | 4136 | 0.2240 | - | - |
| 0.4545 | 4230 | 0.2051 | - | - |
| 0.4646 | 4324 | 0.2064 | - | - |
| 0.4747 | 4418 | 0.2440 | - | - |
| 0.4848 | 4512 | 0.2593 | - | - |
| 0.4949 | 4606 | 0.2287 | - | - |
| 0.5002 | 4655 | - | 0.2084 | 0.9850 |
| 0.5051 | 4700 | 0.2105 | - | - |
| 0.5152 | 4794 | 0.2158 | - | - |
| 0.5253 | 4888 | 0.2178 | - | - |
| 0.5354 | 4982 | 0.2485 | - | - |
| 0.5455 | 5076 | 0.2039 | - | - |
| 0.5556 | 5170 | 0.2173 | - | - |
| 0.5657 | 5264 | 0.1994 | - | - |
| 0.5758 | 5358 | 0.2423 | - | - |
| 0.5859 | 5452 | 0.1970 | - | - |
| 0.5960 | 5546 | 0.2115 | - | - |
| 0.6003 | 5586 | - | 0.1973 | 0.9856 |
| 0.6061 | 5640 | 0.2252 | - | - |
| 0.6162 | 5734 | 0.2096 | - | - |
| 0.6263 | 5828 | 0.2174 | - | - |
| 0.6364 | 5922 | 0.2348 | - | - |
| 0.6465 | 6016 | 0.2073 | - | - |
| 0.6566 | 6110 | 0.2011 | - | - |
| 0.6667 | 6204 | 0.1737 | - | - |
| 0.6768 | 6298 | 0.2077 | - | - |
| 0.6869 | 6392 | 0.2339 | - | - |
| 0.6970 | 6486 | 0.2158 | - | - |
| 0.7003 | 6517 | - | 0.1718 | 0.9853 |
| 0.7071 | 6580 | 0.2093 | - | - |
| 0.7172 | 6674 | 0.1844 | - | - |
| 0.7273 | 6768 | 0.2290 | - | - |
| 0.7374 | 6862 | 0.2104 | - | - |
| 0.7475 | 6956 | 0.2257 | - | - |
| 0.7576 | 7050 | 0.2251 | - | - |
| 0.7677 | 7144 | 0.2216 | - | - |
| 0.7778 | 7238 | 0.2061 | - | - |
| 0.7879 | 7332 | 0.1936 | - | - |
| 0.7980 | 7426 | 0.2379 | - | - |
| 0.8003 | 7448 | - | 0.1727 | 0.9855 |
| 0.8081 | 7520 | 0.1819 | - | - |
| 0.8182 | 7614 | 0.2353 | - | - |
| 0.8283 | 7708 | 0.2131 | - | - |
| 0.8384 | 7802 | 0.2044 | - | - |
| 0.8485 | 7896 | 0.2020 | - | - |
| 0.8586 | 7990 | 0.2011 | - | - |
| 0.8687 | 8084 | 0.1970 | - | - |
| 0.8788 | 8178 | 0.2376 | - | - |
| 0.8889 | 8272 | 0.2090 | - | - |
| 0.8990 | 8366 | 0.2130 | - | - |
| 0.9004 | 8379 | - | 0.1692 | 0.9856 |
| -1 | -1 | - | - | 0.9856 |
@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",
}
Base model
ku-nlp/deberta-v2-tiny-japanese