Tien09/pair_similarity
Viewer • Updated • 12.8k • 11
How to use Tien09/tiny_bert_ft_sim_score with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Tien09/tiny_bert_ft_sim_score")
sentences = [
"When this card is Normal Summoned: You can Special Summon 1 \"Crashbug X\" from your Deck. You must control a face-up \"Crashbug Z\" to activate and to resolve this effect.",
"You can remove from play 1 Tuner monster in your GY to Special Summon this card from your hand.",
"This spirit emerges from the mystic lamp and obeys the wishes of its summoner.",
"When your opponent activates a monster effect, while you control a \"Beetrooper\" monster: Negate the activation, and if you do, destroy it. During your End Phase, if this card is in your GY and you control an Insect monster with 3000 or more ATK: You can banish 1 Insect monster from your GY; Set this card. You can only use 1 \"Beetrooper Fly & Sting\" effect per turn, and only once that turn."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from prajjwal1/bert-tiny on the pair_similarity dataset. It maps sentences & paragraphs to a 128-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': 128, '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("Tien09/tiny_bert_ft_sim_score")
# Run inference
sentences = [
'If you control 3 or more face-up "Six Samurai" monsters, you can activate 1 of these effects: Destroy all face-up monsters your opponent controls. Destroy all face-up Spell/Trap Cards your opponent controls. Destroy all Set Spell/Trap Cards your opponent controls.',
'Target 1 Link Monster you control and 1 monster your opponent controls; destroy them, then draw 1 card. You can only activate 1 "Link Burst" per turn.',
'While you have 2 or less cards in your hand, all face-up "Fabled" monsters you control gain 400 ATK.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 128]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
effect_text, score, and effect_text2| effect_text | score | effect_text2 | |
|---|---|---|---|
| type | string | float | string |
| details |
|
|
|
| effect_text | score | effect_text2 |
|---|---|---|
Once per turn, if you Special Summon a DARK Synchro Monster(s) from the Extra Deck: You can target 1 of your "Blackwing" monsters, or "Black-Winged Dragon", with lower ATK that is banished or in your GY; Special Summon it. Once per turn, if a DARK monster(s) you control would be destroyed by battle or card effect, you can remove 1 Black Feather Counter from your field instead. |
0.0 |
A Millennium item, it's rumored to block any strong attack. |
Target 1 face-up monster your opponent controls; the ATK of all other monsters currently on the field become equal to that monster's ATK, until the end of this turn. |
0.0 |
While you control a "Blue-Eyes" monster, you choose the attack targets for your opponent's attacks. You can only use each of the following effects of "Dictator of D." once per turn. You can send 1 "Blue-Eyes White Dragon" from your hand or Deck to the GY; Special Summon this card from your hand. You can discard 1 "Blue-Eyes White Dragon", or 1 card that mentions it, then target 1 "Blue-Eyes" monster in your GY; Special Summon it. |
1 Tuner + 1+ non-Tuner monsters |
||
If this card is Synchro Summoned using a Tuner Synchro Monster: You can target 1 Spell/Trap in your GY; add it to your hand. When your opponent activates a card or effect (Quick Effect): You can send 1 Spell/Trap from your hand or field to the GY; Special Summon 1 Level 7 or lower Tuner Synchro Monster from your Extra Deck, GY, or banishment. You can only use each effect of "Diabell, Queen of the White Forest" once per turn. |
0.2 |
1 Aqua monster + 1 Level 10 WATER monster |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
effect_text, score, and effect_text2| effect_text | score | effect_text2 | |
|---|---|---|---|
| type | string | float | string |
| details |
|
|
|
| effect_text | score | effect_text2 |
|---|---|---|
A proud ruler of the jungle that some fear and others respect. |
0.0 |
Cannot attack the turn it is Normal Summoned. Once per turn: You can target 1 face-up monster on the field; change this card to Defense Position, and if you do, that target loses 800 ATK until the end of this turn. |
During your opponent's Main Phase or Battle Phase: You can Special Summon 1 non-Tuner monster from your hand, but it has its effects negated (if any), and if you do, immediately after this effect resolves, Synchro Summon 1 Machine-Type Synchro Monster using only that monster and this card (this is a Quick Effect). You can only use this effect of "Crystron Quan" once per turn. |
0.0 |
You can Tribute this card while "Neo Space" is on the field to Special Summon 1 "Neo-Spacian Dark Panther" from your hand or Deck. |
When your opponent Special Summons a monster(s): Destroy it, then you can banish 5 Zombie monsters from your GY, and if you do, Special Summon 1 Level 7 or higher Zombie monster from your hand or Deck. |
0.25 |
You can target 1 Dragon monster you control; it gains ATK/DEF equal to the total Link Rating of the Link Monsters currently on the field x 100, until the end of the opponent's turn. You can only use this effect of "Guardragon Shield" once per turn. Once per turn, if exactly 1 Dragon monster you control would be destroyed by battle or card effect, you can send 1 Normal Monster from your hand or Deck to the GY instead. |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 5warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_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: 1.0num_train_epochs: 5max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_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: Truefp16_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: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.1786 | 100 | 3.8917 | 3.7898 |
| 0.3571 | 200 | 3.7289 | 3.7576 |
| 0.5357 | 300 | 3.6719 | 3.7211 |
| 0.7143 | 400 | 3.6294 | 3.6751 |
| 0.8929 | 500 | 3.5188 | 3.6291 |
| 1.0714 | 600 | 3.6794 | 3.5768 |
| 1.25 | 700 | 3.4962 | 3.5798 |
| 1.4286 | 800 | 3.4325 | 3.6149 |
| 1.6071 | 900 | 3.3956 | 3.6151 |
| 1.7857 | 1000 | 3.2907 | 3.7533 |
| 1.9643 | 1100 | 3.3685 | 3.5106 |
| 2.1429 | 1200 | 3.502 | 3.4844 |
| 2.3214 | 1300 | 3.3796 | 3.6363 |
| 2.5 | 1400 | 3.2383 | 3.5744 |
| 2.6786 | 1500 | 3.1346 | 3.6568 |
| 2.8571 | 1600 | 3.1808 | 3.6278 |
| 3.0357 | 1700 | 3.3241 | 3.4786 |
| 3.2143 | 1800 | 3.2864 | 3.4705 |
| 3.3929 | 1900 | 3.2056 | 3.5290 |
| 3.5714 | 2000 | 3.1519 | 3.6228 |
| 3.75 | 2100 | 3.0889 | 3.5919 |
| 3.9286 | 2200 | 2.9385 | 3.6148 |
| 4.1071 | 2300 | 3.2051 | 3.5180 |
| 4.2857 | 2400 | 3.2581 | 3.5216 |
| 4.4643 | 2500 | 3.0765 | 3.5968 |
| 4.6429 | 2600 | 2.9497 | 3.6496 |
| 4.8214 | 2700 | 2.8502 | 3.6804 |
| 5.0 | 2800 | 3.1919 | 3.6668 |
@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",
}
@online{kexuefm-8847,
title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
author={Su Jianlin},
year={2022},
month={Jan},
url={https://kexue.fm/archives/8847},
}
Base model
prajjwal1/bert-tiny
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Tien09/tiny_bert_ft_sim_score") sentences = [ "When this card is Normal Summoned: You can Special Summon 1 \"Crashbug X\" from your Deck. You must control a face-up \"Crashbug Z\" to activate and to resolve this effect.", "You can remove from play 1 Tuner monster in your GY to Special Summon this card from your hand.", "This spirit emerges from the mystic lamp and obeys the wishes of its summoner.", "When your opponent activates a monster effect, while you control a \"Beetrooper\" monster: Negate the activation, and if you do, destroy it. During your End Phase, if this card is in your GY and you control an Insect monster with 3000 or more ATK: You can banish 1 Insect monster from your GY; Set this card. You can only use 1 \"Beetrooper Fly & Sting\" effect per turn, and only once that turn." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4]