The Natural Geometry of Code: Hyperbolic Representation Learning for Program Reasoning
Weilin Zhou
Abstract
State-of-the-art models for code representation, such as GraphCodeBERT, embed the hierarchical structure of source code into Euclidean space. This approach can lead to significant representation distortion, especially when embedding deep or highly branched hierarchies,limiting the models' ability to capture deep program semantics. We argue that the natural geometry for code is hyperbolic, as its exponential volume growth perfectly matches the tree-like structure of a code's Abstract Syntax Tree (AST), enabling low-distortion hierarchical embeddings. We introduce HypeCodeNet, a geometric deep learning framework that operates natively in hyperbolic space. Formulated in the numerically stable Lorentz model, its manifold-aware components include a hyperbolic embedding layer, a tangent space message-passing mechanism, and a geodesic-based attention module. On code clone detection, code completion, and link prediction, HypeCodeNet significantly outperforms existing Euclidean models, especially on tasks requiring deep structural understanding. Our work suggests that hyperbolic geometry offers a geometrically sound foundation for code representation, establishing hyperbolic geometry as a key to unlocking the structured semantics of code.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext b8a518be-00b4-4338-9220-159b26ff19a7Builds on6
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
- Hyperbolic Neural Networks++Ryohei Shimizu, Yusuke Mukuta, Tatsuya HaradaICLR 2021 · 791 citations
- Learning and Evaluating Contextual Embedding of Source CodeAditya Kanade, Petros Maniatis, Gogul Balakrishnan, Kensen ShiICML 2020 · 438 citations
- Mixed-curvature Variational AutoencodersOndrej Skopek, Octavian-Eugen Ganea, Gary BécigneulICLR 2020 · 122 citations
- Hyperbolic Representation Learning: Revisiting and AdvancingMenglin Yang, Min Zhou, Rex Ying, Yankai Chen et al.ICML 2023 · 41 citations
Related papers
- Lorentzian Graph Convolutional NetworksYiding Zhang, Xiao Wang, Chuan Shi, Nian Liu et al.WWW 2021 · 119 citations
- Fully Hyperbolic Neural NetworksWeize Chen, Xu Han, Yankai Lin, Hexu Zhao et al.ACL 2022
- Discrete-time Temporal Network Embedding via Implicit Hierarchical Learning in Hyperbolic SpaceMenglin Yang, Min Zhou, Marcus Kalander, Zengfeng Huang et al.KDD 2021 · 101 citations
- Hypformer: Exploring Efficient Transformer Fully in Hyperbolic SpaceMenglin Yang, Harshit Verma, Delvin Ce Zhang, Jiahong Liu et al.KDD 2024 · 14 citations
- Hyperbolic Dataset DistillationWenyuan Li, Guang Li, Keisuke Maeda, Takahiro Ogawa et al.NeurIPS 2025 · 17 citations
