1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Hugging Face

Connected

Exercise

Dynamic category assignment

Dynamic category assignment enables a model to classify text into predefined categories, even without prior training for those categories.

Using Hugging Face’s pipeline() for the zero-shot-classification task, provide the text and predefined categories to identify the best match.

Build a classifier to predict the label for the input text, which is a news headline already loaded for you.

The pipelines from the transformers library is preloaded for your convenience.

Note: We are using a customized version of the pipeline to help you learn how to use these functions without needing to download the model.

Instructions

100 XP
  • Build the pipeline and save as classifier.
  • Create a list of the labels - "politics", "science", "sports" - and save as categories.
  • Predict the label of text using the classifier and predefined categories.