Hierarchical Contrastive Learning
- Hierarchical contrastive learning is a family of methods that conditions similarity, repulsion, or alignment on explicit hierarchies rather than flat instance spaces.
- Techniques integrate structures like abstract syntax trees, clustering-based prototypes, and multiscale graph pyramids to enhance representation quality and reduce false negatives.
- Empirical studies show that hierarchy-aware contrastive losses improve clustering, retrieval, and classification performance in areas such as vision, language, and medical imaging.
Hierarchical contrastive learning is a family of contrastive representation-learning methods in which similarity, repulsion, or alignment is conditioned on an explicit hierarchy rather than a flat instance space. In the surveyed literature, the hierarchy may be the depth structure of an abstract syntax tree, a hierarchy of prototypes discovered by clustering, a coarse-to-fine spatial taxonomy, a multiscale graph pyramid, a decomposition into globally shared, partially shared, and modality-specific latent factors, or a medical label tree (Wang et al., 2022, Guo et al., 2022, Bhalla et al., 2024, Wang et al., 2022, Li et al., 7 Apr 2026, Khan, 5 Nov 2025). A recurring motivation is that standard contrastive learning is often too flat: it can treat semantically related samples as negatives, ignore nested structure, and produce embeddings that are locally discriminative but poorly aligned with global organization (Guo et al., 2022, Wei et al., 2022, Liu et al., 2022).
1. Hierarchy as the organizing principle
In hierarchical contrastive learning, the hierarchy itself supplies the supervisory geometry. In HELoC, the hierarchy is the abstract syntax tree: node level is the unique path length from the root to the node, and node pairs are partitioned into neighborhood, adjacent hierarchy, and non-adjacent hierarchy according to whether their level difference is $0$, $1$, or greater than $1$ (Wang et al., 2022). In the WikiScenes study, the hierarchy is the directory tree of cathedral concepts; positives are drawn from the same node’s subtree, negatives from sibling nodes, and training proceeds from coarse to fine concepts with a depth-dependent margin (Bhalla et al., 2024). In HHCH and HCSC, the hierarchy is not given directly by labels but is constructed by hierarchical clustering: bottom layers represent finer-grained semantics and higher layers represent coarser semantics, with parent-child links maintained across levels (Wei et al., 2022, Guo et al., 2022).
Other papers generalize the notion further. In graph representation learning, HCL constructs a sequence of coarsened graphs so that contrastive objectives can be applied at multiple graph resolutions rather than only on the original graph (Wang et al., 2022). In HiTeC, the hierarchy spans node-level, hyperedge-level, and subgraph-level representations in text-attributed hypergraphs (Pan et al., 5 Aug 2025). In multimodal HCL, the hierarchy is a lattice of modality subsets: globally shared structure , partially shared pairwise structure , and modality-specific structure (Li et al., 7 Apr 2026). In medical imaging and hierarchical text classification, the relevant hierarchy is an explicit label tree or taxonomy, and the objective is to preserve ancestor-descendant structure in the embedding space (Khan, 5 Nov 2025, Wang et al., 2022).
This diversity suggests that hierarchical contrastive learning is less a single algorithm than a structural principle: pair definitions, losses, prototypes, and encoders are all modified so that the latent geometry reflects a known or discovered hierarchy.
2. Contrastive objectives under hierarchical constraints
A central departure from flat contrastive learning is that negatives are no longer equally negative. HELoC makes this explicit with a triplet formulation in which same-level nodes are positives, different-level nodes are negatives, and the level gap enlarges the margin pressure for negatives farther away in the AST hierarchy. The intended geometry is
The same paper couples this node-relationship optimization with node level prediction, so that embeddings retain enough information to infer AST depth while also respecting graded hierarchical separation (Wang et al., 2022).
Prototype-based variants refine the same idea at the level of clusters. HHCH combines hierarchical instance-wise contrastive learning with hierarchical prototype-wise contrastive learning. At hierarchy level , samples sharing the same ancestor are removed from the negative set, and each instance is also aligned with its ancestor prototype at that level; both objectives are weighted by $1$0, so finer layers receive larger weight than coarser layers (Wei et al., 2022). HiURE reaches a similar conclusion in unsupervised relation extraction: plain InfoNCE preserves local consistency, but exemplar-wise contrastive learning is added so that sentences are pulled toward hierarchical exemplars discovered from the relational feature space rather than merely pushed away from other instances (Liu et al., 2022). HCSC likewise augments both instance-wise and prototypical contrastive learning with hierarchy-aware selective coding, using a tree of dynamically updated prototypes to remove semantically ambiguous negatives (Guo et al., 2022).
A different formulation appears in hierarchy-preserving medical imaging. There, Hierarchy-Weighted Contrastive scales pairwise contributions by shared ancestry depth, using
$1$1
for positives and negatives respectively, where $1$2 is normalized lowest-common-ancestor depth (Khan, 5 Nov 2025). The same framework adds Level-Aware Margin, a prototype hinge loss that separates ancestor groups across levels. This is explicitly geometry-agnostic: Euclidean and hyperbolic distances are both allowed without changing the architectural pipeline (Khan, 5 Nov 2025).
Hierarchical contrastive learning also appears as a decomposition across representational granularity rather than tree depth alone. HiCL for sentence embeddings combines a local segment-level contrastive loss and a global sequence-level contrastive loss through $1$3, while HeCo++ combines cross-view contrast, which extracts invariant factors across views of a heterogeneous graph, with intra-view contrast, which preserves view-specific structure (Wu et al., 2023, Liu et al., 2023). In both cases, hierarchy refers to nested relations among representation levels rather than simply ancestor labels.
3. Constructing hierarchy and encoding structure
Many hierarchical contrastive methods are inseparable from the mechanism that constructs the hierarchy itself. HCSC rebuilds a hierarchy of prototypes before each epoch with bottom-up hierarchical K-means on current image embeddings, so the semantic tree tracks the evolving latent space (Guo et al., 2022). HHCH extends this construction to hyperbolic space, where cluster assignment uses hyperbolic distance and prototype updates use the Einstein midpoint in the Klein model; this is motivated by the claim that tree-like structure incurs less distortion in hyperbolic space than in Euclidean or hypersphere space (Wei et al., 2022). HiURE constructs multi-level exemplars through Hierarchical Propagation Clustering and then stabilizes cross-level interaction with Cross Hierarchy Attention, so that adjacent clustering layers do not evolve independently (Liu et al., 2022).
Other systems internalize hierarchy within the encoder. HELoC introduces the Residual Self-attention Graph Neural Network, whose layers combine a Residual Self-attention Mechanism with a graph-convolution sublayer so that local AST structure and overall AST structure are both captured before hierarchical pretraining objectives are applied (Wang et al., 2022). In hierarchical contrastive motion learning for video, a side motion branch with a Prime Motion Block extracts motion features at multiple backbone levels, and each higher motion level is trained contrastively to predict future motion features at the previous level (Yang et al., 2020). In graph HCL, a learned topology pyramid is produced by Learning to Pool, which couples multi-head attention with GCNII-based value transformation and then contrasts node-level and summary representations at every pooled scale via a multi-channel pseudo-siamese network (Wang et al., 2022).
A further pattern is that hierarchy is often enforced by view design or augmentation. HeCo and HeCo++ define a network schema view and a meta-path view of a heterogeneous information network, and hierarchical contrastive learning is realized by coupling cross-view agreement with intra-view refinement (Liu et al., 2023). HiTeC uses prompt-enhanced text augmentation and semantic-aware hyperedge drop rather than random perturbations, and then adds subgraph-level contrast based on $1$4-walk sampling to capture long-range dependencies in text-attributed hypergraphs (Pan et al., 5 Aug 2025). THCRL, in multi-view clustering, precedes contrastive alignment with a Deep Symmetry Hierarchical Fusion module based on a UNet-like encoder-decoder and then uses averaged $1$5-nearest-neighbor structure to suppress false negatives among likely same-cluster samples (Zhu, 29 Nov 2025).
The common design implication is that hierarchical contrastive learning is rarely just a loss replacement. It is typically paired with a structure-construction mechanism—clustering, pooling, multiview decomposition, semantic augmentation, or coarse-to-fine refinement—that makes the hierarchy operational.
4. Major application families
In source code and language, hierarchical contrastive learning is used to encode structure that flat token or sentence objectives do not directly capture. HELoC learns source-code representations from ASTs and transfers them to code classification, code clone detection, and code clustering (Wang et al., 2022). HiURE uses hierarchical exemplars for unsupervised relation extraction, addressing both gradual drift in clustering-based pipelines and over-separation in flat instance-wise contrastive learning (Liu et al., 2022). HGCLR injects label hierarchy into a BERT encoder by generating hierarchy-guided positive samples for hierarchical text classification, with the explicit aim that the enhanced text encoder can dispense with the hierarchy at inference time (Wang et al., 2022). HiCL, by contrast, addresses unsupervised sentence embeddings through a local/global split over segments and sequences, improving training efficiency as well as representation quality (Wu et al., 2023).
In vision, video, and restoration, hierarchy frequently takes the form of multiscale or coarse-to-fine organization. Hierarchical contrastive motion learning for action recognition starts from reconstruction-based low-level motion cues and trains higher-level motion features to predict future lower-level motion features, thereby bridging low-level movement and high-level semantic dynamics (Yang et al., 2020). The WikiScenes work treats dataset structure as a weakly supervised modality and uses a depth-dependent triplet margin to organize cathedral representations from coarse spatial concepts to fine components (Bhalla et al., 2024). In dehazing, HCD combines a hierarchical dehazing network with a hierarchical contrastive loss defined over restored outputs, clean images, and hazy inputs at three scales (2212.11473). In blind corruption detection, a coarse mask is first predicted in low-resolution feature space, uncertain pixels are identified, and higher-resolution contrastive learning refines only those ambiguous regions (Feng et al., 2023). In medical imaging, hierarchy-preserving contrastive learning uses taxonomy-aware pair weighting and level-aware margins so that sibling classes remain closer than distant branches (Khan, 5 Nov 2025). HCL-FF brings a related idea to the Forward-Forward algorithm by assigning coarse super-classes to shallow layers and finer labels to deeper layers, while supervised contrastive learning restores class-discriminative structure after goodness decoupling (Yao et al., 24 May 2026).
Graph-structured data form another major cluster of applications. HCL for graph representation learning contrasts representations across pooled graph scales (Wang et al., 2022). HeCo++ learns both shared and view-specific semantics in heterogeneous graphs through cross-view and intra-view contrast (Liu et al., 2023). HiTeC extends hypergraph self-supervision from node- and hyperedge-level objectives to subgraph-level contrast (Pan et al., 5 Aug 2025). HGCL for recommendation first pre-trains a graph-contrastive encoder on the original user-item graph, then constructs a two-hierarchy user-item bipartite graph by clustering items, and finally fine-tunes on both item-level and cluster-level interactions (Xue et al., 25 May 2025).
Retrieval, hashing, clustering, and multimodal representation learning provide further variants. HHCH uses hyperbolic hierarchical contrastive hashing for unsupervised retrieval, combining hierarchical instance-wise and prototype-wise losses with quantization (Wei et al., 2022). THCRL addresses the “untrustworthy fusion” problem in multi-view clustering by making same-cluster neighborhoods, rather than only same-instance cross-view pairs, influence the contrastive denominator (Zhu, 29 Nov 2025). Multimodal HCL departs from the usual shared-private split by learning globally shared, partially shared, and modality-specific structure within one contrastive framework, with identifiability and recovery guarantees stated under uncorrelated latent variables (Li et al., 7 Apr 2026).
5. Empirical regularities and evaluation practice
Across these papers, one empirical regularity is that hierarchy is used to reduce false negatives and to make latent geometry more faithful to known or discovered structure. HELoC reports that nodes with greater AST-level differences become farther apart in the embedding space, a claim supported by t-SNE visualization (Wang et al., 2022). The WikiScenes study likewise uses t-SNE to show clearer separation among “interior,” “exterior,” and “views” than comparable weakly supervised and baseline methods (Bhalla et al., 2024). HiURE reports tighter, more discriminative clusters when hierarchical exemplar discovery and exemplar-wise contrastive learning are both present, and HCL for graphs uses visualization to argue that multi-scale contrastive objectives produce more compact graph clusters than fixed-scale baselines (Liu et al., 2022, Wang et al., 2022).
Quantitative gains are also reported, although evaluation protocols differ by domain. HiCL improves the prior top-performing SNCSE setting by an average of $1$6 on BERT-large and $1$7 on RoBERTa-large across seven STS tasks (Wu et al., 2023). HCL-FF reports accuracy gains of $1$8, $1$9, and $1$0 on CIFAR-10, CIFAR-100, and Tiny-ImageNet relative to prior FF-based methods (Yao et al., 24 May 2026). HCSC reaches $1$1 top-1 accuracy on ImageNet linear evaluation and $1$2 with multi-crop (Guo et al., 2022). HGCL reports the best Recall@20 / NDCG@20 on Yelp2018, Amazon-Kindle, and Alibaba-iFashion, with $1$3, $1$4, and $1$5 respectively (Xue et al., 25 May 2025). HiURE reports average improvements over EIURE of about $1$6 B$1$7 F1, $1$8 V-measure F1, and $1$9 ARI across NYT+FB and TACRED (Liu et al., 2022).
Evaluation itself becomes hierarchy-aware in some of the most recent work. The medical-imaging framework explicitly argues that flat top-1 accuracy is insufficient and adds HF1, H-Acc, and parent-distance violation rate as metrics tailored to taxonomy faithfulness (Khan, 5 Nov 2025). That shift is conceptually important: once hierarchy becomes a first-class training signal, it also becomes an evaluation target.
6. Limitations, trade-offs, and recurring points of confusion
A frequent point of confusion is to equate hierarchical contrastive learning with any one particular source of supervision. The surveyed work shows otherwise. Some methods use explicit label trees or taxonomies, but others derive hierarchy from AST depth, directory structure, hierarchical clustering, multiscale pooling, or subset-specific modality sharing (Wang et al., 2022, Bhalla et al., 2024, Wang et al., 2022, Li et al., 7 Apr 2026). Another confusion is to identify hierarchy preservation with hyperbolic geometry alone. HHCH argues that hyperbolic space embeds hierarchies with lower distortion than Euclidean or hypersphere space, and its ablation reports better mAP for hyperbolic embedding than hyper-sphere embedding (Wei et al., 2022). By contrast, the medical-imaging framework states that HWC and LAM are geometry-agnostic and remain effective without curvature, although hyperbolic embeddings help more on deeper taxonomies such as iNaturalist (Khan, 5 Nov 2025).
The main technical trade-offs concern hierarchy quality, hierarchy depth, and computational overhead. The WikiScenes study reports that training on intermediate layers alone does not help much and attributes this to inconsistent tree depth across cathedrals; it further notes that the current margin schedule uses a global 0, and suggests that a more adaptive per-instance depth schedule might work better (Bhalla et al., 2024). The feature-identification approach to hierarchical multi-label contrastive learning assumes that the number of hierarchy levels is known, especially in the GMM-based method, and proposes a Dirichlet process extension as future work (Ott et al., 1 Oct 2025). HHCH notes that deeper hierarchies help, but not monotonically, and that too many prototypes or too deep a hierarchy increases overhead without guaranteed gains (Wei et al., 2022). HGCL states that it has not been validated on very large industrial-scale datasets with millions of nodes (Xue et al., 25 May 2025). THCRL remains dependent on 1-NN graph quality, and HiTeC’s two-stage design improves scalability precisely because it is not fully joint (Zhu, 29 Nov 2025, Pan et al., 5 Aug 2025).
A broader implication is that hierarchical contrastive learning inherits two simultaneous burdens: it must learn a representation, and it must either trust, discover, or refine a hierarchy. When the hierarchy is reliable, papers repeatedly report gains in discriminability, clustering quality, retrieval quality, or taxonomy faithfulness. When the hierarchy is noisy, shallow, inconsistent, or expensive to construct, the hierarchy itself becomes the primary bottleneck. The field’s more recent directions therefore emphasize adaptive hierarchy logic, structure-aware augmentations, task-specific hierarchy metrics, and stronger guarantees for partial sharing and latent recovery rather than relying on a fixed flat contrastive template (Bhalla et al., 2024, Li et al., 7 Apr 2026, Khan, 5 Nov 2025).