[OC] Interactive Low-Dimensional Embeddings of Magic: the Gathering Cards

OC

Posted Dec 7, 2021, 1:52 PM UTC

52139
dingadingdongg•

are you willing to explain this to a mtg non-player? i'd love to know what this means!

15
Kandlejackk•

I'm a mtg player and I have no idea what most of this means

36
SumNeuronOPOC: 4•

See my previous comments, but in short it shows that the embedding schema used here is sufficient to represent the cards in a meaningful way. This is a "sanity check" / stepping stone towards a larger project.

8
Jiddlez•

I recognize some of those words

9
St33lbutcher•

Since OP is being obtuse on purpose... Basically OP got a list of every card and all of it's characteristics. If you can turn each of these characteristics into a number (for example the mana cost would be very easy) you can do some math that finds the primary axes along which cards change.

That's pretty abstract though. So imagine taking a simpler set of characteristics: mana cost, strength, and name. If you could turn these characteristics into a number (mana and strength already are typically, you'd need to do something snazzy for the name since it's a word) youd need 3 axes to represent the full range of possibilities. If you run the math that OP ran, you'd find that mana and strength are strongly correlated (the higher the mana cost, the higher strength is likely to be) while the card's name probably has no correlation to it's strength.

Now I want to visualize this space. We can only make 2D graphs on a flat screen so I'd like to use the correlation between mana and strength to my advantage. Pretend that mana and strength are perfectly correlated, if mana is 3 then strength is 3. I could smush both of these characteristics into the same axis. I could call it the mana axis but I know that the strength is the same as the mana so I'm not really losing any information. If I do this, I can plot a 2D axis of mana vs name without losing any information. This is called dimensional reduction.

Now back to the full set of characteristics. It's gonna be a lot messier than our hypothetical above. OPs math is gonna blend together the characteristics together that are correlated with different weights to explain as much as possible about the card with the smallest number of axes.

This worked amazingly well. You can see that if you highlight the dot representing Planeswalker, they all sit really closely on the graph. If you gave OP a card with a full set of characteristics but the type was hidden, they could do some math on it and figure out if it was a Planeswalker. So in a sense, OP has found a "mathematical definition" of each type which is very powerful.

Hope this makes some sense and I didn't screw anything up too badly.

26
[deleted]•

Algorithms exist for two general purposes: (1) classifying things into groups and (2) predicting values.

Here, both algorithms classify things into groups, and it appears the point of this exercise is to group MtG cards into groups based on the card characteristics from Scryfall.

The natural next question: What do the groupings produced by the algorithms mean? Unknown. So we're left to argue about what the groupings "mean."

Groups produced by other classification algos are more straightforward in meaning. For example, phones have algorithms that analyze pictures and group them into two groups: (1) pictures with "Bob" in them and (2) pictures without "Bob" in them. That is how facial recognition works. Sort pics into two piles: with Bob's face, without Bob's face.

1
Kandlejackk•

Yeah like obviously I know what each category he's selecting means, but as for how they translate to usable data in the graph/what the X and Y axis are saying is what I don't understand.

5
[deleted]•

They don't translate to usable data. The axes are meaningless.

Algorithms will spit out groupings regardless of the data you feed them. That doesn't always mean the groupings are meaningful.

One criticism of using algorithms is that they don't produce meaningful groupings. Instead, they produce arbitrary groupings, and our decision that they are meaningful *because an algorithm produced them* makes those groupings meaningful.

This criticism applies to things like using algorithms to sort convicted criminals into groups of "will commit crime again" and "will not commit crime again" in parole decisions, or sorting college applicants into groups "admit" or "deny admission."

8
SumNeuronOPOC: 4•

The actual axes are less important than the relative distance between points. The axes are those belonging to the dimensional reduction technique.

1
SumNeuronOPOC: 4•

Yes. If you have a loose sense / familiarity with the game then you know that a playing card from Magic: the Gathering (MtG) has a lot of properties and attributes on it. In the linked article I briefly touch on the notion of reprints and "functional" reprints (cards that do more-or-less the same thing). This begs the question "how do we know if two cards are similar?" In other words we need a way to compare them. What if two cards are identical in all attributes but (1) their name and (2) the power of the creature. How different is it? Is power more important than say color?

To start to address this the card attributes (categorical, sparse, and numerical) are converted into a large feature vector. So how do we know this vector means anything? Our embedding schema could be complete bunk! To answer this I used two different dimension reduction methods: t-SNE and PHATE. These reduced our large matrix (rows being cards, columns being features) into two dimensions (plotted above). By inspecting a third dimension (feature) via the color of the points, we can see that both PHATE and t-SNE manage to preserve aspects of the data's native manifold / high dimensional distances respectively and thus we see clusters e.g. all the "Planeswalker" cards are together.

In short, it is a sanity check to see if this is a decent way of embedding the cards (without using their rules text). Since this produces an embedding from which their latent space can be learned, it is a step towards a more powerful model. For example, I could combine this embedding with one specifically curated for a card's rules text.

4
Randusnuder•

Not to be that guy, but it “raises the question,” not “begs the question.”

A simple test you can use is to ask yourself “Does this beg the question?” And then say “No, it raises the question.”

1
dingadingdongg•

dang i think my brain is not sufficiently wrinkled to understand this, i'm also just a plebian who stumbled across this sub because of some interesting graphics

thank you for taking the time to write all this out! i think i'll have to slowly go through and figure out what the terms mean before i can begin understanding what your explanation meant 🥲

1
gzou•

From each card they extract a number of feature, their type, cost, stats, some special capabilities (but not too special so they have a counter for it). This gives you a feature vector for each card. Then they compressed this feature vectors using "t-sne". "T-sne" preserves the neighborhood while projecting the data. So the fact that the groups respect some characteristics like the cost / type of cards just show that T-sne works as intended. So nothing really informative in this diagram IMHO.

1
SumNeuronOPOC: 4•

Depends on how you look at it. Given the large number of categorical and sparse features, there is no guarantee that this method of embedding the cards into feature vectors would preserve any information. In this sense t-SNE and PHATE which show clustering by various attributes (type, mana value, mana cost, abilities, etc) are a sanity check that this feature representation is not inconsequential. Combined with a dedicated NLP embedding for the rules text, it could actually be quite fruitful.

2
SumNeuronOPOC: 4•

Interactive Article Link: https://magusoftheblog.com/articles/the-non-oracle-text-similarity-of-cards/

Source data was acquired from Scryfall.com's Bulk data API via HTTP request. It then underwent processing via personal Python 3.7+ scripts which relied on standard packages like SKLearn, NumPy, SciPy, etc. Once the data was processed, a minimal JSON file was exported. The website was developed using Nuxtjs, Vuetifyjs and Vuejs. The interactive visualization is powered by D3js.

12
NotMyGovernor•

I used to have I believe a blue / white "interrupts" deck with all 1/1 and 1/2 etc low cost creatures. I used to call it the "piss me hoffer deck". It was undefeated.

It interrupted absolutely everything that mattered from them and slow killed them over like 5 turns.

3
PinkTitanium•

What are the x- and y- axis??

2
SumNeuronOPOC: 4•

the axes correspond to the low dimensional space in which the respective algorithms (t-SNE, PHATE) have reduced the card embeddings. The actual coordinate values are less important than the relative distance.

7
PinkTitanium•

Interesting, so cards that are closer together in parameter space would be considered more similar by the algorithms?

Edit - just saw the thread above with longer comment explainations. Very cool! It’s interesting that the algorithms cluster cards for reasons that we don’t necessarily understand. I love MTG and data visualization, so I can’t wait to see where you go with this!

3
SumNeuronOPOC: 4•

Yes, although how t-SNE and PHATE work are both understood. t-SNE uses SGD to position the low dimensional representation as best it can to reflect the distances in the high dimensional space. PHATE uses manifold learning to traverse the native space of the data rather than the ambient space.

​

Many thanks for the encouragement :D

5
[deleted]•

[deleted]

1
vhua•

Have you tried UMAP? It should give better separation than t-SNE.

2
SumNeuronOPOC: 4•

UMAP is a fairly controversial algorithm (it has some use in practice but is still an unpublished paper) and fundamentally is quite similar to its predecessor diffusion maps (which is theoretically sound). Neither diffusion maps, nor umap guarantees better separation than t-SNE. Additionally, it is not like PHATE is divorce from differential geometry. It quite literally starts the same... distance matrix ---> affinity matrix --> normalized affinities ** time --> (then phate does something different).

Very neat to run into someone here familiar with UMAP though! :D

1
dataisbeautiful-botMODOC: ∞•

Thank you for your Original Content, u/SumNeuron!
Here is some important information about this post:

Remember that all visualizations on r/DataIsBeautiful should be viewed with a healthy dose of skepticism. If you see a potential issue or oversight in the visualization, please post a constructive comment below. Post approval does not signify that this visualization has been verified or its sources checked.

Join the Discord Community

Not satisfied with this visual? Think you can do better? Remix this visual with the data in the author's citation.


^^I'm open source | How I work

1
[deleted]•

[removed]

1
Shivaess•

This is awesome. Nicely done.

1
SumNeuronOPOC: 4•

Thank you very much :)

2
wond3rlove•

I was just reading up on the ass crack dude. This was the first post I saw right after that

1
[deleted]•

This eventually could be used to create decks faster and better, correct? Probably even solve the game to an extent. Also would be good for determining good drafting strategies before going to a draft.

1