MTG Embeddings v2
Collection
5 items • Updated
How to use philipp-zettl/all-MiniLM-L6-v2-mtg-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("philipp-zettl/all-MiniLM-L6-v2-mtg-v2")
sentences = [
"instant",
"Title: Flash Foliage\nCost: {2}{G}\nColors: G\nType: Instant\nDesc: Cast this spell only during combat after blockers are declared.\nCreate a 1/1 green Saproling creature token that's blocking target creature attacking you.\nDraw a card.",
"Title: Security Rhox\nCost: {2}{R}{G}\nColors: G, R\nType: Creature — Rhino Warrior\nDesc: You may pay {R}{G} rather than pay this spell's mana cost. Spend only mana produced by Treasures to cast it this way.",
"Title: Circle of Protection: Red\nCost: {1}{W}\nColors: W\nType: Enchantment\nDesc: {1}: The next time a red source of your choice would deal damage to you this turn, prevent that damage."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2. It maps sentences & paragraphs to a 384-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': 384, 'pooling_mode': 'mean', '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("philipp-zettl/all-MiniLM-L6-v2-mtg-v2")
# Run inference
sentences = [
'{4}, {t}, sacrifice this artifact: target player discards a card for each charge counter on this artifact',
'Title: Shrine of Limitless Power\nCost: {3}\nType: Artifact\nDesc: At the beginning of your upkeep and whenever you cast a black spell, put a charge counter on this artifact.\n{4}, {T}, Sacrifice this artifact: Target player discards a card for each charge counter on this artifact.',
'Title: Dawn Charm\nCost: {1}{W}\nColors: W\nType: Instant\nDesc: Choose one —\n• Prevent all combat damage that would be dealt this turn.\n• Regenerate target creature.\n• Counter target spell that targets you.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.6342, -0.0303],
# [ 0.6342, 1.0000, -0.0325],
# [-0.0303, -0.0325, 1.0000]])
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
colos yearling |
Title: Colos Yearling |
creature — zombie wizard |
Title: Prophet of the Scarab |
{w}, {t}: target permanent you control gains protection from instant spells and from sorcery spells until end of turn |
Title: Devoted Caretaker |
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: 96fp16: Trueper_device_eval_batch_size: 96multi_dataset_batch_sampler: round_robinper_device_train_batch_size: 96num_train_epochs: 3max_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: Truebf16_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: 96prediction_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_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0225 | 500 | 0.8076 |
| 0.0450 | 1000 | 0.4803 |
| 0.0675 | 1500 | 0.4223 |
| 0.0900 | 2000 | 0.4065 |
| 0.1125 | 2500 | 0.3884 |
| 0.1350 | 3000 | 0.3720 |
| 0.1575 | 3500 | 0.3705 |
| 0.1800 | 4000 | 0.3654 |
| 0.2025 | 4500 | 0.3555 |
| 0.2250 | 5000 | 0.3534 |
| 0.2475 | 5500 | 0.3514 |
| 0.2701 | 6000 | 0.3571 |
| 0.2926 | 6500 | 0.3438 |
| 0.3151 | 7000 | 0.3496 |
| 0.3376 | 7500 | 0.3458 |
| 0.3601 | 8000 | 0.3406 |
| 0.3826 | 8500 | 0.3406 |
| 0.4051 | 9000 | 0.3350 |
| 0.4276 | 9500 | 0.3376 |
| 0.4501 | 10000 | 0.3329 |
| 0.4726 | 10500 | 0.3311 |
| 0.4951 | 11000 | 0.3305 |
| 0.5176 | 11500 | 0.3336 |
| 0.5401 | 12000 | 0.3306 |
| 0.5626 | 12500 | 0.3239 |
| 0.5851 | 13000 | 0.3265 |
| 0.6076 | 13500 | 0.3172 |
| 0.6301 | 14000 | 0.3240 |
| 0.6526 | 14500 | 0.3187 |
| 0.6751 | 15000 | 0.3234 |
| 0.6976 | 15500 | 0.3231 |
| 0.7201 | 16000 | 0.3206 |
| 0.7426 | 16500 | 0.3191 |
| 0.7651 | 17000 | 0.3193 |
| 0.7876 | 17500 | 0.3196 |
| 0.8102 | 18000 | 0.3187 |
| 0.8327 | 18500 | 0.3124 |
| 0.8552 | 19000 | 0.3133 |
| 0.8777 | 19500 | 0.3183 |
| 0.9002 | 20000 | 0.3076 |
| 0.9227 | 20500 | 0.3204 |
| 0.9452 | 21000 | 0.3188 |
| 0.9677 | 21500 | 0.3196 |
| 0.9902 | 22000 | 0.3094 |
| 1.0127 | 22500 | 0.3077 |
| 1.0352 | 23000 | 0.3112 |
| 1.0577 | 23500 | 0.3058 |
| 1.0802 | 24000 | 0.3103 |
| 1.1027 | 24500 | 0.3123 |
| 1.1252 | 25000 | 0.3085 |
| 1.1477 | 25500 | 0.3046 |
| 1.1702 | 26000 | 0.3071 |
| 1.1927 | 26500 | 0.3074 |
| 1.2152 | 27000 | 0.3134 |
| 1.2377 | 27500 | 0.3059 |
| 1.2602 | 28000 | 0.3101 |
| 1.2827 | 28500 | 0.3089 |
| 1.3052 | 29000 | 0.3027 |
| 1.3278 | 29500 | 0.3125 |
| 1.3503 | 30000 | 0.3024 |
| 1.3728 | 30500 | 0.3034 |
| 1.3953 | 31000 | 0.3031 |
| 1.4178 | 31500 | 0.3080 |
| 1.4403 | 32000 | 0.3095 |
| 1.4628 | 32500 | 0.3044 |
| 1.4853 | 33000 | 0.3012 |
| 1.5078 | 33500 | 0.3113 |
| 1.5303 | 34000 | 0.3023 |
| 1.5528 | 34500 | 0.3117 |
| 1.5753 | 35000 | 0.3078 |
| 1.5978 | 35500 | 0.3130 |
| 1.6203 | 36000 | 0.3103 |
| 1.6428 | 36500 | 0.3023 |
| 1.6653 | 37000 | 0.2976 |
| 1.6878 | 37500 | 0.3018 |
| 1.7103 | 38000 | 0.3040 |
| 1.7328 | 38500 | 0.2962 |
| 1.7553 | 39000 | 0.3036 |
| 1.7778 | 39500 | 0.3040 |
| 1.8003 | 40000 | 0.3062 |
| 1.8228 | 40500 | 0.3040 |
| 1.8454 | 41000 | 0.3046 |
| 1.8679 | 41500 | 0.2976 |
| 1.8904 | 42000 | 0.3014 |
| 1.9129 | 42500 | 0.3041 |
| 1.9354 | 43000 | 0.3035 |
| 1.9579 | 43500 | 0.3001 |
| 1.9804 | 44000 | 0.3012 |
| 2.0029 | 44500 | 0.3000 |
| 2.0254 | 45000 | 0.3061 |
| 2.0479 | 45500 | 0.3035 |
| 2.0704 | 46000 | 0.2972 |
| 2.0929 | 46500 | 0.3001 |
| 2.1154 | 47000 | 0.2968 |
| 2.1379 | 47500 | 0.2978 |
| 2.1604 | 48000 | 0.3052 |
| 2.1829 | 48500 | 0.2998 |
| 2.2054 | 49000 | 0.2950 |
| 2.2279 | 49500 | 0.3018 |
| 2.2504 | 50000 | 0.3004 |
| 2.2729 | 50500 | 0.2934 |
| 2.2954 | 51000 | 0.2969 |
| 2.3179 | 51500 | 0.2968 |
| 2.3404 | 52000 | 0.3023 |
| 2.3629 | 52500 | 0.2974 |
| 2.3855 | 53000 | 0.3037 |
| 2.4080 | 53500 | 0.3007 |
| 2.4305 | 54000 | 0.2969 |
| 2.4530 | 54500 | 0.3055 |
| 2.4755 | 55000 | 0.2938 |
| 2.4980 | 55500 | 0.2989 |
| 2.5205 | 56000 | 0.2913 |
| 2.5430 | 56500 | 0.2969 |
| 2.5655 | 57000 | 0.3012 |
| 2.5880 | 57500 | 0.2974 |
| 2.6105 | 58000 | 0.2937 |
| 2.6330 | 58500 | 0.2917 |
| 2.6555 | 59000 | 0.2998 |
| 2.6780 | 59500 | 0.2915 |
| 2.7005 | 60000 | 0.2924 |
| 2.7230 | 60500 | 0.2926 |
| 2.7455 | 61000 | 0.2959 |
| 2.7680 | 61500 | 0.2950 |
| 2.7905 | 62000 | 0.2950 |
| 2.8130 | 62500 | 0.2972 |
| 2.8355 | 63000 | 0.2955 |
| 2.8580 | 63500 | 0.2934 |
| 2.8805 | 64000 | 0.2962 |
| 2.9031 | 64500 | 0.2941 |
| 2.9256 | 65000 | 0.2910 |
| 2.9481 | 65500 | 0.2941 |
| 2.9706 | 66000 | 0.2893 |
| 2.9931 | 66500 | 0.2953 |
@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
nreimers/MiniLM-L6-H384-uncased