---
title: Hierarchy Builder (HB) Framework
url: https://www.emergentmind.com/topics/hierarchy-builder-hb
type: topic
---

# Hierarchy Builder (HB) Framework

Hierarchy Builder (HB) is a name used for several technically distinct hierarchy-construction frameworks in recent research. In one usage, HB converts a flat list of extracted textual spans into a compact, navigable directed acyclic graph (DAG) for exploratory browsing in medical information extraction [2309.10057]. In another, HB denotes an abstract framework of adaptive model hierarchies in which models $M_1,\dots,M_L$ of increasing cost and decreasing error are queried until an a posteriori error criterion is met [2411.17252]. In a third, HB is a packed-class framework on top of Coq’s canonical structures for describing directed acyclic graphs of mathematical structures and inheritance relations, used to formalize adhesive category theory and categorical graph rewriting in Rocq [2509.17392]. The shared name therefore identifies a recurring design motif—the explicit organization of objects into layered or partially ordered form—rather than a single unified formalism.

## 1. Terminological scope

The expression “Hierarchy Builder” does not designate a unique standard architecture across the literature. The three uses summarized here differ in domain, object of organization, and correctness criterion. In the information-extraction setting, the organized objects are textual spans, and the target artifact is a navigable DAG whose structure is driven by lexical containment, semantic similarity, and taxonomic abstraction. In the adaptive-model setting, the organized objects are surrogate or reduced models ordered by fidelity, cost, and certifiable error. In the Rocq setting, the organized objects are mathematical structures and morphism classes arranged by forgetful inheritance inside a packed-class hierarchy.

A common misconception is to equate HB with tree construction. That characterization is inaccurate for two of the three usages. The information-extraction HB explicitly produces a DAG and preserves multiple inheritance; the Rocq HB likewise represents a directed acyclic graph of structures rather than a simple chain. Even in the adaptive-model framework, the operative object is not a tree but an ordered sequence of models together with switching rules and adaptation procedures. This suggests that “hierarchy” is the stable abstraction, while the concrete semantics of nodes and edges are domain-specific.

## 2. HB as a textual-span organizer

In “Hierarchy Builder: Organizing Textual Spans into a Hierarchy to Facilitate Navigation,” HB is a multi-stage pipeline that turns a flat list of textual spans into a compact, navigable DAG [2309.10057]. The workflow begins with hundreds–thousands of extracted noun-phrases. Each phrase is expanded by extracting all meaningful sub-spans, including head nouns and modifiers. Every span $s$ is then preprocessed to remove stop-words, modal words, and quantities, and is lemmatized to define its lemma-bag $L(s)$.

The first consolidation stage is lexical equivalence. Two spans $s_1,s_2$ belong to the same initial group if $L(s_1)=L(s_2)$ up to small edit-distance matches and known spelling variants in UMLS/WordNet. This produces equivalence sets $E_1,\dots,E_n$. Every lexical equivalence set becomes a DAG node, and each span’s head noun or adjective is also introduced as an additional node to support co-mention grouping. A single artificial ROOT is added above all heads so that the graph is connected.

The initial edge relation is specificity by lemma-bag containment. Node $B$ is more specific than node $A$ when they are not equivalent and $A$’s lemma bag is strictly contained in $B$’s lemma bag. An edge $A\to B$ is drawn only when there is no intermediate node $C$ with $A\to C\to B$, yielding what the paper calls a clean “containment DAG.” This graph is subsequently refined by semantic merging. For each equivalence set $E$, the average embedding is
$$
v_E=\frac{1}{|E|}\sum_{s\in E}\mathrm{BERT}(s).
$$
The system traverses the DAG in depth-first order. Direct neighbors are merged when
$$
\mathrm{cosine}(v_{E_i},v_{E_j})=\frac{v_{E_i}\cdot v_{E_j}}{\|v_{E_i}\|\|v_{E_j}\|}\ge t_1=0.90
$$
and merging would not introduce a cycle. A second pass uses $t_2=0.95$ for merging a node with its direct child. Any UMLS-synonym pairs are also merged.

A further enrichment stage injects taxonomy. Each node, via its canonical span, is mapped into UMLS, and UMLS concepts that subsume at least two nodes are collected. If such a concept already appears as a node, the system connects it to descendants where missing, while avoiding cycles. Otherwise, it creates a new node labeled by its most similar synonym and hooks it above its descendant nodes. The resulting DAG is intentionally rich, but it is then pruned to reduce visual and navigational burden while preserving reachability of all original spans.

Pruning is formulated as a set-cover problem. For each node $p$, let $S_1,\dots,S_m$ be the sets of original-span descendants covered by each child. HB chooses a minimal subcollection of children such that
$$
\bigcup_{\text{child } c \text{ chosen}} S_c=\text{all descendants of }p.
$$
Because minimum-cardinality set cover is NP-hard, the system uses the standard greedy set-cover approximation: at each step it picks the child covering the largest number of yet-uncovered spans. After pruning edges, any node with only one child is spliced out by connecting its parent directly to its grandchild.

Entry-point selection gives the hierarchy a browse-oriented top layer. Each candidate node $c$ is scored by
$$
\mathrm{score}(c)=\sum_{i\in \mathrm{desc}(c)} \mathrm{cosine}(v_c,v_i),
$$
where $v_i$ are embeddings of original spans reachable from $c$. HB picks the top-scoring node, subtracts its covered spans’ affinities from the scores of remaining candidates, and repeats until $k$ entry nodes are chosen. In the front end, the user first sees the $k$ entry nodes plus an “Other” bucket. Clicking an entry node expands its children, each node is labeled by its best representative span, and each node shows the number of original-span leaves reachable beneath it. The shallow average depth, approximately $3$, and small average branching factor, approximately $5$–$9$, are presented as the structural basis for bird’s-eye browsing with only a few clicks.

## 3. Medical information extraction deployment and evaluation

The textual-span HB was evaluated on a medical information-extraction task involving causes, or etiologies, of two common conditions: jaundice and chest pain, extracted from approximately $30$M PubMed abstracts [2309.10057]. Extraction used $33$ syntactic patterns via SPIKE and yielded $3{,}389$ raw strings for jaundice and $2{,}464$ for chest pain, collapsing to $2{,}623$ and $2{,}037$ unique strings, respectively. After lexical grouping, these became $2{,}227$ jaundice concepts and $1{,}783$ chest-pain concepts. The known-etiology benchmarks contained $38$ established causes for jaundice and $33$ for chest pain.

Coverage was measured relative to both the flat extraction list and the hierarchy’s entry nodes. The flat list contained $28/38$ jaundice causes and $26/33$ chest-pain causes. With $k=50$ entry nodes, the HB hierarchy made $25/28$ reachable for jaundice and $21/26$ for chest pain; with $k=100$, it yielded full coverage for jaundice, $28/28$, and $24/26$ for chest pain. At $k=50$, the jaundice DAG had $2{,}620$ nodes, depth at most $11$, average children approximately $9.1$, and average entry-leaf distance approximately $2.9$. The chest-pain DAG had $2{,}124$ nodes, depth at most $9$, average children approximately $4.9$, and average entry-leaf distance approximately $2.8$.

Human experts evaluated “effort” to locate known causes by comparing scanning a flat frequency-ranked list with navigating HB. The reported average outcome was that HB reduced effort drastically: most etiologies required far fewer clicks or scans in the DAG than positions in the flat list. Path quality was rated on a $1$–$5$ scale. Among $25$ jaundice paths, $23$ were rated $5$ (“excellent”), $1$ was rated $2$, and $1$ was rated $1$; for chest pain, $19/21$ were rated $5$, $1$ was rated $2$, and $1$ was rated $1$.

The deployment context was a demo in which biomedical researchers could pick a condition such as “chest pain” and browse hundreds of candidate causes in a compact DAG. Specialists reported that the hierarchy surfaces major categories of etiologies, hides near duplicates via merges, and preserves multiple inheritance when an item logically sits under two parents, as in “leg pain” under both Leg and Pain. The last point is important conceptually: the object produced by HB is not a taxonomic tree with unique parentage, but a DAG designed to retain semantically meaningful cross-classification.

## 4. HB as adaptive model hierarchies for multi-query computation

In “Adaptive Model Hierarchies for Multi-Query Scenarios,” HB is an abstract framework for choosing among cheaper and more expensive models on a per-query basis [2411.17252]. The starting point is an expensive “truth” solution operator $S:P\to V$, for example a PDE solve for parameter $\mu\in P$. One constructs $L$ lower-fidelity models $M_1,\dots,M_L$ with strictly increasing cost
$$
C(M_1)<C(M_2)<\cdots<C(M_L),
$$
and strictly decreasing error
$$
E(M_1(\mu),\mu)\ge E(M_2(\mu),\mu)\ge\cdots\ge E(M_L(\mu),\mu).
$$
For each query $\mu$, HB tries models from lowest to highest fidelity and stops as soon as an a posteriori error criterion is met.

The mathematical formulation makes the switching rule explicit. For $\ell=1,\dots,L$, define $M_\ell:P\to V$ or to some lower-dimensional $V_\ell$, with evaluation cost $C_\ell=C(M_\ell)$ and error measure
$$
E_\ell(\mu):=\|M_\ell(\mu)-S(\mu)\|_V.
$$
Each level is equipped with an inexpensive error estimator $\eta_\ell:P\to \mathbb{R}_{\ge 0}$ satisfying
$$
E_\ell(\mu)\le \eta_\ell(\mu)\le C_{\rm eff}\,E_\ell(\mu),
$$
with $C_{\rm eff}$ a moderate constant. Given a global tolerance $\mathrm{TOL}$, HB stops at level $\ell$ if
$$
\eta_\ell(\mu)\le \mathrm{TOL}.
$$
This makes the hierarchy adaptive per request rather than statically fixed at one fidelity level.

The same mechanism is integrated into larger computational loops. In optimization, many evaluations of an objective $J(\mu)=\ell(S(\mu))$ are required; HB returns certified approximations $\hat J(\mu)$ quickly, only calling the expensive model when needed. In Monte Carlo or uncertainty quantification, one draws $N\gg 1$ samples $\mu^{(i)}$, and HB avoids calling $S$ on every sample by replacing most calls with fast surrogates such as $M_1$ or $M_2$. The framework also defines an adaptation routine: when a higher level $M_\ell(\mu)$ with $\ell>1$ is actually evaluated, the pair $(\mu,M_\ell(\mu))$ is appended to a training set $D_{\ell-1}$, and once $|D_{\ell-1}|\ge N_{\rm update}$, model $M_{\ell-1}$ is retrained and the training set may be cleared or pruned.

The performance analysis is likewise hierarchical. If $p_\ell=\mathrm{Prob}[\mathrm{HB}\text{ reaches level }\ell]$, then the average cost is approximately
$$
\mathrm{Cost}_{\rm avg}\approx \sum_{\ell=1}^L p_\ell\cdot C_\ell.
$$
Good hierarchies have $p_1\approx 1$, so $\mathrm{Cost}_{\rm avg}\approx C_1$ plus small overhead. With $C_L=O(N^\alpha)$ and $C_1=O(N^\beta)$ for $\beta\ll \alpha$, the average cost per query is $O(N^\beta+\epsilon N^\alpha)$ with small $\epsilon$. Reported empirical speed-ups include a $5$–$10\times$ speed-up in total runtime for PDE-constrained optimization with two levels while meeting the same objective tolerance, up to $15\times$ reduction in expensive solves for a parabolic PDE Monte Carlo example with three levels, and $8\times$ fewer full-order solves for an optimal-control setting with three levels.

Implementation guidance in the same framework is concrete. Each $M_\ell$ is stored as an object with methods `eval(μ)` and `update(D_ℓ)`. Training sets $D_\ell$ may be kept in a ring buffer or KD-tree for nearest-neighbor selection when pruning. Batch evaluation of many `HB_Query` calls can exploit GPUs or threads, and the error estimators $\eta_\ell$ can be accumulated before falling back one model at a time. A concrete one-iteration example sets $L=2$, $P=[0,1]$, and $\mathrm{TOL}=10^{-2}$, with $M_1$ a linear regression surrogate of cost approximately $1$ ms and $M_2$ a full PDE solver of cost approximately $500$ ms. For query $\mu=0.30$, the surrogate gives $M_1(0.30)=0.512$ with $\eta_1(0.30)=1.5\times 10^{-2}>10^{-2}$, so the system falls back to $M_2(0.30)=0.515$ with true error approximately $2.5\times 10^{-3}\le \mathrm{TOL}$, appends $(0.30,0.515)$ to $D_1$, and retrains $M_1$ by least squares when $|D_1|$ reaches $20$. In that illustrative scenario, after a few such iterations, $80\%$ of future $\mu$ values stop at level $1$, yielding a $50\times$ net speed-up compared to always using $M_2$.

## 5. HB as a packed-class hierarchy builder in Rocq

In “Adhesive category theory for graph rewriting in Rocq,” HB is a “packed-class” framework on top of Coq’s canonical structures for defining a directed acyclic graph of structures by specifying, for each node, the extra data or “mixin” that it adds and the lower nodes from which it inherits [2509.17392]. From these specifications, HB automatically generates a record type for each structure, canonical-structure instances, and coercions. The intended effect is that an adhesive category is also recognized as a category with pullbacks, and similar inheritance relations are reconstructed automatically.

Three design principles are central. First, inheritance is forgetful only: every structure bundles its own mixin together with the mixins of its ancestors, with no implicit ad hoc augmentation of older nodes. Second, builders and factories mediate logical implication between mixins. When one mixin implies another, as with regular mono implying mono, the user supplies a builder lemma so that declaring a regular mono automatically fills the mono data. Factories are “virtual” mixins that do not appear in final structures but allow multiple alternative presentations of the same concept. Third, coercions are user-controlled: HB tracks a single “index” for each hierarchy, namely the object-type in the category hierarchy and the underlying arrow in the morphism hierarchy.

The resulting library contains two parallel hierarchies. In the category-theory hierarchy, the levels are Quiver, PreCategory, Category, CatPb, CatRmPo, RmQAdhesive, RmAdhesive, CatMPo, and Adhesive. In the morphism hierarchy, the levels are Morphism, Iso, SplitMono, SplitEpi, RegMono, RegEpi, Mono, Epi, PreAdh, and Adh. Because HB allows only forgetful inheritance, adhesive morphisms lie above RegMono but below Iso, and the development introduces a separate $\mathrm{Iso}'$ that inherits from both Iso and Adh so that the primitive Iso mixin need not be rewritten.

The definitional backbone is categorical. For a precategory or category $C$, objects $A,B,C,D$, and morphisms $f:A\to C$, $g:B\to C$, a pullback square is defined by
$$
\begin{aligned}
&\mathrm{isPullback}_C(f,g,p,q)\;:=\;f\circ p \equiv g\circ q\;\wedge\\
&\quad\forall E,\,p':E\to A,\;q':E\to B,\;
(f\circ p'\equiv g\circ q')
\;\to\;\exists!\,u:E\to D.\;(p'\equiv p\circ u\;\wedge\;q'\equiv q\circ u).
\end{aligned}
$$
For equalizers, with $f,g:A\to B$ and $e:E\to A$,
$$
\mathrm{isEqualizer}_C(f,g,e)\;:=\;f\circ e\equiv g\circ e\;\wedge\;
\forall E',e':E'\to A,\;(f\circ e'\equiv g\circ e')
\;\to\;\exists!\,\varepsilon:E'\to E.\;e'\equiv e\circ\varepsilon.
$$
A regular mono is then
$$
\mathrm{isRegMono}_C(m)\;:=\;\exists\,B,f,g.\,\mathrm{isEqualizer}_C(f,g,m).
$$

The higher levels specialize these notions. An rm-quasiadhesive category is one with all pullbacks and such that for every regular mono $m:U\hookrightarrow A$ and $g:B\to A$, the pushout of $m$ and $g$ exists, is stable, and is a pullback. An rm-adhesive category is an $\mathrm{RmQAdhesive}$ category in which regular subobjects are closed under binary union. An adhesive category is an $\mathrm{RmQAdhesive}$ category in which every mono is regular and all pushouts along monos exist, are stable, and are pullbacks. At the interface level, HB jargon treats every structure as a sequence of mixins; for example, regular monos are defined through a mixin record `IsRegMono` whose field is `rm_prop : isRegMono m`, and `RegMono` is declared as inheriting both `Mono` and `IsRegMono`, with a builder instance deriving `IsMono` from `IsRegMono`.

## 6. Instances, implementation trade-offs, and graph-rewriting formalization

The Rocq development uses HB to instantiate a range of concrete categorical settings [2509.17392]. The category of extensional Coq types, `TypeCat`, is given an `AdhesiveCategory` instance by supplying pullbacks and constructing pushouts via quotients by the smallest congruence; the proof uses two axioms, `predicate_extensionality` and `constructive_definite_description`. `SetoidCat` is also given an `AdhesiveCategory` instance. No axioms are needed to show it rm-quasiadhesive; to show it rm-adhesive one needs “$P\vee Q \Rightarrow P+Q$”; to show it fully adhesive one needs constructive indefinite description. The category of finite types, `finType`, is obtained by transport along the full-and-faithful forgetful functor `finType → TypeCat`, and because that functor preserves pullbacks, monos, and related structure, one obtains an axiom-free `Adhesive` instance on `finType`.

Other examples delimit the scope of adhesivity. A simple graph is represented as $(V,E:V\to V\to \mathrm{Prop})$, and a homomorphism preserves edges. `SimpleGraphCat` is shown rm-quasiadhesive by reduction to `TypeCat`, but it is not rm-adhesive because of a counter-example pushout that fails to be a pullback. Slice and functor categories inherit structure pointwise: if $D$ has pullbacks, or is adhesive, then $[C\to D]$ and $D/X$ inherit the same structure. In particular, presheaf categories $[(C^{op})\to \mathrm{Set}]$ are (rm-)adhesive.

The implementation choices are explicitly trade-off driven. The library adopts setoid-enrichment rather than strict categories with propositional equality: all hom-sets are setoids, and composition and identity respect the equivalence. This avoids the need for axioms for quotients and for suppressing computational content of “regular mono,” but it requires many `Proper` and `CMorphisms.Proper` instances so that rewriting works up to setoid equivalence in `Type`. The library also maintains both bundled and unbundled forms. Categories, monos, and pullbacks are bundled records, but proofs often need predicate forms such as `isMono f : Prop` or `isPullback f g p q : Type`; conversion lemmas support movement between the two. Duality is encoded by assigning each structure $S$ a dual $S^{op}$ obtained by swapping sources and targets and reversing composites. Since $\mathrm{Iso}_C$ and $\mathrm{Iso}_{C^{op}}$ are propositionally but not definitionally equal, occasional casts are necessary, and an alias `catop : Type→Type` with notation `C^op` is introduced to disambiguate canonical-structure inference.

The stated limitations of HB are equally important for understanding the framework. There is no universe polymorphism, so small and large setoids must be duplicated. HB does not allow adding new downward inheritance edges after the fact, which is why a separate $\mathrm{Iso}'$ was created to sit above `Adh`. Dynamic collapse of classes, such as `Mono ≡ AdhesiveMono` in an adhesive category, is not automatic; promotions must be invoked explicitly via factories and builders. These are not incidental engineering details but structural constraints on the expressivity of the hierarchy description mechanism.

The principal application is the formalization of double-pushout graph rewriting. A linear production is a span of regular monos
```text
I ← K → O
```
and a derivation is represented by two pushout squares. Using the abstract library, the development formalizes the Local Church–Rosser theorem and the Concurrency Theorem from Lack and Sobociński. For Local Church–Rosser (Theorem 7.7), the equivalence “parallel independence ⇔ sequential independence” occupies $2$ pages with $11$ objects per diagram in the paper proof, and $80$ lines of Coq statements plus $78$ lines of proof in Rocq+HB. For the Concurrency Theorem (Theorem 7.10), the paper proof occupies $2½$ pages with $19$ objects per diagram, and the Rocq+HB version uses $107$ lines of statements plus $105$ lines of proof. Because the abstract library itself is axiom-free, with axioms entering only when instantiating the Type category or lifting disjunctions in Setoids, these theorems hold in every rm-quasiadhesive instance without further assumption. The overall development, approximately $10$ k LOC, presents HB as a modular mechanism for declaring large intertwined hierarchies of structures while supporting nontrivial reusable formalization in categorical graph rewriting.

Source: https://www.emergentmind.com/topics/hierarchy-builder-hb