Taxonomy Refinement¶
See Taxonomy Refinement > Usage for how to run it.
rac4os.taxonomy_refinement.TaxonomyRefinement.ClassificationsSystemAugmenter
¶
Writes a description for each inner category from the labels of its children.
Retrieval compares an item against what a category says about itself, and inner categories usually say very little: a few words of label is thin evidence for an embedding model and thin ground for a generator to judge on. The information is not missing from the taxonomy though, it is in the children, whose labels together delimit what the parent covers. This module makes that implicit scope explicit by writing it out as prose and storing it on the parent.
It is the same idea as candidate augmentation, applied one step earlier: augmentation shows the children to the model at classification time, refinement turns them into a description once, up front.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classification_name
|
str
|
dataset name resolved through |
required |
api_key
|
str
|
credential for the LM provider. |
required |
model
|
str
|
LiteLLM model identifier, e.g. "openai/gpt-4o-mini". |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
classification_system |
HierarchicalClassificationSystem
|
the taxonomy being refined, modified in place. A parent is described from its children, so the hierarchy is what this module works from and a flat system will not do. |
generator |
ChainOfThought
|
the generation step over |
Source code in rac4os/taxonomy_refinement/TaxonomyRefinement.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__init__
¶
Loads the classification system and configures the LM.
This calls dspy.configure globally and does not pin its LM per call, so construct it
in a script of its own rather than alongside classifiers that expect a different
model.
Source code in rac4os/taxonomy_refinement/TaxonomyRefinement.py
enrich_classification_system
¶
After this is through: lookup is updated but _children_register and codes are not
Source code in rac4os/taxonomy_refinement/TaxonomyRefinement.py
get_updated_classification_system
¶
Write every record in the lookup to a JSON file.
The result is a complete dataset in Code shape, which is exactly what the "JSON"
loader reads, so the refined taxonomy comes back as a dataset of its own. Treat the
written file as the output of a refinement run and load it fresh: only the lookup is
updated during the run, while codes and the children register still hold what the
loader produced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
file to write the refined dataset to. |
required |
Source code in rac4os/taxonomy_refinement/TaxonomyRefinement.py
rac4os.taxonomy_refinement.TaxonomyRefinement.GenerateParentDescription
¶
Bases: Signature
Generate a detailed description for a parent category in a hierarchical classification system , based on its own label and the labels of its direct children.
The classification system is a directed acyclic graph in which each node is a code. Parent nodes represent broader, more general concepts; their children represent progressively more specific concepts. A parent's meaning is the union of the concepts covered by its children: every child falls under the parent, and together the children delimit the parent's scope.
Write the detailed description so that it: - Characterizes the parent category as a whole (the general concept it captures), not merely a concatenation of the children. - Reflects the full scope implied by the children, making clear what kinds of items belong to this category. - Stays faithful to the given labels: do not invent subcategories, products, or distinctions that are not supported by the parent or child descriptions. - Is written in the same language as the input labels. - Is a coherent, self-contained prose description usable on its own, without requiring the reader to see the child list.