knot2vec
Embeddings for knot diagrams. Two diagrams of the same knot, however tangled, should land close together; diagrams of different knots should land apart. Part of Weird2Vec, embedding models for data nobody embeds.
What is a knot diagram? A knot is a closed loop in space. Drawn on paper it becomes a diagram: a curve with crossings, each marked over or under. The same knot has infinitely many diagrams, related by Reidemeister moves. Telling whether two diagrams show the same knot is hard; this model learns a fast, approximate answer.
Two tangles the model names correctly. Results below say how often that happens. Try your own in the demo.
🚀 Usage
The repo holds the script that trained the model, so one command embeds a PD code and names the nearest catalogued knots:
uv run https://huggingface.co/jgalego/knot2vec/resolve/main/knot2vec.py embed --pd "[[1,5,2,4],[3,1,4,6],[5,3,6,2]]"
It prints the five nearest of the 12,965 prime knots up to 13 crossings, guesses for signature, determinant and hyperbolic volume, and the 256-dimensional embedding.
🧶 Data
jgalego/knot2vec-diagrams: every prime knot up to 13 crossings in KnotInfo, with invariants, and diagrams of each knot scrambled by random Reidemeister moves in SnapPy. 10% of the knots are held out of training entirely.
🏋️ Training
A diagram becomes its Gauss sequence: walk the knot and, at each crossing, record whether the strand passes over or under and the crossing's sign. Crossings are named by first visit and the walk starts at a random edge. A transformer encodes the sequence, and a contrastive loss pulls two scrambles of the same knot together against the rest of the batch. Small heads predict signature, determinant and volume.
| Parameters | 4,974,095 (6 layers, width 256) |
| Steps | 10000, 512 knots (two diagrams each) per step |
| Learning rate | 0.0001, cosine; temperature 0.05 |
| Final loss | 1.1689 (contrastive 0.5045) |
| Hardware | NVIDIA A10G, 92 min |
📊 Results
Each test diagram is a fresh scramble. The model names it by the nearest canonical KnotInfo diagram among all 12965 knots. Seen knots were in training, as other diagrams; unseen knots never were.
| Knots | n | Top-1 | Top-5 | Signature | Determinant ±10% | Volume MAE |
|---|---|---|---|---|---|---|
| seen | 46676 | 0.874 | 0.978 | 0.926 | 0.264 | 1.21 |
| unseen | 5184 | 0.867 | 0.976 | 0.896 | 0.246 | 1.373 |
Chance top-1 is 7.7e-05. For an exact answer, use SnapPy's identify().
Every catalogued knot's embedding, flattened with UMAP and coloured by signature. The map is ordered by signature, from positive to strongly negative.
⚠️ Limitations
- Prime knots up to 13 crossings only, and only the chirality KnotInfo lists; a mirror image is a different input.
- Use it to shortlist candidates, then confirm with an exact tool such as SnapPy.
- Diagrams over 64 crossings are out of range.
📚 Related work
The closest work is Halverson & Ruehle (2025), who train contrastive and generative models to embed braid words of the same knot at the same point. Knot2Vec works on PD codes scrambled by Reidemeister moves instead, covers every prime knot up to 13 crossings, and holds out 10% of the knots.
Articles
- Applebaum, T., Blackwell, S., Davies, A., Edlich, T., Juhász, A., Lackenby, M., Tomašev, N., & Zheng, D. (2024). The unknotting number, hard unknot diagrams, and reinforcement learning (arXiv:2409.09032). arXiv. https://doi.org/10.48550/arXiv.2409.09032
- Craven, J., Hughes, M., Jejjala, V., & Kar, A. (2022). (K)not machine learning (arXiv:2201.08846). arXiv. https://doi.org/10.48550/arXiv.2201.08846
- Davies, A., Juhász, A., Lackenby, M., & Tomašev, N. (2024). The signature and cusp geometry of hyperbolic knots. Geometry & Topology, 28(5), 2313–2343. https://doi.org/10.2140/gt.2024.28.2313
- Davies, A., Veličković, P., Buesing, L., Blackwell, S., Zheng, D., Tomašev, N., Tanburn, R., Battaglia, P., Blundell, C., Juhász, A., Lackenby, M., Williamson, G., Hassabis, D., & Kohli, P. (2021). Advancing mathematics by guiding human intuition with AI. Nature, 600(7887), 70–74. https://doi.org/10.1038/s41586-021-04086-x
- Gukov, S., Halverson, J., Ruehle, F., & Sułkowski, P. (2021). Learning to unknot. Machine Learning: Science and Technology, 2(2), 025035. https://doi.org/10.1088/2632-2153/abe91f
- Halverson, J., & Ruehle, F. (2025). Learning topological invariance (arXiv:2504.12390). arXiv. https://doi.org/10.48550/arXiv.2504.12390
- Hughes, M. C. (2020). A neural network approach to predicting and computing knot invariants. Journal of Knot Theory and Its Ramifications, 29(3), 2050005. https://doi.org/10.1142/S0218216520500054
- Jaretzki, L. (2023). Geometric deep learning approach to knot theory (arXiv:2305.16808). arXiv. https://doi.org/10.48550/arXiv.2305.16808
- Jejjala, V., Kar, A., & Parrikar, O. (2019). Deep learning the hyperbolic volume of a knot. Physics Letters B, 799, 135033. https://doi.org/10.1016/j.physletb.2019.135033
- Mihajlovic, D., & Michieletto, D. (2026). Shortcut learning in geometric knot classification (arXiv:2602.17350). arXiv. https://doi.org/10.48550/arXiv.2602.17350
- Piccirillo, L. (2020). The Conway knot is not slice. Annals of Mathematics, 191(2), 581–591. https://doi.org/10.4007/annals.2020.191.2.5
- Sleiman, J. L., Conforto, F., Fosado, Y. A. G., & Michieletto, D. (2024). Geometric learning of knot topology. Soft Matter, 20(1), 71–78. https://doi.org/10.1039/D3SM01199B
Data and software
- KnotInfo: table of knot invariants by C. Livingston and A. H. Moore, and its Python package database_knotinfo.
- SnapPy: M. Culler, N. M. Dunfield, M. Goerner and J. R. Weeks' program for the topology and geometry of 3-manifolds, with the spherogram link library.
Blogs and press
- DeepMind (2021). Exploring the beauty of pure mathematics in novel ways.
- IAIFI (2025). Learning topological invariance.
- IAIFI. Learning to unknot.
- Klarreich, E. (2020). Graduate student solves decades-old Conway knot problem. Quanta Magazine.
- Quanta Magazine (2022). Why mathematicians study knots.
- Downloads last month
- 114
