pier97 commited on
Commit
b40ce4b
·
verified ·
1 Parent(s): 9970868

Publish v3 ONNX model

Browse files
Files changed (39) hide show
  1. .gitignore +0 -18
  2. README.md +75 -58
  3. example.py +0 -36
  4. featurizer/__init__.py +0 -3
  5. featurizer/assets/cards.json +0 -0
  6. featurizer/assets/patterns/abilities.json +0 -65
  7. featurizer/assets/patterns/card_advantage.json +0 -35
  8. featurizer/assets/patterns/conditional.json +0 -75
  9. featurizer/assets/patterns/cost_wording.json +0 -40
  10. featurizer/assets/patterns/counters_synergy.json +0 -25
  11. featurizer/assets/patterns/counters_typed.json +0 -20
  12. featurizer/assets/patterns/effects_extra.json +0 -155
  13. featurizer/assets/patterns/enchantment_equipment.json +0 -40
  14. featurizer/assets/patterns/evasion_combat.json +0 -35
  15. featurizer/assets/patterns/graveyard.json +0 -40
  16. featurizer/assets/patterns/keywords_set.json +0 -25
  17. featurizer/assets/patterns/mana_ramp.json +0 -45
  18. featurizer/assets/patterns/mechanics.json +0 -30
  19. featurizer/assets/patterns/modal_misc.json +0 -40
  20. featurizer/assets/patterns/players_targets.json +0 -35
  21. featurizer/assets/patterns/protection.json +0 -15
  22. featurizer/assets/patterns/quantitative.json +0 -110
  23. featurizer/assets/patterns/removal.json +0 -80
  24. featurizer/assets/patterns/resource_payoff.json +0 -60
  25. featurizer/assets/patterns/set_mechanics_extra.json +0 -10
  26. featurizer/assets/patterns/set_mechanics_extra2.json +0 -15
  27. featurizer/assets/patterns/spells_matter.json +0 -25
  28. featurizer/assets/patterns/tokens_board.json +0 -30
  29. featurizer/assets/patterns/tokens_named.json +0 -15
  30. featurizer/assets/patterns/triggers.json +0 -55
  31. featurizer/assets/patterns/typal.json +0 -15
  32. featurizer/assets/patterns/vehicles_types.json +0 -35
  33. featurizer/assets/sbert_pca.joblib +0 -3
  34. featurizer/featurizer.py +0 -178
  35. inference.py +0 -116
  36. model.py +0 -53
  37. model/mtgda-encdec.ckpt +0 -3
  38. requirements.txt +0 -5
  39. static/seen-vs-unseen-acc-graph.png +0 -0
.gitignore DELETED
@@ -1,18 +0,0 @@
1
- /*
2
- !/.gitignore
3
- !/.gitattributes
4
- !/README.md
5
- !/example.py
6
- !/inference.py
7
- !/model.py
8
- !/requirements.txt
9
- !/static/
10
- !/featurizer/
11
- !/model/
12
-
13
- *.onnx
14
- *.pt
15
- *.pth
16
-
17
- __pycache__/
18
- *.py[cod]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,78 +1,95 @@
1
- # MTG Draft Assistant
2
-
3
- Given the cards in a booster pack and the cards you have already picked, this model
4
- ranks which card to take next. It generalizes to **unseen sets**: a card it has never
5
- seen still gets a vector from its features for zero-shot inference.
6
-
7
- The model was trained on draft data from 30 different sets from 17Lands, keeping only drafts from players who achieved a 55% win rate, reached at least Platinum rank, and scored at least 5 wins with the drafted deck. It was validated on zero-shot inference using the latest Secrets of Strixhaven (SOS) set.
8
-
9
- ## Metrics
10
-
11
- Pick accuracy by how many cards are left in the pack, on a **seen** set (in training)
12
- and on the **unseen** SOS set (zero-shot):
13
-
14
- ![seen vs unseen accuracy](static/seen-vs-unseen-acc-graph.png)
15
-
16
- ## How it works
17
-
18
- - **Featurizer** (`featurizer/`) - turns a card into a 255-d vector
19
- (PCA of SBERT text embedding + numeric features + 207 regex flags). The card type is
20
- prepended to the oracle text before SBERT. Assets: `sbert_pca.joblib`, `patterns/`,
21
- `cards.json`.
22
- - **Model** (`model.py`) - 3.67M params encoder-decoder transformer: the encoder pools the pack
23
- history, the decoder cross-attends the picked-card history (your current deck), and a head
24
- scores each candidate.
25
 
26
  ## Install
27
 
28
  ```bash
29
- pip install -r requirements.txt
30
  ```
31
 
32
- The SBERT model (`all-MiniLM-L6-v2`) is downloaded automatically on first use.
33
-
34
- ## Usage
35
-
36
- ### Statefull API
37
 
38
  ```python
39
- from inference import MtgDraftAssistant
40
 
41
- asst = MtgDraftAssistant.from_pretrained()
 
42
 
43
- d = asst.new_draft() # fresh new stateful draft context
44
- d.see(["Lightning Bolt", "Llanowar Elves", "Cancel"]) # see pack 1 (inference)
45
- d.pick("Lightning Bolt") # take a card
 
 
46
 
47
- for name, prob in d.see(["Shock", "Giant Growth", "Murder"]):
48
- print(f"{prob:.1%} {name}")
49
  ```
50
 
51
- ### Stateless API
52
 
53
  ```python
54
- asst.rank(
55
- pack_history=[ # one pack per step, current pack last
56
- ["Lightning Bolt", "Cancel"],
57
- ["Shock", "Giant Growth"],
58
- ],
59
- pool=["Lightning Bolt"], # cards already picked
 
 
 
 
 
 
 
60
  )
61
- # -> [("Shock", 0.94), ("Giant Growth", 0.06)]
62
  ```
63
 
64
- ### Unseen / custom cards
 
65
 
66
- Cards are passed as **names** (resolved via the bundled card database) or as
67
- **Scryfall-style dicts** (used directly works for custom, spoiler, or yet to be released cards):
68
 
69
- ```python
70
- custom = {
71
- "name": "Made-Up Card",
72
- "type_line": "Creature - Goblin",
73
- "mana_cost": "{1}{R}",
74
- "power": "3", "toughness": "1",
75
- "oracle_text": "Haste. When it enters, it deals 2 damage to any target.",
76
- }
77
- asst.rank([[custom, "Giant Growth", "Cancel"]], pool=[])
78
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: onnxruntime
3
+ language:
4
+ - en
5
+ tags:
6
+ - onnx
7
+ - magic-the-gathering
8
+ - draft
9
+ - ranking
10
+ - zero-shot
11
+ ---
12
+
13
+ # MTG Draft Assistant v3
14
+
15
+ MTG Draft Assistant ranks the cards in a booster pack using the cards selected
16
+ earlier in the draft. The release contains the ONNX card encoder, the ONNX draft
17
+ model, tokenizer files, model configuration, and a card catalog for name-based
18
+ inference. The Python package supplies the deterministic mechanic featurizer.
19
+
20
+ The source code and Python API are available on
21
+ [GitHub](https://github.com/pier-tmp/mtgda).
 
 
 
22
 
23
  ## Install
24
 
25
  ```bash
26
+ pip install "mtgda @ git+https://github.com/pier-tmp/mtgda.git"
27
  ```
28
 
29
+ ## Stateful API
 
 
 
 
30
 
31
  ```python
32
+ from mtgda import MtgDraftAssistant
33
 
34
+ assistant = MtgDraftAssistant.from_pretrained("pier97/mtgda")
35
+ draft = assistant.new_draft()
36
 
37
+ recommendations = draft.see([
38
+ "Lightning Bolt",
39
+ "Llanowar Elves",
40
+ "Cancel",
41
+ ])
42
 
43
+ draft.pick("Lightning Bolt")
 
44
  ```
45
 
46
+ ## Stateless API
47
 
48
  ```python
49
+ from mtgda import DraftStep, MtgDraftAssistant
50
+
51
+ assistant = MtgDraftAssistant.from_pretrained("pier97/mtgda")
52
+ history = [
53
+ DraftStep(
54
+ pack=("Lightning Bolt", "Llanowar Elves", "Cancel"),
55
+ pick="Lightning Bolt",
56
+ )
57
+ ]
58
+
59
+ recommendations = assistant.rank(
60
+ history,
61
+ ["Shock", "Giant Growth", "Murder"],
62
  )
 
63
  ```
64
 
65
+ Card names may be replaced with Scryfall-style dictionaries for custom or newly
66
+ released cards.
67
 
68
+ ## Metrics
 
69
 
70
+ The checkpoint was selected by validation NLL. SOS and MSH were excluded from
71
+ training and checkpoint selection.
72
+
73
+ | Split | Top-1 | Top-3 | NLL |
74
+ |---|---:|---:|---:|
75
+ | Known test | 68.26% | 95.17% | 0.8184 |
76
+ | SOS holdout | 50.49% | 85.41% | 1.3349 |
77
+ | MSH holdout | 51.50% | 85.95% | 1.2839 |
78
+
79
+ ## Architecture
80
+
81
+ The card representation combines a 320-dimensional MPNet text projection, 16
82
+ numeric features, and 207 deterministic mechanic flags. A two-layer causal
83
+ encoder-decoder transformer with 320-dimensional hidden states and eight
84
+ attention heads ranks the candidates in the current pack.
85
+
86
+ The exported graphs use ONNX opset 18. Validation against the PyTorch checkpoint
87
+ produced identical API ranking, with maximum absolute errors of `1.01e-5` for
88
+ logits and `7.67e-7` for probabilities.
89
+
90
+ ## Limits
91
+
92
+ The model supports up to 45 draft steps and 15 cards per pack. It predicts the
93
+ historical choices represented in its training data and does not guarantee an
94
+ optimal pick or account for private information unavailable in the supplied
95
+ draft history.
example.py DELETED
@@ -1,36 +0,0 @@
1
- from pathlib import Path
2
- import sys
3
-
4
- sys.path.insert(0, str(Path(__file__).parent))
5
- from inference import MtgDraftAssistant
6
-
7
- asst = MtgDraftAssistant.from_pretrained()
8
-
9
- # Stateless
10
- pack_history = [
11
- ["Lightning Bolt", "Llanowar Elves", "Cancel"],
12
- ["Shock", "Giant Growth", "Murder", "Consider"],
13
- ]
14
- pool = ["Lightning Bolt"]
15
- for name, prob in asst.rank(pack_history, pool):
16
- print(f" {prob:6.1%} {name}")
17
-
18
- # Stateful
19
- d = asst.new_draft()
20
- d.see(["Lightning Bolt", "Llanowar Elves", "Cancel"])
21
- d.pick("Lightning Bolt")
22
- print("pack 2 ranking:")
23
- for name, prob in d.see(["Shock", "Giant Growth", "Murder", "Consider"]):
24
- print(f" {prob:6.1%} {name}")
25
-
26
- # Custom cards
27
- custom = {
28
- "name": "Made-Up Firebrand",
29
- "type_line": "Creature — Elemental",
30
- "mana_cost": "{1}{R}",
31
- "power": "3", "toughness": "1",
32
- "oracle_text": "Haste. When Made-Up Firebrand enters, it deals 2 damage to any target.",
33
- }
34
- pack = [custom, "Giant Growth", "Cancel"]
35
- for name, prob in asst.rank([pack], pool=[]):
36
- print(f" {prob:6.1%} {name}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from .featurizer import CardFeaturizer
2
-
3
- __all__ = ["CardFeaturizer"]
 
 
 
 
featurizer/assets/cards.json DELETED
The diff for this file is too large to render. See raw diff
 
featurizer/assets/patterns/abilities.json DELETED
@@ -1,65 +0,0 @@
1
- {
2
- "category": "abilities",
3
- "patterns": [
4
- {
5
- "name": "tap_ability",
6
- "regex": "\\{t\\}:",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "mana_ability",
11
- "regex": "\\{t\\}: add",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "activated_mana",
16
- "regex": "\\{\\d+\\}.{0,4}:",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "sac_outlet",
21
- "regex": "sacrifice (a|another|two|three|\\w+) .{0,20}:",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "may_pay",
26
- "regex": "you may pay",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "kicker",
31
- "regex": "kicker",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "convoke",
36
- "regex": "convoke",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "x_spell",
41
- "regex": "\\{x\\}",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "cost_reduction",
46
- "regex": "costs? \\{?\\d?\\}? ?less",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "cost_increase",
51
- "regex": "costs? \\{?\\d?\\}? ?more",
52
- "kind": "flag"
53
- },
54
- {
55
- "name": "enters_tapped",
56
- "regex": "enters .{0,15}tapped",
57
- "kind": "flag"
58
- },
59
- {
60
- "name": "grant_keyword",
61
- "regex": "you control (gain|have) .{0,25}(flying|trample|lifelink|deathtouch|haste|vigilance|menace|first strike|double strike|hexproof|indestructible|reach|flash|protection|ward|prowess|defender)",
62
- "kind": "flag"
63
- }
64
- ]
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/card_advantage.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "category": "card_advantage",
3
- "patterns": [
4
- {
5
- "name": "search_library",
6
- "regex": "search your library",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "reveal",
11
- "regex": "reveal",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "look_at_top",
16
- "regex": "look at the top",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "impulse_draw",
21
- "regex": "exile the top .{0,30}may (play|cast)",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "tutor_to_hand",
26
- "regex": "search your library for a .{0,30}(card|creature).{0,30}hand",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "draw_then_discard",
31
- "regex": "draw .{0,15}then discard",
32
- "kind": "flag"
33
- }
34
- ]
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/conditional.json DELETED
@@ -1,75 +0,0 @@
1
- {
2
- "category": "conditional",
3
- "patterns": [
4
- {
5
- "name": "as_long_as",
6
- "regex": "as long as",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "if_you_control_n",
11
- "regex": "if you control \\w+ or more",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "conditional_etb",
16
- "regex": "enters,? if",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "gained_life_turn",
21
- "regex": "gained life this turn",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "damage_this_turn",
26
- "regex": "dealt damage this turn",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "if_opponent_controls",
31
- "regex": "if an opponent controls",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "tapped_creature_check",
36
- "regex": "tapped creatures? you control",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "if_you_have_life",
41
- "regex": "you have \\d+ or (more|less) life|life total",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "cast_from_exile",
46
- "regex": "cast .{0,15}from exile",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "spent_colors_cast",
51
- "regex": "colors? .{0,10}spent to cast",
52
- "kind": "flag"
53
- },
54
- {
55
- "name": "power_matters",
56
- "regex": "equal to .{0,10}power|where x is .{0,10}power",
57
- "kind": "flag"
58
- },
59
- {
60
- "name": "toughness_matters",
61
- "regex": "equal to .{0,10}toughness|rather than .{0,10}power",
62
- "kind": "flag"
63
- },
64
- {
65
- "name": "mana_spent_scales",
66
- "regex": "equal to .{0,15}mana spent",
67
- "kind": "flag"
68
- },
69
- {
70
- "name": "different_powers",
71
- "regex": "creatures with different powers",
72
- "kind": "flag"
73
- }
74
- ]
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/cost_wording.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "category": "cost_wording",
3
- "patterns": [
4
- {
5
- "name": "pay_n_life",
6
- "regex": "pay \\{?\\d+\\}? life",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "remove_counter",
11
- "regex": "remove a .{0,15}counter",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "whenever_player_casts",
16
- "regex": "whenever a player casts",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "whenever_opponent",
21
- "regex": "whenever an opponent",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "you_may_reveal",
26
- "regex": "you may reveal",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "start_your_engines",
31
- "regex": "start your engines",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "max_speed",
36
- "regex": "max speed|your speed",
37
- "kind": "flag"
38
- }
39
- ]
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/counters_synergy.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "category": "counters_synergy",
3
- "patterns": [
4
- {
5
- "name": "plus_counter_ref",
6
- "regex": "\\+1/\\+1 counter",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "minus_counter_ref",
11
- "regex": "-1/-1 counter",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "proliferate",
16
- "regex": "proliferate",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "counter_on_matters",
21
- "regex": "with a .{0,15}counter on",
22
- "kind": "flag"
23
- }
24
- ]
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/counters_typed.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "category": "counters_typed",
3
- "patterns": [
4
- {
5
- "name": "stun_counter",
6
- "regex": "stun counter",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "poison_counter",
11
- "regex": "poison counter",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "saga_lore",
16
- "regex": "lore counter",
17
- "kind": "flag"
18
- }
19
- ]
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/effects_extra.json DELETED
@@ -1,155 +0,0 @@
1
- {
2
- "category": "effects_extra",
3
- "patterns": [
4
- {
5
- "name": "damage_each_opponent",
6
- "regex": "damage to each opponent",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "damage_each_creature",
11
- "regex": "damage to each creature",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "each_opponent_loses",
16
- "regex": "each opponent loses",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "where_x_is",
21
- "regex": "where x is",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "bottom_of_library",
26
- "regex": "bottom of .{0,5}library",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "top_of_library_put",
31
- "regex": "on top of .{0,5}library",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "shuffle_into_library",
36
- "regex": "shuffle .{0,30}into .{0,15}library",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "additional_cost",
41
- "regex": "as an additional cost",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "indestructible_until",
46
- "regex": "indestructible until",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "cant_block_this_turn",
51
- "regex": "creatures? can'?t block",
52
- "kind": "flag"
53
- },
54
- {
55
- "name": "unblocked_attacker",
56
- "regex": "unblocked attacker",
57
- "kind": "flag"
58
- },
59
- {
60
- "name": "damage_prevented_no",
61
- "regex": "damage can'?t be prevented",
62
- "kind": "flag"
63
- },
64
- {
65
- "name": "cant_cast",
66
- "regex": "can'?t cast",
67
- "kind": "flag"
68
- },
69
- {
70
- "name": "flicker_blink",
71
- "regex": "exile .{0,40}return .{0,20}battlefield",
72
- "kind": "flag"
73
- },
74
- {
75
- "name": "phase_out",
76
- "regex": "phases? out",
77
- "kind": "flag"
78
- },
79
- {
80
- "name": "an_opponent_loses_game",
81
- "regex": "loses the game",
82
- "kind": "flag"
83
- },
84
- {
85
- "name": "can_block_only",
86
- "regex": "can block only",
87
- "kind": "flag"
88
- },
89
- {
90
- "name": "hexproof_from_color",
91
- "regex": "hexproof from",
92
- "kind": "flag"
93
- },
94
- {
95
- "name": "double_counters",
96
- "regex": "twice that many|double .{0,15}counter",
97
- "kind": "flag"
98
- },
99
- {
100
- "name": "double_power",
101
- "regex": "double .{0,15}power",
102
- "kind": "flag"
103
- },
104
- {
105
- "name": "play_from_exile_turn",
106
- "regex": "may play .{0,20}exiled with",
107
- "kind": "flag"
108
- },
109
- {
110
- "name": "becomes_artifact",
111
- "regex": "becomes? an? artifact",
112
- "kind": "flag"
113
- },
114
- {
115
- "name": "land_becomes_creature",
116
- "regex": "becomes a \\d+/\\d+ .{0,25}creature",
117
- "kind": "flag"
118
- },
119
- {
120
- "name": "sacrifice_nonland",
121
- "regex": "sacrifice a nonland permanent",
122
- "kind": "flag"
123
- },
124
- {
125
- "name": "loses_card_types",
126
- "regex": "loses all .{0,10}(card )?types",
127
- "kind": "flag"
128
- },
129
- {
130
- "name": "greatest_power_among",
131
- "regex": "greatest power among",
132
- "kind": "flag"
133
- },
134
- {
135
- "name": "excess_damage",
136
- "regex": "excess damage",
137
- "kind": "flag"
138
- },
139
- {
140
- "name": "force_block_target",
141
- "regex": "must be blocked|all creatures? able to block|able to block .{0,20}(do so|does so|must)",
142
- "kind": "flag"
143
- },
144
- {
145
- "name": "opp_discards",
146
- "regex": "(each opponent|target player|that player|opponents?) .{0,15}discards?",
147
- "kind": "flag"
148
- },
149
- {
150
- "name": "opp_sacrifices",
151
- "regex": "(each opponent|target player|that player|opponents?) .{0,15}sacrifices?",
152
- "kind": "flag"
153
- }
154
- ]
155
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/enchantment_equipment.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "category": "enchantment_equipment",
3
- "patterns": [
4
- {
5
- "name": "equip_cost",
6
- "regex": "equip \\{?\\d",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "equipped_bonus",
11
- "regex": "equipped creature (gets|has)",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "enchant_creature",
16
- "regex": "enchant creature",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "enchant_perm",
21
- "regex": "enchant (artifact|land|player|permanent)",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "enchanted_changes",
26
- "regex": "enchanted (creature|permanent|land) (gets|has|is|can|doesn)",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "bestow",
31
- "regex": "bestow",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "aura_you_control",
36
- "regex": "auras? you control",
37
- "kind": "flag"
38
- }
39
- ]
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/evasion_combat.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "category": "evasion_combat",
3
- "patterns": [
4
- {
5
- "name": "cant_be_blocked",
6
- "regex": "can'?t be blocked",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "cant_block",
11
- "regex": "can'?t block",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "cant_attack",
16
- "regex": "can'?t attack",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "extra_combat",
21
- "regex": "additional combat phase",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "islandwalk",
26
- "regex": "\\w+walk",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "attacks_alone",
31
- "regex": "attacks alone",
32
- "kind": "flag"
33
- }
34
- ]
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/graveyard.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "category": "graveyard",
3
- "patterns": [
4
- {
5
- "name": "graveyard_matters",
6
- "regex": "(from your graveyard|cards? in .{0,12}graveyard|in your graveyard)",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "return_from_gy",
11
- "regex": "return .{0,40}from .{0,15}graveyard",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "exile_from_gy",
16
- "regex": "exile .{0,40}from .{0,15}graveyard",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "self_recursion",
21
- "regex": "return (this|~|it) .{0,20}from .{0,10}graveyard",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "flashback",
26
- "regex": "flashback",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "mill_self",
31
- "regex": "mill .{0,15}yourself|put .{0,20}into your graveyard",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "unearth",
36
- "regex": "unearth",
37
- "kind": "flag"
38
- }
39
- ]
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/keywords_set.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "category": "keywords_set",
3
- "patterns": [
4
- {
5
- "name": "transform_dfc",
6
- "regex": "transform|daybound|nightbound",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "crew",
11
- "regex": "crew (\\d+)",
12
- "kind": "quant"
13
- },
14
- {
15
- "name": "cycling_typed",
16
- "regex": "\\w*cycling",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "earthbend",
21
- "regex": "earthbend|airbend|firebending|waterbend",
22
- "kind": "flag"
23
- }
24
- ]
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/mana_ramp.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "category": "mana_ramp",
3
- "patterns": [
4
- {
5
- "name": "ramp_land",
6
- "regex": "search your library for a .{0,20}land",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "add_one_any",
11
- "regex": "add one mana of any",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "energy",
16
- "regex": "\\{e\\}|energy counter",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "ritual_mana",
21
- "regex": "add \\{[wubrgc]\\}\\{[wubrgc]\\}",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "extra_land_drop",
26
- "regex": "play an additional land",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "mana_any_color",
31
- "regex": "mana of any color",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "cost_alt",
36
- "regex": "rather than pay .{0,15}mana cost",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "cost_less_per",
41
- "regex": "less to cast for each",
42
- "kind": "flag"
43
- }
44
- ]
45
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/mechanics.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "category": "mechanics",
3
- "patterns": [
4
- {
5
- "name": "face_down_up",
6
- "regex": "face (down|up)",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "once_per_turn",
11
- "regex": "only once each turn",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "gain_control",
16
- "regex": "gain control of",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "ward_cost",
21
- "regex": "ward \\{?\\d",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "cant_be_countered",
26
- "regex": "can'?t be countered",
27
- "kind": "flag"
28
- }
29
- ]
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/modal_misc.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "category": "modal_misc",
3
- "patterns": [
4
- {
5
- "name": "choose_one",
6
- "regex": "choose one",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "modal",
11
- "regex": "choose (one|two|up to)",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "extra_turn",
16
- "regex": "take an extra turn",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "copy",
21
- "regex": "create a (token that's a )?copy",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "untap",
26
- "regex": "untap",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "explore",
31
- "regex": "explore",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "investigate",
36
- "regex": "investigate",
37
- "kind": "flag"
38
- }
39
- ]
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/players_targets.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "category": "players_targets",
3
- "patterns": [
4
- {
5
- "name": "each_opponent",
6
- "regex": "each opponent",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "each_player",
11
- "regex": "each player",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "target_player",
16
- "regex": "target player",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "you_control_matters",
21
- "regex": "creatures you control",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "target_opponent",
26
- "regex": "target opponent",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "each_creature",
31
- "regex": "each creature",
32
- "kind": "flag"
33
- }
34
- ]
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/protection.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "category": "protection",
3
- "patterns": [
4
- {
5
- "name": "regenerate",
6
- "regex": "regenerate",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "prevent_damage",
11
- "regex": "prevent .{0,20}damage",
12
- "kind": "flag"
13
- }
14
- ]
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/quantitative.json DELETED
@@ -1,110 +0,0 @@
1
- {
2
- "category": "quantitative",
3
- "patterns": [
4
- {
5
- "name": "draw_n",
6
- "regex": "draw .{0,15}cards?",
7
- "kind": "quant"
8
- },
9
- {
10
- "name": "damage_n",
11
- "regex": "deals? .{0,20}damage",
12
- "kind": "quant"
13
- },
14
- {
15
- "name": "pump_power",
16
- "regex": "\\+(\\d+)/\\+\\d+",
17
- "kind": "quant"
18
- },
19
- {
20
- "name": "shrink_power",
21
- "regex": "-(\\d+)/-\\d+",
22
- "kind": "quant"
23
- },
24
- {
25
- "name": "gain_life_n",
26
- "regex": "gains? .{0,15}life",
27
- "kind": "quant"
28
- },
29
- {
30
- "name": "lose_life_n",
31
- "regex": "loses? .{0,15}life",
32
- "kind": "quant"
33
- },
34
- {
35
- "name": "create_tokens_n",
36
- "regex": "creates? .{0,40}token",
37
- "kind": "quant"
38
- },
39
- {
40
- "name": "counters_n",
41
- "regex": "(\\w+) \\+1/\\+1 counters?",
42
- "kind": "quant"
43
- },
44
- {
45
- "name": "minus_counters_n",
46
- "regex": "(\\w+) -1/-1 counters?",
47
- "kind": "quant"
48
- },
49
- {
50
- "name": "mill_n",
51
- "regex": "mill (\\w+)",
52
- "kind": "quant"
53
- },
54
- {
55
- "name": "scry_n",
56
- "regex": "scry (\\w+)",
57
- "kind": "quant"
58
- },
59
- {
60
- "name": "surveil_n",
61
- "regex": "surveil (\\w+)",
62
- "kind": "quant"
63
- },
64
- {
65
- "name": "discard_n",
66
- "regex": "discard .{0,15}cards?",
67
- "kind": "quant"
68
- },
69
- {
70
- "name": "add_mana_n",
71
- "regex": "add .{0,15}mana",
72
- "kind": "quant"
73
- },
74
- {
75
- "name": "token_power_xx",
76
- "regex": "(\\d+)/(\\d+) .{0,15}creature token",
77
- "kind": "quant"
78
- },
79
- {
80
- "name": "for_each_count",
81
- "regex": "for each (\\w+)",
82
- "kind": "quant"
83
- },
84
- {
85
- "name": "dmg_equal_power",
86
- "regex": "damage equal to (its|that|this) power",
87
- "kind": "flag"
88
- },
89
- {
90
- "name": "devotion",
91
- "regex": "devotion to",
92
- "kind": "flag"
93
- },
94
- {
95
- "name": "domain",
96
- "regex": "basic land type|\\bdomain\\b",
97
- "kind": "flag"
98
- },
99
- {
100
- "name": "colors_among",
101
- "regex": "colors among",
102
- "kind": "flag"
103
- },
104
- {
105
- "name": "nonbasic_count",
106
- "regex": "nonbasic land",
107
- "kind": "flag"
108
- }
109
- ]
110
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/removal.json DELETED
@@ -1,80 +0,0 @@
1
- {
2
- "category": "removal",
3
- "patterns": [
4
- {
5
- "name": "destroy_target",
6
- "regex": "destroy target",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "exile_target",
11
- "regex": "exile target",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "counter_spell",
16
- "regex": "counter target .{0,15}spell",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "tap_target",
21
- "regex": "tap target",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "fight",
26
- "regex": "fights?",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "return_to_hand",
31
- "regex": "return target .{0,40}to .{0,20}hand",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "destroy_all",
36
- "regex": "destroy all",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "exile_all",
41
- "regex": "exile all",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "damage_to_any",
46
- "regex": "damage to any target",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "damage_to_creature",
51
- "regex": "damage to target creature",
52
- "kind": "flag"
53
- },
54
- {
55
- "name": "minus_xx_target",
56
- "regex": "target creature gets -",
57
- "kind": "flag"
58
- },
59
- {
60
- "name": "loses_abilities",
61
- "regex": "loses all abilities",
62
- "kind": "flag"
63
- },
64
- {
65
- "name": "becomes_copy",
66
- "regex": "becomes a copy of",
67
- "kind": "flag"
68
- },
69
- {
70
- "name": "exile_instead_die",
71
- "regex": "would die.{0,10}exile .{0,5}instead",
72
- "kind": "flag"
73
- },
74
- {
75
- "name": "polymorph",
76
- "regex": "becomes a .{0,20}creature",
77
- "kind": "flag"
78
- }
79
- ]
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/resource_payoff.json DELETED
@@ -1,60 +0,0 @@
1
- {
2
- "category": "resource_payoff",
3
- "patterns": [
4
- {
5
- "name": "equal_number_of",
6
- "regex": "equal to the number of",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "cards_in_hand_matters",
11
- "regex": "cards? in .{0,15}hand",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "four_card_types_gy",
16
- "regex": "four or more card types",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "shares_creature_type",
21
- "regex": "shares? a creature type",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "base_pt",
26
- "regex": "base power and toughness",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "noncreature_nonland",
31
- "regex": "noncreature.{0,5}nonland",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "artifacts_you_control",
36
- "regex": "artifacts? you control",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "enchantments_matter",
41
- "regex": "enchantments? you control",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "lands_you_control",
46
- "regex": "lands? you control",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "legendary_matters",
51
- "regex": "legendary",
52
- "kind": "flag"
53
- },
54
- {
55
- "name": "instant_sorcery_gy",
56
- "regex": "instant (and|or) sorcery",
57
- "kind": "flag"
58
- }
59
- ]
60
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/set_mechanics_extra.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "category": "set_mechanics_extra",
3
- "patterns": [
4
- {
5
- "name": "descend",
6
- "regex": "descend",
7
- "kind": "flag"
8
- }
9
- ]
10
- }
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/set_mechanics_extra2.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "category": "set_mechanics_extra2",
3
- "patterns": [
4
- {
5
- "name": "job_select",
6
- "regex": "job select",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "seek",
11
- "regex": "\\bseek\\b",
12
- "kind": "flag"
13
- }
14
- ]
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/spells_matter.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "category": "spells_matter",
3
- "patterns": [
4
- {
5
- "name": "noncreature_payoff",
6
- "regex": "whenever you cast a noncreature spell",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "instant_sorcery_cast",
11
- "regex": "whenever you cast an? (instant|sorcery)",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "cast_two_spells",
16
- "regex": "cast (two or more|your second)",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "copy_spell",
21
- "regex": "cop(y|ies) (that|target) (spell|instant|sorcery)",
22
- "kind": "flag"
23
- }
24
- ]
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/tokens_board.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "category": "tokens_board",
3
- "patterns": [
4
- {
5
- "name": "creates_treasure",
6
- "regex": "treasure token",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "creates_food",
11
- "regex": "food token",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "creates_clue",
16
- "regex": "clue token",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "anthem",
21
- "regex": "creatures you control get \\+",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "lord_typal",
26
- "regex": "other .{0,15}creatures you control get \\+",
27
- "kind": "flag"
28
- }
29
- ]
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/tokens_named.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "category": "tokens_named",
3
- "patterns": [
4
- {
5
- "name": "spirit_token",
6
- "regex": "create .{0,20}spirit.{0,15}token",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "tapped_attacking_token",
11
- "regex": "tapped and attacking",
12
- "kind": "flag"
13
- }
14
- ]
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/triggers.json DELETED
@@ -1,55 +0,0 @@
1
- {
2
- "category": "triggers",
3
- "patterns": [
4
- {
5
- "name": "etb",
6
- "regex": "(when|whenever) .{0,30}enters",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "etb_value",
11
- "regex": "(when|whenever) .{0,30}enters.{0,45}(draw|create|deal|destroy|gain|search)",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "dies_trigger",
16
- "regex": "(when|whenever) .{0,25}dies",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "attack_trigger",
21
- "regex": "whenever .{0,25}attacks",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "cast_trigger",
26
- "regex": "whenever you cast",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "upkeep_trigger",
31
- "regex": "at the beginning of .{0,20}upkeep",
32
- "kind": "flag"
33
- },
34
- {
35
- "name": "end_step_trigger",
36
- "regex": "at the beginning of .{0,20}end step",
37
- "kind": "flag"
38
- },
39
- {
40
- "name": "combat_dmg_player",
41
- "regex": "deals combat damage to a player",
42
- "kind": "flag"
43
- },
44
- {
45
- "name": "landfall",
46
- "regex": "landfall|whenever a land enters",
47
- "kind": "flag"
48
- },
49
- {
50
- "name": "spellcast_matters",
51
- "regex": "whenever you cast .{0,20}(instant|sorcery)",
52
- "kind": "flag"
53
- }
54
- ]
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/typal.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "category": "typal",
3
- "patterns": [
4
- {
5
- "name": "other_type_you_control",
6
- "regex": "other \\w+ you control",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "for_each_type",
11
- "regex": "for each \\w+ you control",
12
- "kind": "flag"
13
- }
14
- ]
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/patterns/vehicles_types.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "category": "vehicles_types",
3
- "patterns": [
4
- {
5
- "name": "vehicle_crew",
6
- "regex": "crew",
7
- "kind": "flag"
8
- },
9
- {
10
- "name": "class_level",
11
- "regex": "level \\d|class",
12
- "kind": "flag"
13
- },
14
- {
15
- "name": "saga_chapter",
16
- "regex": "(i|ii|iii|iv) —",
17
- "kind": "flag"
18
- },
19
- {
20
- "name": "adventure",
21
- "regex": "adventure",
22
- "kind": "flag"
23
- },
24
- {
25
- "name": "planeswalker_loyalty",
26
- "regex": "loyalty",
27
- "kind": "flag"
28
- },
29
- {
30
- "name": "room_door",
31
- "regex": "\\bdoor\\b",
32
- "kind": "flag"
33
- }
34
- ]
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
featurizer/assets/sbert_pca.joblib DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:327d88b5d4d9f0670bd5e0686deecb0601d284f4b4c92254079718b5a9fe9650
3
- size 52023
 
 
 
 
featurizer/featurizer.py DELETED
@@ -1,178 +0,0 @@
1
- import re
2
- import json
3
- from pathlib import Path
4
-
5
- import numpy as np
6
- import joblib
7
-
8
- ASSETS = Path(__file__).parent / "assets"
9
- N_PCA = 32
10
- PIPS = ["W", "U", "B", "R", "G", "C"]
11
-
12
- _COLOR = {"W": "white", "U": "blue", "B": "black", "R": "red", "G": "green", "C": "colorless"}
13
- _NUM = {str(i): w for i, w in enumerate(
14
- "zero one two three four five six seven eight nine ten eleven twelve "
15
- "thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty".split())}
16
- _SPECIAL = {"T": "tap", "Q": "untap", "E": "energy", "S": "snow mana", "P": "phyrexian mana",
17
- "X": "variable x mana", "Y": "variable y mana", "Z": "variable z mana"}
18
- _TOK = re.compile(r"\{([^}]+)\}")
19
-
20
-
21
- def _one(inner):
22
- s = inner.strip().upper()
23
- if s in _SPECIAL: return _SPECIAL[s]
24
- if s in _COLOR: return f"{_COLOR[s]} mana"
25
- if s.isdigit(): return f"{_NUM.get(s, s)} generic mana"
26
- if "/" in s:
27
- parts = s.split("/"); phy = "P" in parts
28
- parts = [p for p in parts if p != "P"]
29
- w = [_COLOR[p] if p in _COLOR else
30
- (f"{_NUM.get(p, p)} generic" if p.isdigit() else p.lower()) for p in parts]
31
- j = " or ".join(w)
32
- return f"{j} phyrexian mana" if phy else f"{j} mana"
33
- return f"{s.lower()} symbol"
34
-
35
-
36
- def _expand_symbols(text):
37
- out = _TOK.sub(lambda m: f" {_one(m.group(1))} ", text or "")
38
- out = re.sub(r"\s+", " ", out)
39
- out = re.sub(r"\s+([,.:;])", r"\1", out)
40
- return out.strip()
41
-
42
-
43
- def _self_name_forms(card_name):
44
- forms = {card_name}
45
- short = card_name.split(",")[0].strip()
46
- forms.add(short)
47
- words = short.split()
48
- if len(words) > 1:
49
- forms.add(words[0])
50
- forms.add(" ".join(words[:2]))
51
- return forms
52
-
53
-
54
- def _normalize_oracle(card_name, text):
55
- out = text or ""
56
- for cand in sorted(_self_name_forms(card_name), key=len, reverse=True):
57
- out = re.sub(r"\b" + re.escape(cand) + r"\b", "this card", out)
58
- return _expand_symbols(out)
59
-
60
-
61
- def _typeline_text(face):
62
- tl = (face.get("type_line", "") or "").strip()
63
- return f"This card is a {tl}. " if tl else ""
64
-
65
-
66
- def _parse_cost(mana_cost):
67
- pips = re.findall(r"\{([^}]+)\}", mana_cost or "")
68
- counts = {c: 0.0 for c in PIPS}
69
- generic = 0.0
70
- mv = 0.0
71
- for p in pips:
72
- if p.isdigit():
73
- generic += float(p); mv += float(p)
74
- elif p in ("X", "Y", "Z"):
75
- pass
76
- else:
77
- mv += 1.0
78
- for c in PIPS:
79
- if c in p: counts[c] += 1.0
80
- return mv, generic, counts
81
-
82
-
83
- def _ptval(x):
84
- try:
85
- return float(x), 0.0
86
- except (TypeError, ValueError):
87
- return 0.0, (1.0 if x not in (None, "") else 0.0)
88
-
89
-
90
- def _numeric_vec(face):
91
- mc = face.get("mana_cost")
92
- castable = 1.0 if (mc not in (None, "")) else 0.0
93
- mv, generic, counts = _parse_cost(mc)
94
- has_p = "power" in face and face.get("power") is not None
95
- has_t = "toughness" in face and face.get("toughness") is not None
96
- has_l = "loyalty" in face and face.get("loyalty") is not None
97
- pwr, var_p = _ptval(face.get("power")) if has_p else (0.0, 0.0)
98
- tou, var_t = _ptval(face.get("toughness")) if has_t else (0.0, 0.0)
99
- loy, _ = _ptval(face.get("loyalty")) if has_l else (0.0, 0.0)
100
- vec = [
101
- mv / 10.0, castable,
102
- generic / 10.0,
103
- pwr / 10.0, 1.0 if has_p else 0.0,
104
- tou / 10.0, 1.0 if has_t else 0.0,
105
- loy / 10.0, 1.0 if has_l else 0.0,
106
- 1.0 if (var_p or var_t) else 0.0,
107
- ]
108
- vec += [counts[c] / 5.0 for c in PIPS]
109
- return np.array(vec, dtype=np.float32)
110
-
111
-
112
- def _faces_of(card):
113
- if "card_faces" in card and card["card_faces"]:
114
- out = []
115
- for f in card["card_faces"]:
116
- g = dict(f)
117
- g.setdefault("name", card["name"])
118
- out.append(g)
119
- return out
120
- return [card]
121
-
122
-
123
- def _l2(v):
124
- n = np.linalg.norm(v)
125
- return v / n if n > 0 else v
126
-
127
-
128
- class CardFeaturizer:
129
- def __init__(self, sbert_model="all-MiniLM-L6-v2", assets=ASSETS, device=None):
130
- from sentence_transformers import SentenceTransformer
131
- self.stm = SentenceTransformer(sbert_model, device=device)
132
- self.pca = joblib.load(Path(assets) / "sbert_pca.joblib")
133
- self.patterns = self._load_patterns(Path(assets) / "patterns")
134
-
135
- @staticmethod
136
- def _load_patterns(pdir):
137
- out = []
138
- for jf in sorted(Path(pdir).glob("*.json")):
139
- d = json.loads(jf.read_text(encoding="utf-8"))
140
- for p in d["patterns"]:
141
- out.append(re.compile(p["regex"]))
142
- return out
143
-
144
- def _feature_vec(self, text):
145
- t = (text or "").lower()
146
- return np.array([1.0 if rx.search(t) else 0.0 for rx in self.patterns], dtype=np.float32)
147
-
148
- def _face_607(self, card, faces, sb):
149
- out = []
150
- for i, f in enumerate(faces):
151
- nm = _l2(_numeric_vec(f))
152
- ft = self._feature_vec(f.get("oracle_text", ""))
153
- out.append(np.concatenate([_l2(sb[i]), nm, ft]).astype(np.float32))
154
- return np.stack(out)
155
-
156
- def featurize_batch(self, cards):
157
- all_texts, spans = [], []
158
- per_card_faces = []
159
- for card in cards:
160
- faces = _faces_of(card)
161
- per_card_faces.append(faces)
162
- start = len(all_texts)
163
- for f in faces:
164
- all_texts.append(_typeline_text(f) + _normalize_oracle(f.get("name", card["name"]),
165
- f.get("oracle_text", "")))
166
- spans.append((start, len(all_texts)))
167
- sb = self.stm.encode(all_texts, convert_to_numpy=True,
168
- normalize_embeddings=True).astype(np.float32)
169
- out = []
170
- for (a, b), faces in zip(spans, per_card_faces):
171
- face607 = self._face_607(None, faces, sb[a:b])
172
- fused = np.maximum.reduce(face607, 0) if face607.shape[0] > 1 else face607[0]
173
- sb32 = self.pca.transform(fused[None, 0:384])[0]
174
- out.append(np.concatenate([sb32, fused[384:400], fused[400:607]]).astype(np.float32))
175
- return np.stack(out)
176
-
177
- def featurize(self, card):
178
- return self.featurize_batch([card])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inference.py DELETED
@@ -1,116 +0,0 @@
1
- import sys
2
- import json
3
- from pathlib import Path
4
-
5
- import numpy as np
6
- import torch
7
-
8
- sys.path.insert(0, str(Path(__file__).parent))
9
- from model import EncDecDraft, ModelConfig
10
- from featurizer import CardFeaturizer
11
-
12
- ASSETS = Path(__file__).parent / "featurizer" / "assets"
13
-
14
-
15
- class CardDB:
16
- def __init__(self, cards_path=ASSETS / "cards.json"):
17
- raw = json.loads(Path(cards_path).read_text(encoding="utf-8"))
18
- self.by_name = {}
19
- for c in raw:
20
- self._index(c["name"], c)
21
- for f in c.get("card_faces", []) or []:
22
- self._index(f.get("name", ""), c)
23
-
24
- def _index(self, name, card):
25
- if name:
26
- self.by_name.setdefault(name.lower(), card)
27
-
28
- def get(self, name):
29
- c = self.by_name.get(name.lower().strip())
30
- if c is None:
31
- raise KeyError(f"card not found: {name!r} (pass a dict for custom/unseen cards)")
32
- return c
33
-
34
-
35
- def _card_key(card):
36
- return card["name"] if isinstance(card, dict) else card
37
-
38
-
39
- class MtgDraftAssistant:
40
- def __init__(self, model, featurizer, db, cfg):
41
- self.model = model.eval()
42
- self.fz = featurizer
43
- self.db = db
44
- self.cfg = cfg
45
- self._cache = {}
46
-
47
- @classmethod
48
- def from_pretrained(cls, hf_dir=None, device="cpu"):
49
- hf_dir = Path(hf_dir) if hf_dir else Path(__file__).parent
50
- ckpt_path = next((hf_dir / "model").glob("*.ckpt"))
51
- cfg = ModelConfig()
52
- model = EncDecDraft(255, 45, cfg)
53
- ck = torch.load(ckpt_path, map_location=device, weights_only=False)
54
- sd = {k.replace("model.", "", 1): v for k, v in ck["state_dict"].items() if k.startswith("model.")}
55
- model.load_state_dict(sd)
56
- fz = CardFeaturizer(device=device)
57
- db = CardDB()
58
- return cls(model, fz, db, cfg)
59
-
60
- def _vec(self, card):
61
- key = _card_key(card).lower().strip()
62
- if key not in self._cache:
63
- data = card if isinstance(card, dict) else self.db.get(card)
64
- self._cache[key] = self.fz.featurize(data)
65
- return self._cache[key]
66
-
67
- @torch.no_grad()
68
- def rank(self, pack_history, pool):
69
- T = len(pack_history)
70
- P = max(len(p) for p in pack_history)
71
- cards = {}
72
- for pk in pack_history:
73
- for c in pk:
74
- cards.setdefault(_card_key(c), c)
75
- for c in pool:
76
- cards.setdefault(_card_key(c), c)
77
-
78
- gid = {name: i + 1 for i, name in enumerate(sorted(cards))}
79
- table = np.zeros((len(gid) + 1, 255), dtype=np.float32)
80
- for name, card in cards.items():
81
- table[gid[name]] = self._vec(card)
82
-
83
- pack_gid = np.zeros((1, T, P), dtype=np.int64)
84
- for t, pk in enumerate(pack_history):
85
- for j, c in enumerate(pk):
86
- pack_gid[0, t, j] = gid[_card_key(c)]
87
- pickvec = np.zeros((1, T), dtype=np.int64)
88
- for t, c in enumerate(pool):
89
- pickvec[0, t] = gid[_card_key(c)]
90
-
91
- batch = {"pack_gid": torch.from_numpy(pack_gid), "pickvec_gid": torch.from_numpy(pickvec)}
92
- compact = torch.from_numpy(table)
93
- score = self.model(batch, compact)[0, T - 1]
94
- cur = [_card_key(c) for c in pack_history[-1]]
95
- prob = torch.softmax(score[:len(cur)], -1)
96
- out = [(cur[j], float(prob[j])) for j in range(len(cur))]
97
- return sorted(out, key=lambda x: -x[1])
98
-
99
- def new_draft(self):
100
- return Draft(self)
101
-
102
-
103
-
104
- class Draft:
105
- def __init__(self, assistant):
106
- self.a = assistant
107
- self.pack_history = []
108
- self.pool = []
109
-
110
- def see(self, pack):
111
- self.pack_history.append(list(pack))
112
- return self.a.rank(self.pack_history, self.pool)
113
-
114
- def pick(self, card):
115
- self.pool.append(card)
116
- return card
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
model.py DELETED
@@ -1,53 +0,0 @@
1
- from dataclasses import dataclass
2
-
3
- import numpy as np
4
- import torch
5
- import torch.nn as nn
6
-
7
-
8
- @dataclass
9
- class ModelConfig:
10
- d_model: int = 160
11
- n_heads: int = 16
12
- n_layers: int = 2
13
- ff_dim: int = 512
14
- dropout: float = 0.124
15
-
16
-
17
- class EncDecDraft(nn.Module):
18
- def __init__(self, compact_dim, t_max, cfg: ModelConfig):
19
- super().__init__()
20
- d = cfg.d_model
21
- self.d = d
22
- self.t_max = t_max
23
- self.proj = nn.Sequential(nn.Linear(compact_dim, d), nn.GELU(), nn.Linear(d, d))
24
- self.qpool = nn.Parameter(torch.randn(d) * 0.02)
25
- self.pos_e = nn.Embedding(t_max, d)
26
- self.pos_d = nn.Embedding(t_max, d)
27
- enc = nn.TransformerEncoderLayer(d, cfg.n_heads, cfg.ff_dim, dropout=cfg.dropout, batch_first=True, activation="gelu", norm_first=True)
28
- self.encoder = nn.TransformerEncoder(enc, cfg.n_layers)
29
- dec = nn.TransformerDecoderLayer(d, cfg.n_heads, cfg.ff_dim, dropout=cfg.dropout, batch_first=True, activation="gelu", norm_first=True)
30
- self.decoder = nn.TransformerDecoder(dec, cfg.n_layers)
31
- self.score_mlp = nn.Sequential(nn.Linear(d * 2, d), nn.GELU(), nn.Linear(d, 1))
32
-
33
- def forward(self, batch, compact):
34
- pack_gid = batch["pack_gid"]
35
- B, T, P = pack_gid.shape
36
- packmask = pack_gid != 0
37
- pv = self.proj(compact[pack_gid])
38
- att = (pv * self.qpool).sum(-1) / np.sqrt(self.d)
39
- att = att.masked_fill(~packmask, -1e9)
40
- w = torch.softmax(att, -1).unsqueeze(-1)
41
- mem = (w * pv).sum(2) + self.pos_e(torch.arange(T, device=pack_gid.device))
42
- mem_mask = ~packmask.any(-1)
43
- mem = self.encoder(mem, src_key_padding_mask=mem_mask)
44
-
45
- pk = self.proj(compact[batch["pickvec_gid"]])
46
- pk = torch.cat([torch.zeros(B, 1, self.d, device=pk.device), pk[:, :-1]], 1)
47
- pk = pk + self.pos_d(torch.arange(T, device=pk.device))
48
- causal = nn.Transformer.generate_square_subsequent_mask(T, device=pk.device)
49
- state = self.decoder(pk, mem, tgt_mask=causal, memory_key_padding_mask=mem_mask)
50
-
51
- st = state.unsqueeze(2).expand(-1, -1, P, -1)
52
- s = self.score_mlp(torch.cat([st, pv], -1)).squeeze(-1)
53
- return s.masked_fill(~packmask, -1e4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
model/mtgda-encdec.ckpt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ffdb112813b68e1feb623efcb418f88d60ce8ea87df77ec858e0978536082513
3
- size 26061571
 
 
 
 
requirements.txt DELETED
@@ -1,5 +0,0 @@
1
- torch>=2.4.0
2
- numpy
3
- scikit-learn
4
- joblib
5
- sentence-transformers>=2.2
 
 
 
 
 
 
static/seen-vs-unseen-acc-graph.png DELETED
Binary file (34.2 kB)