Search

Search papers and lessons

DistMult

Level 3 · 12 min read

DistMult gives each entity and relation a vector and scores a triple by the sum of the products of their matching entries, a fast way to rank missing facts in a knowledge graph.

On this page

  • Colour = topic mix
  • Discrete math
  • Linear algebra
  • Calculus
  • Neural network basics
  • Probability
  • Representation learning
  • ReadReady to readNot yet

TL;DR

DistMult learns a vector for every entity and every relation in a Knowledge Graph, then scores a candidate fact (h,r,t)(h, r, t) by multiplying the matching entries of the three vectors and adding the results. Facts that score high are predicted to be true, which fills in the links missing from an incomplete graph. Its scoring uses only a diagonal Bilinear Form, so it is fast and simple, but it treats a fact and its reverse as equally plausible.

Builds on: Knowledge Graph, Knowledge Graph Embedding, Bilinear Form, Link Prediction · Leads to: knowledge graph completion with richer models

Where it's used

Completing large knowledge bases. Projects such as Wikidata and Freebase store millions of facts as triples, but many true facts are missing. DistMult was tested on benchmark subsets of Freebase and WordNet, FB15k and WN18, where it ranks the held-out true facts above random false ones. The same ranking can propose new triples for a curator to check.

Recommendation. A shop can store facts such as (customer, bought, product) and (product, made_by, brand). Embedding the graph lets the system score unseen (customer, will_buy, product) triples and recommend the highest-scoring products. Here the relation is usually a single type, which suits DistMult's simple scoring.

Suggesting links for researchers. Scientific knowledge graphs connect papers, genes, chemicals and authors. Link prediction over them can propose pairs of concepts that co-occur in the literature but are not yet linked in the graph, so a human expert can decide whether the link is worth studying. The model proposes; the expert judges.

How it works

Take a tiny graph with two entities, "Ana" and "Blue Cafe", and one relation, "likes". Each entity and relation has a Vector of two numbers. Let h=(1,2)\mathbf{h} = (1, 2) be Ana, t=(3,1)\mathbf{t} = (3, 1) be Blue Cafe, and r=(0.5,−1)\mathbf{r} = (0.5, -1) be "likes". We want a score for the fact (Ana, likes, Blue Cafe).

  1. Look up the three vectors. Ana is (1,2)(1, 2), the relation is (0.5,−1)(0.5, -1), and Blue Cafe is (3,1)(3, 1). Check: each vector has two numbers, one per dimension.
  2. Multiply the first entries. 1×0.5×3=1.51 \times 0.5 \times 3 = 1.5. Check: this is the contribution of dimension 1.
  3. Multiply the second entries. 2×(−1)×1=−22 \times (-1) \times 1 = -2. Check: this is the contribution of dimension 2, and it is negative because the relation's second entry is negative.
  4. Add the contributions. 1.5+(−2)=−0.51.5 + (-2) = -0.5. Check: the score is −0.5-0.5.
  5. Decide what the score means. A high positive score means the model believes the fact. A negative score means the model thinks the fact is unlikely. Here the fact scores −0.5-0.5, so the model leans against it.
  6. Train so true facts score high. During training, the model sees true facts from the graph and invented false facts, and adjusts the vectors so that the true ones score high and the false ones low. Check: the training changes the numbers in the vectors, not the formula.
flowchart LR
  H["Entity h, a vector"] --> P[Multiply matching entries of h, r and t]
  R["Relation r, a vector"] --> P
  T["Entity t, a vector"] --> P
  P --> S[Add the products into one score]
  S --> D{High score?}
  D -- yes --> Y[Predict the fact is true]
  D -- no --> N[Predict the fact is unlikely]

The key step is step 2 and 3: the relation vector acts as a set of per-dimension weights between the two entities. DistMult does not mix dimensions together; each dimension is handled on its own and the results are summed.

The math

Definition: DistMult score

Let each entity ee have a vector e∈Rd\mathbf{e} \in \mathbb{R}^d and each relation rr have a vector r∈Rd\mathbf{r} \in \mathbb{R}^d. For a triple (h,r,t)(h, r, t) with head hh, relation rr and tail tt, the score is f(h,r,t)=∑i=1dhi ri ti=h⊤diag⁡(r) t,f(h, r, t) = \sum_{i=1}^{d} h_i\, r_i\, t_i = \mathbf{h}^\top \operatorname{diag}(\mathbf{r})\, \mathbf{t}, where hih_i, rir_i and tit_i are the ii-th entries of the three vectors, and diag⁡(r)\operatorname{diag}(\mathbf{r}) is the Diagonal Matrix whose diagonal holds the entries of r\mathbf{r}.

Step 1 in symbols: the lookup

Each triple is turned into three vectors of the same length dd. The number dd is a design choice, often between 50 and 200 in published experiments; the example uses d=2d = 2.

Step 2 to 4 in symbols: the sum of products

The score is a sum over dimensions. Each term hiritih_i r_i t_i is a product of three numbers, one from each vector in the same position. In the example, the terms are 1×0.5×3=1.51 \times 0.5 \times 3 = 1.5 and 2×(−1)×1=−22 \times (-1) \times 1 = -2, which sum to −0.5-0.5.

Writing the same sum with a Dot Product shows why the relation acts as weights. Let w=r⊙t\mathbf{w} = \mathbf{r} \odot \mathbf{t} mean the entry-by-entry product of r\mathbf{r} and t\mathbf{t}. Then f(h,r,t)=h⋅wf(h, r, t) = \mathbf{h} \cdot \mathbf{w}. The relation has been folded into t\mathbf{t} before the dot product.

Step 5 in symbols: turning a score into a probability

To use a score as a probability, pass it through the logistic function σ(s)=1/(1+e−s)\sigma(s) = 1 / (1 + e^{-s}). Then σ(f(h,r,t))\sigma(f(h, r, t)) is the model's belief that the triple holds. For the example, σ(−0.5)=1/(1+e0.5)≈0.38\sigma(-0.5) = 1/(1 + e^{0.5}) \approx 0.38. So the model gives the fact about a 38 percent chance, which is below even.

Step 6 in symbols: training

For each true triple (h,r,t)(h, r, t), a training step draws a corrupted triple (h′,r,t)(h', r, t) or (h,r,t′)(h, r, t') by replacing one end with a random entity. The loss for a pair of a true and a false triple with the logistic form is L=log⁡ ⁣(1+e−f(h,r,t))+log⁡ ⁣(1+ef(h′,r,t′)).\mathcal{L} = \log\!\left(1 + e^{-f(h, r, t)}\right) + \log\!\left(1 + e^{f(h', r, t')}\right). The first term is small when the true triple scores high. The second is small when the corrupted one scores low. Gradient descent adjusts the entries of all the vectors. Corrupted triples are the same idea as Negative Sampling, and the logistic loss plays the role of Cross-Entropy Loss for a yes-or-no label.

A symmetry

Swap head and tail. The score becomes f(t,r,h)=∑iti ri hi=f(h,r,t).f(t, r, h) = \sum_i t_i\, r_i\, h_i = f(h, r, t). Multiplication is commutative, so DistMult scores a fact and its reverse identically. This is a real limitation: a relation such as "parent of" is not symmetric, and DistMult cannot represent that asymmetry with a single relation vector.

Worked examples

Example
Example 1: a tiny score (hand-computable)

Use h=(2,1)\mathbf{h} = (2, 1), r=(1,3)\mathbf{r} = (1, 3) and t=(0,4)\mathbf{t} = (0, 4) in two dimensions.

  1. The first dimension product is h1r1t1=2×1×0=0h_1 r_1 t_1 = 2 \times 1 \times 0 = 0.
  2. The second dimension product is h2r2t2=1×3×4=12h_2 r_2 t_2 = 1 \times 3 \times 4 = 12.
  3. The score is 0+12=120 + 12 = 12.
  4. Check: the first dimension contributes nothing because the tail's first entry is 0. The second dimension contributes the whole score.
  5. Interpretation: a large positive score says the model strongly believes the fact, and the zero in one dimension means that dimension plays no role for this tail.
Example
Example 2: the standard case with three dimensions

Let h=(0.8,0.1,0.5)\mathbf{h} = (0.8, 0.1, 0.5), r=(1.2,0.0,−0.7)\mathbf{r} = (1.2, 0.0, -0.7) and t=(0.9,0.4,0.6)\mathbf{t} = (0.9, 0.4, 0.6).

  1. First dimension: 0.8×1.2×0.90.8 \times 1.2 \times 0.9. First 0.8×1.2=0.960.8 \times 1.2 = 0.96, then 0.96×0.9=0.8640.96 \times 0.9 = 0.864.
  2. Second dimension: 0.1×0.0×0.4=00.1 \times 0.0 \times 0.4 = 0. The relation has zero weight here.
  3. Third dimension: 0.5×(−0.7)×0.60.5 \times (-0.7) \times 0.6. First 0.5×(−0.7)=−0.350.5 \times (-0.7) = -0.35, then −0.35×0.6=−0.21-0.35 \times 0.6 = -0.21.
  4. Add the three contributions: 0.864+0−0.21=0.6540.864 + 0 - 0.21 = 0.654.
  5. Apply the logistic function: σ(0.654)=1/(1+e−0.654)\sigma(0.654) = 1 / (1 + e^{-0.654}). Since e−0.654≈0.520e^{-0.654} \approx 0.520, the probability is 1/1.520≈0.661 / 1.520 \approx 0.66.
  6. Interpretation: the model gives the fact about a 66 percent chance. The negative relation entry in the third dimension pulls the score down, but the first dimension pushes it up more.
Example
Example 3: a realistic knowledge-graph fact, and the symmetry

A knowledge graph has the fact (Marie Curie, won, Nobel Prize). Suppose the trained vectors are: Marie Curie h=(0.9,0.2,0.4)\mathbf{h} = (0.9, 0.2, 0.4), the relation "won" r=(1.5,0.1,0.8)\mathbf{r} = (1.5, 0.1, 0.8), and Nobel Prize t=(0.7,0.3,0.5)\mathbf{t} = (0.7, 0.3, 0.5).

  1. First dimension: 0.9×1.5×0.7=0.9450.9 \times 1.5 \times 0.7 = 0.945. Check: 0.9×1.5=1.350.9 \times 1.5 = 1.35, and 1.35×0.7=0.9451.35 \times 0.7 = 0.945.
  2. Second dimension: 0.2×0.1×0.3=0.0060.2 \times 0.1 \times 0.3 = 0.006. Check: 0.2×0.1=0.020.2 \times 0.1 = 0.02, and 0.02×0.3=0.0060.02 \times 0.3 = 0.006.
  3. Third dimension: 0.4×0.8×0.5=0.160.4 \times 0.8 \times 0.5 = 0.16. Check: 0.4×0.8=0.320.4 \times 0.8 = 0.32, and 0.32×0.5=0.160.32 \times 0.5 = 0.16.
  4. Sum: 0.945+0.006+0.16=1.1110.945 + 0.006 + 0.16 = 1.111.
  5. Now score the reverse fact (Nobel Prize, won, Marie Curie). The same three products appear in a different order, so the score is again 1.1111.111.
  6. Interpretation: the model cannot tell the fact from its reverse. For "won", that is harmless in practice because the reverse is nonsense and is rarely a candidate; for "parent of" it would be a real error, and a different model should be used.

Try it: a relation vector is r=(2,0)\mathbf{r} = (2, 0), the head is h=(1,5)\mathbf{h} = (1, 5) and the tail is t=(3,7)\mathbf{t} = (3, 7). What is the score, and how much does the second dimension contribute? Answer: the first dimension gives 1×2×3=61 \times 2 \times 3 = 6 and the second gives 5×0×7=05 \times 0 \times 7 = 0, so the score is 6, and the second dimension contributes nothing because the relation's second entry is zero.

Common mistakes and tradeoffs

It is tempting to think that DistMult can represent any relation between two entities. In fact the score is symmetric in head and tail, so it can only represent relations that are symmetric, or that are harmless to treat symmetrically. For asymmetric relations, such as "contains" or "parent of", models that use a separate matrix or a rotation for each relation are more suitable, and they are the subject of the later embedding models.

It is tempting to think that a high score means the fact is true. In fact the score is a ranking signal learned from the graph's own data. The model may give high scores to plausible-sounding facts that are false, and it knows only the facts in the graph it saw. Its outputs should be checked before they are trusted.

It is tempting to think that more dimensions always help. In fact a larger dd costs more memory and training time, and it can overfit on a sparse graph where most entities have only a few facts. The right size depends on how much data the graph has.

It is tempting to think that negative sampling is optional. In fact without corrupted triples, the training signal contains only true facts, and the easiest solution is to give every vector a large norm, which makes every score high. Negative sampling is what forces the model to separate true facts from false ones.

When to use it. Use DistMult when the relations are mostly symmetric, when the graph is large and you need fast scoring, or when you want a simple baseline before trying a more expressive model.

When not to use it. Do not use it alone when direction matters for most relations, when you need to model composition of relations (a relation applied twice), or when you need calibrated probabilities without further checks.

History

Before the mid-2010s, knowledge bases had grown large but were sparse, and reasoning over them was mostly symbolic: rules and logical queries that break on any missing link. Researchers began to embed entities and relations in vectors so that a learned model could fill gaps, starting with full bilinear models such as RESCAL in 2011, and with translation-based models such as TransE in 2013.

The DistMult paper by Bishan Yang, Wen-tau Yih, Xiaodong He, Jianfeng Gao and Li Deng, posted in 2014 and presented at ICLR 2015, showed that restricting each relation to a diagonal matrix made the model both simpler and competitive on the standard benchmarks. The simplification caught on because it trains quickly on large graphs. Its symmetry limitation became the motivation for the later models that handle directed relations.

Recap

  • A knowledge graph stores facts as triples, and link prediction fills in the missing ones.
  • DistMult gives each entity and relation a vector, and scores a triple by ∑ihiriti\sum_i h_i r_i t_i.
  • The score is the sum of products of matching entries, so each dimension is handled on its own.
  • Training pushes true triples above corrupted ones, which needs negative sampling.
  • The score is symmetric in head and tail, so DistMult cannot model directed relations on its own.
  • Read next: the later embedding models that handle direction and richer interactions, which build directly on the scoring idea here.

Check yourself

QuestionWhat does DistMult compute for a triple (h, r, t)?Show answer
It computes the sum over dimensions of hiritih_i r_i t_i, where each term multiplies the matching entries of the head, relation and tail vectors. The result is a single score, and a high score means the model believes the fact.
QuestionCompute the DistMult score for h=(1,2)\mathbf{h} = (1, 2), r=(3,−1)\mathbf{r} = (3, -1) and t=(2,4)\mathbf{t} = (2, 4).Show answer
The first term is 1×3×2=61 \times 3 \times 2 = 6. The second is 2×(−1)×4=−82 \times (-1) \times 4 = -8. The score is 6+(−8)=−26 + (-8) = -2.
QuestionWhy does DistMult give the same score to (A, r, B) and (B, r, A), and why is that a problem for some relations?Show answer
The score is a sum of products hiritih_i r_i t_i, and multiplication does not depend on order, so swapping head and tail leaves each product, and the sum, unchanged. This is a problem for asymmetric relations such as "parent of", where the reverse fact is false and the model cannot represent the difference.
QuestionA team builds a link predictor for a graph whose relations are mostly symmetric, such as is-similar-to. They skip negative sampling to save time. Explain in plain words what could go wrong during training.Show answer
Without corrupted triples, the training signal only rewards high scores for true facts. The easiest way to lower the loss is to make the vectors grow, which makes every score high, including for false facts. The model then cannot rank true links above false ones. Negative sampling is what teaches the model to separate them.

Sources