Use hierarchical labels for structured classification
mainGLiClass supports hierarchical label structures using dot notation. You can pass a dictionary where keys are parent labels and values are lists of sub-labels.
If you set return_hierarchical=True, the output will be a nested dictionary matching your input structure instead of a flat list of dot-notated strings.
hierarchical_labels = {
"sentiment": ["positive", "negative", "neutral"],
"topic": ["product", "service", "shipping"]
}
text = "The product quality is amazing but delivery was slow"
# Returns flat dot-notation labels: 'sentiment.positive', etc.
results = pipeline(text, hierarchical_labels, threshold=0.5)[0]
# Returns nested dictionary structure
results_nested = pipeline(text, hierarchical_labels, return_hierarchical=True)[0]