Use multi-label classification with thresholds
mainBy default, .classification() performs single-label classification (returning a single string). To allow multiple labels to be assigned to a single text, set multi_label=True.
You can also control which labels are returned by setting a cls_threshold. Only labels with a confidence score above this threshold will be included in the output list.
schema = (extractor.create_schema()
# Single-label classification
.classification("primary_topic", ["tech", "business", "health", "sports", "politics"])
# Multi-label classification with a threshold
.classification("emotions",
["happy", "sad", "angry", "surprised", "fearful", "disgusted"],
multi_label=True,
cls_threshold=0.4
)
)
text = "URGENT: I'm thrilled to announce our new product!"
results = extractor.extract(text, schema)
# 'emotions' will return a list of labels meeting the threshold