Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Hierarchical labels: parent closure and multi-label meaning

Last updated: 6 Oct 20265 min read
tutorial
AdvancedBy AITrove Editorial

A ticket can belong to several branches of a taxonomy. Child labels require their parents, but parent-only cases remain valid.

Define the taxonomy as versioned data

A support ticket might be tagged Billing → Refund and also Account → Access. A flat single-choice target loses one issue. Store stable label IDs, parent links, effective dates and a policy for parent-only labels. The displayed name may change without changing the ID. Do not infer that every parent has exactly one child; “Billing” may be the most specific supported answer. The general label contract defines provenance for reviewed examples.

Close predicted paths deliberately

If a model predicts Refund, add Billing to the output set, or reject the inconsistent prediction under the task policy. Do not count an inferred parent as separately observed evidence. A graph taxonomy may permit multiple parents, so traverse all ancestors and detect cycles before release. Keep predicted labels, derived ancestors and reviewer labels distinguishable. This matters when analytics count how many tickets were explicitly about Billing versus inherited from a child.

Calibrate by branch

Rare leaves have few examples and can be confused with common siblings. Use thresholds by branch and allow a parent-only or review outcome when child evidence is weak. Compare precision and recall at each depth, exact path accuracy and wrong-branch cost. A model that predicts broad parents well may still route specialist queues badly. Threshold and migration review covers release changes.

Evaluate across changes

Group related conversations before splitting. Audit label co-occurrence, child-parent consistency and disagreement on parent-only cases. A taxonomy revision can change training targets even if text is unchanged; freeze the version during model comparison. The applied routing project tests a ticket with two valid branches and a costly false specialist handoff.

Implementation

python
def close_ancestors(predicted_labels, parent_by_label):
    result = set(predicted_labels)
    frontier = list(predicted_labels)
    while frontier:
        label = frontier.pop()
        parent = parent_by_label.get(label)
        if parent is not None and parent not in result:
            result.add(parent)
            frontier.append(parent)
    return result

parents = {"refund": "billing", "billing": "support",
           "access": "account", "account": "support"}
assert close_ancestors({"refund", "access"}, parents) == {
    "refund", "billing", "access", "account", "support"}

Performance and operating cost

Ancestor closure visits each reachable label once, O(v + e) time and O(v) space for v labels and e parent links. Validate the taxonomy for cycles before serving; a visited set prevents this code from looping but does not make a cyclic taxonomy meaningful. Model inference and specialist review dominate routing cost.

Common Mistakes

  • Forcing a ticket into one leaf when two issues are present.
  • Treating a derived parent as an independent model prediction.
  • Rejecting valid parent-only cases because no child was selected.
  • Comparing model scores across different taxonomy versions.

Read next

ai-data
natural-language-processing
Storage details