TopicClassification

API reference for TopicClassification

TopicClassification

Evaluator to classify text topics using Fiddler’s zero-shot topic classification model.

The TopicClassification evaluator uses Fiddler’s implementation of the mortizlaurer/roberta-base-zeroshot-v2-0-c model to classify text content into predefined topic categories. This evaluator helps identify the main subject matter or theme of text content, providing both topic labels and confidence scores for topic classification.

Key Features:

  • Topic Classification: Classifies text into predefined topic categories

  • Dual Score Output: Returns both topic label and probability confidence

  • Zero-Shot Model: Uses mortizlaurer/roberta-base-zeroshot-v2-0-c for flexible topic classification

  • Multi-Score Output: Returns both topic name and probability scores

Topic Categories Evaluated:

  • top_topic: The predicted topic name from the provided topics list

  • top_topic_prob: Probability score (0.0-1.0) for the predicted topic

Use Cases:

  • Content Categorization: Automatically organizing content by topic

  • Document Classification: Sorting documents by subject matter

  • News Analysis: Categorizing news articles by topic

  • Customer Support: Routing tickets by topic or issue type

  • Content Moderation: Identifying content themes for policy enforcement

Scoring Logic: : The topic classification provides two complementary scores:

  • top_topic: The predicted topic name from the provided topics list

    • Selected from the topics provided during initialization

    • Represents the most relevant topic for the input text

  • top_topic_prob: Confidence score (0.0-1.0) for the prediction : - 0.0-0.3: Low confidence in topic prediction

  • 0.3-0.7: Medium confidence in topic prediction

  • 0.7-1.0: High confidence in topic prediction

Parameters

Parameter
Type
Required
Default
Description

topics

list[str]

None

List of topic categories to classify text into.

Returns

A list of Score objects containing: : - top_topic: Score object with predicted topic name

  • top_topic_prob: Score object with probability score (0.0-1.0) Return type: list[Score]

Raises

ValueError – If the text is empty or None, or if no scores are returned from the API.

Example

This evaluator uses zero-shot classification, meaning it can classify text into any set of topics provided during initialization without requiring training data for those specific topics. The mortizlaurer/roberta-base-zeroshot-v2-0-c model is particularly effective for general-purpose topic classification across diverse domains. The dual-score output provides both categorical classification and confidence assessment for robust topic analysis workflows.

name = 'topic_classification'

Initialize the TopicClassification evaluator.

Parameters

Parameter
Type
Required
Default
Description

topics

list[str]

None

List of topic categories to classify text into.

Raises

ValueError – If the topics are empty or None.

score()

Score the topic classification of text content.

Parameters

Parameter
Type
Required
Default
Description

text

str

None

The text content to evaluate for topic classification.

Returns

A list of Score objects for topic name and probability. Return type: list[Score]

Last updated

Was this helpful?