TransE Embedding Geometry¶
Run the TransE Embedding Geometry MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim¶
TransE models each relation as a translation in vector space: the tail entity \(t\) should be close to head \(h\) displaced by relation vector \(r\). Training minimizes \(\|\mathbf{h} + \mathbf{r} - \mathbf{t}\|\) for positive triples while maximizing the distance for corrupted ones.
This MicroSim animates the 2D embedding space. Entity points and relation arrows update as you step through training. A live loss display shows positive and negative pair distances. A "symmetric relation" preset shows the France–borders–Germany example where the relation vector must equal zero to satisfy both \((\text{France}, \text{borders}, \text{Germany})\) and \((\text{Germany}, \text{borders}, \text{France})\).
Learning objective (Bloom's Apply (Level 3)): Watch TransE training drive valid triples toward \(\mathbf{h} + \mathbf{r} \approx \mathbf{t}\) and see why a symmetric relation forces its vector toward zero — exposing TransE's fundamental limitation with symmetry.
How to Use¶
- Select a preset — choose "simple transitive" or "symmetric (fails)" to load example triples.
- Step training — click "Train Step" to run one gradient update and watch the embeddings shift.
- Read the loss — the loss panel shows the margin loss for positive and negative triples.
- Toggle relation — click any displayed relation arrow to highlight the triples it is used in.
- View failure — in the symmetric preset, observe that the relation vector collapses toward zero.
Iframe Embed Code¶
You can embed this MicroSim in any web page with the following HTML:
<iframe src="https://AnvithPothula.github.io/graph-neural-networks-textbook/sims/ch12-kg-embedding-geometry/main.html"
height="522"
width="100%"
scrolling="no"></iframe>
Lesson Plan¶
Grade Level¶
Undergraduate / Graduate (College Level)
Duration¶
15–20 minutes
Prerequisites¶
Knowledge graph basics — entity, relation, triple (Chapter 12 intro). Vector operations. Distance functions.
Activities¶
- Train on the composition example: "fatherOf" composed with "fatherOf" should approximate "grandfatherOf". Do the learned relation vectors have this property?
- Load the symmetric preset. After 50 training steps, measure the magnitude of the "borders" relation vector \(\mathbf{r}\). Compare to an asymmetric relation.
- Explain why ComplEx and RotatE overcome the symmetry limitation using complex-valued embeddings.
Assessment Question¶
Define the TransE scoring function \(\|\mathbf{h} + \mathbf{r} - \mathbf{t}\|\). List the four relation patterns (symmetry, antisymmetry, inversion, composition) and state which TransE can and cannot model, with justification.
References¶
- Bordes et al. (2013). Translating Embeddings for Modeling Multi-relational Data. NeurIPS.
- Sun et al. (2019). RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space. ICLR.
Part of Chapter 12: Knowledge Graph Embeddings. Return to the chapter page or browse all MicroSims.