tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Hugging Face > Zero-Shot Text Classification with Hugging Face

Zero-Shot Text Classification with Hugging Face

Author: Venkata Sudhakar

Zero-shot classification assigns text to categories without any labelled training data. ShopMax India uses it to instantly route incoming customer queries - refund requests, delivery complaints, product questions - into the right support queue without needing to collect and label training examples first. New categories can be added just by naming them.

Hugging Face provides a zero-shot-classification pipeline backed by NLI (Natural Language Inference) models like facebook/bart-large-mnli. The model treats each candidate label as a hypothesis and the input text as a premise, scoring how likely the text entails each label. Setting multi_label=True allows a single input to match multiple categories simultaneously.

The example below classifies ShopMax India customer queries into support categories without any prior training, using only descriptive label names.


It gives the following output,

Query: I want my money back. The laptop I ordered is not working.
Category: refund request (78.3%)

Query: My order from Chennai warehouse has not arrived in 10 days.
Category: delivery complaint (91.2%)

Query: Can I pay using UPI for orders above Rs 50000?
Category: payment issue (84.7%)

Zero-shot classification is ideal for ShopMax India when launching a new support category - just add the label string, no retraining needed. For higher accuracy on repeated high-volume categories, collect labelled examples over time and fine-tune a dedicated classifier. Watch inference latency: BART-large is slow on CPU. Use the smaller cross-encoder/nli-MiniLM2-L6-H768 model for production deployments where speed matters.


 
  


  
bl  br