Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Multiplicative and Complex Models: DistMult, ComplEx | Knowledge Graph Embeddings
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Knowledge Graphs and Embeddings

bookMultiplicative and Complex Models: DistMult, ComplEx

Multiplicative and complex-valued embedding models offer a powerful way to capture the semantics of knowledge graphs, especially when dealing with a variety of relation types. Two such models, DistMult and ComplEx, are widely used for their elegant scoring mechanisms and their differing abilities to represent symmetric and antisymmetric relations.

The DistMult model represents entities and relations as real - valued vectors of the same dimension. Its scoring function for a triple (hh, rr, tt) — where hh is the head entity, rr is the relation, and tt is the tail entity — uses a simple elementwise multiplication:

  • The score is computed by taking the sum of the elementwise product of the head, relation, and tail vectors.

This can be written as:

  • score(h,r,t)=h×r×t\text{score}(h, r, t) = \sum h \times r \times t

Because multiplication is commutative, DistMult is inherently limited to modeling symmetric relations, meaning it cannot distinguish between (hh, rr, tt) and (tt, rr, hh).

The ComplEx model extends DistMult by introducing complex-valued embeddings. Entities and relations are represented as complex vectors, and the scoring function incorporates the complex conjugate of the tail entity:

  • score(h,r,t)=Re(h×r×t)\text{score}(h, r, t) = \operatorname{Re}\left( \sum h \times r \times \overline{t} \right)

Here, Re\operatorname{Re} denotes the real part, and t\overline{t} is the complex conjugate. This design allows ComplEx to model both symmetric and antisymmetric relations, making it more expressive for knowledge graphs where directionality matters.

Both models are efficient and scalable, but their scoring mechanisms lead to different capabilities in representing relation patterns.

1234567891011121314151617181920212223
import numpy as np # DistMult scoring for real-valued embeddings def distmult_score(h, r, t): # h, r, t: numpy arrays of shape (d,) return np.sum(h * r * t) # ComplEx scoring for complex-valued embeddings def complex_score(h, r, t): # h, r, t: numpy arrays of shape (d,), dtype=complex return np.real(np.sum(h * r * np.conj(t))) # Example vectors h_real = np.array([0.2, -1.0, 0.5]) r_real = np.array([1.0, 0.3, -0.7]) t_real = np.array([-0.4, 0.8, 1.2]) h_cplx = np.array([0.2 + 0.1j, -1.0 + 0.5j, 0.5 - 0.2j]) r_cplx = np.array([1.0 - 0.3j, 0.3 + 0.2j, -0.7 + 0.4j]) t_cplx = np.array([-0.4 + 0.7j, 0.8 - 0.6j, 1.2 + 0.3j]) print("DistMult score:", distmult_score(h_real, r_real, t_real)) print("ComplEx score:", complex_score(h_cplx, r_cplx, t_cplx))
copy
Note
Definition

A symmetric relation is one where if a triple (hh, rr, tt) holds, then (tt, rr, hh) also holds. An antisymmetric relation is one where if (hh, rr, tt) holds, then (tt, rr, hh) does not hold unless h=th = t. Symmetry is crucial for modeling relations like "sibling of," while antisymmetry is needed for "parent of".

question mark

Which statement accurately describes the capabilities of DistMult and ComplEx in modeling relation types in knowledge graphs?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 4

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

bookMultiplicative and Complex Models: DistMult, ComplEx

Svep för att visa menyn

Multiplicative and complex-valued embedding models offer a powerful way to capture the semantics of knowledge graphs, especially when dealing with a variety of relation types. Two such models, DistMult and ComplEx, are widely used for their elegant scoring mechanisms and their differing abilities to represent symmetric and antisymmetric relations.

The DistMult model represents entities and relations as real - valued vectors of the same dimension. Its scoring function for a triple (hh, rr, tt) — where hh is the head entity, rr is the relation, and tt is the tail entity — uses a simple elementwise multiplication:

  • The score is computed by taking the sum of the elementwise product of the head, relation, and tail vectors.

This can be written as:

  • score(h,r,t)=h×r×t\text{score}(h, r, t) = \sum h \times r \times t

Because multiplication is commutative, DistMult is inherently limited to modeling symmetric relations, meaning it cannot distinguish between (hh, rr, tt) and (tt, rr, hh).

The ComplEx model extends DistMult by introducing complex-valued embeddings. Entities and relations are represented as complex vectors, and the scoring function incorporates the complex conjugate of the tail entity:

  • score(h,r,t)=Re(h×r×t)\text{score}(h, r, t) = \operatorname{Re}\left( \sum h \times r \times \overline{t} \right)

Here, Re\operatorname{Re} denotes the real part, and t\overline{t} is the complex conjugate. This design allows ComplEx to model both symmetric and antisymmetric relations, making it more expressive for knowledge graphs where directionality matters.

Both models are efficient and scalable, but their scoring mechanisms lead to different capabilities in representing relation patterns.

1234567891011121314151617181920212223
import numpy as np # DistMult scoring for real-valued embeddings def distmult_score(h, r, t): # h, r, t: numpy arrays of shape (d,) return np.sum(h * r * t) # ComplEx scoring for complex-valued embeddings def complex_score(h, r, t): # h, r, t: numpy arrays of shape (d,), dtype=complex return np.real(np.sum(h * r * np.conj(t))) # Example vectors h_real = np.array([0.2, -1.0, 0.5]) r_real = np.array([1.0, 0.3, -0.7]) t_real = np.array([-0.4, 0.8, 1.2]) h_cplx = np.array([0.2 + 0.1j, -1.0 + 0.5j, 0.5 - 0.2j]) r_cplx = np.array([1.0 - 0.3j, 0.3 + 0.2j, -0.7 + 0.4j]) t_cplx = np.array([-0.4 + 0.7j, 0.8 - 0.6j, 1.2 + 0.3j]) print("DistMult score:", distmult_score(h_real, r_real, t_real)) print("ComplEx score:", complex_score(h_cplx, r_cplx, t_cplx))
copy
Note
Definition

A symmetric relation is one where if a triple (hh, rr, tt) holds, then (tt, rr, hh) also holds. An antisymmetric relation is one where if (hh, rr, tt) holds, then (tt, rr, hh) does not hold unless h=th = t. Symmetry is crucial for modeling relations like "sibling of," while antisymmetry is needed for "parent of".

question mark

Which statement accurately describes the capabilities of DistMult and ComplEx in modeling relation types in knowledge graphs?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 4
some-alt