snorkelflow_extensions.taxonomy_distillation.models.huggingface.HuggingFaceTeacherFewShotHTC
- class snorkelflow_extensions.taxonomy_distillation.models.huggingface.HuggingFaceTeacherFewShotHTC(taxonomy: Taxonomy, config: Dict[str, Any])
Bases:
TeacherHTC
Hugging Face-based teacher model using few-shot prompting for hierarchical text classification.
This implementation uses Hugging Face’s inference endpoints and language models with few-shot learning to generate classification labels. The model provides examples from each taxonomy category to guide classification decisions and maintain consistency across the hierarchical structure.
Requires a Hugging Face API key for authentication with model endpoints. Supports various Hugging Face language models through the inference API for scalable teacher-student distillation workflows.
- __init__(taxonomy: Taxonomy, config: Dict[str, Any])
Initialize the teacher model. Huggingface teacher models may require an API key to be set in the HUGGINGFACE_API_KEY environment variable. :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.
\_\_init\_\_
__init__
Methods
__init__
(taxonomy, config)Initialize the teacher model. Huggingface teacher models may require an API key to be set in the HUGGINGFACE_API_KEY environment variable. :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(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.
internal\_classify\_text
internal_classify_text