Skip to main content

snorkelflow_extensions.taxonomy_distillation.models.openai.OpenAITeacherFewShotHTC

class snorkelflow_extensions.taxonomy_distillation.models.openai.OpenAITeacherFewShotHTC(taxonomy: Taxonomy, config: Dict[str, Any])

Bases: TeacherHTC

OpenAI-based teacher model using few-shot prompting for hierarchical text classification.

This implementation leverages OpenAI’s language models with few-shot learning to generate classification labels for training student models. For each classification decision, the model provides examples from each category to improve classification accuracy and consistency across the taxonomy hierarchy.

The few-shot approach automatically selects representative examples from the taxonomy categories and formats them into prompts that guide the language model toward making accurate hierarchical classifications.

__init__

__init__(taxonomy: Taxonomy, config: Dict[str, Any])

Initialize the teacher model. :param taxonomy: The taxonomy data class instance to use. :param config: The configuration dictionary. The configuration dictionary should contain the following keys:

  • teacher_model: The teacher model configuration dictionary. The teacher model configuration dictionary should contain the following keys:

    -name: The name of the teacher model. -params: The keyword arguments to pass to the teacher model.

Methods

__init__(taxonomy, config)Initialize the teacher model. :param taxonomy: The taxonomy data class instance to use. :param config: The configuration dictionary. The configuration dictionary should contain the following keys: - teacher_model: The teacher model configuration dictionary. The teacher model configuration dictionary should contain the following keys: -name: The name of the teacher model. -params: The keyword arguments to pass to the teacher model.
classify_text(text)Classify the text.
classify_texts(texts)Classify a list of texts.
create_few_shot_classification_prompt(...[, ...])Create a prompt for few-shot classification using the provided taxonomy and classes.
create_zero_shot_cot_answer_extraction_prompt(...)Create a prompt for zero-shot cot answer extraction.
create_zero_shot_cot_reasoning_extraction_prompt(text)Create a prompt for zero-shot cot reasoning extraction.
fill_system_prompt_template(...)Fill the system prompt template with the property and classes.
internal_classify_text(text, ...)Internal method to classify the text.

internal_classify_text

internal_classify_text(text: str, current_property: Property, classes: List[str]) Tuple[str, str]

Internal method to classify the text. :param text: The text to classify. :param current_property: The current property to classify the text under. :param classes: The classes to classify the text under.

Returns: The classification result and raw response.