Skip to content

Docs

Cookbook: Hierarchical Classification

Classify documents through deep patent, retail product, biomedical, and source-code hierarchies using parallel beam search over Choice probabilities.
Format
Docs
Reading time
2 min
Published by
TypeSafe AI
Last verified
Sep 2026

Highlights

  • Beam search keeps K=3 paths scored by geometric mean product(p) ** (1/decisions), length-normalized so shallow and deep leaves compare fairly.
  • On four labeled hierarchies, beam K=3 matched 4 of 4 expected leaves while greedy matched 2 of 4, recovering CPC patents and Shopify products.
  • Every sibling set becomes one Choice question keyed c0, c1, ...; each beam path runs as parallel questions so extra exploration barely adds latency.
  • Taxonomies: CPC 2026.05 patents, Shopify 2026-02 products, MeSH 2026 (a DAG expanded into tree paths), and a frozen CookSafe snapshot.
  • Defaults are model jev-1.12, beam width 3, max depth 12, epsilon 1e-9, with RetryPolicy(max_retries=5, backoff_initial=1.0, backoff_max=20.0).

Quickstart

python
@json_cache
def choose(state: str, labels: tuple[str, ...]) -> dict[str, float]:
    if len(labels) == 1:
        return {labels[0]: 1.0}
    question, keys = child_question(labels)
    response = client.system_one(
        state=state, questions={"child": question}, model=MODEL
    )
    probabilities = response.answers["child"].probabilities
    return {label: probabilities[key] for key, label in keys.items()}

Watch out

Greedy search cannot recover an early wrong turn, and for hierarchies deeper than about 10 levels the cookbook recommends exp(mean(log(probs))) over the product formula to avoid precision errors.

Questions about this entry

Short answers drawn from the linked project or page.

From the Jev guides

Original write-ups on what this entry is for.

From the Jev AI model community

Posts from builders shipping with Jev right now.

Follow @typesafeai