Mohamed Ansar,�Applied Scientist @ Glance AI
E-COMMERCE SEARCH QUERY CLASSIFICATION: A TWO-LEVEL HIERARCHICAL APPROACH USING FINE-TUNED TRANSFORMERS
THE CHALLENGE OF E-COMMERCE SEARCH QUERY CLASSIFICATION
Why understanding user intent at scale is harder than it looks
🗂️�~300 subcategories across 25 categories | ❓ Short and Vague exploratory queries | 🌲 2-level Hierarchy parent→child structure |
The Classification Problem Landscape
Multiple category levels
Large Taxonomy
25 cats / 286 sub
Skewed data distribution
Class Imbalance
Some cats
25x bigger
Short phrase queries
Ambiguous Queries
On avg
3-4 words
Many labels together
Multi-Label Classification
~4% span
2+ classes
JOURNEY AND EXPERIMENTS
Baseline Model → Hierarchical Classification Methods
LLM-Assisted Dataset Labeling for Quality & Coverage
Synthetic Data Generation for Rare Categories
MODEL ARCHITECTURES EXPLORED
End-to-End Fine-Tuning:
Fine-Tuned Encoder + Heads:
Independent Classifiers:
Hierarchical Models:
End-to-End & Encoder Approaches
Independent & Hierarchical Models
KEY FINDING: FINE-TUNED ENCODER + CLASSIFICATION HEADS OUTPERFORMS END-TO-END
❌ Underperformed due to noisy labels and high complexity. Single monolithic model struggled to generalize across 300+ subcategories.
❌ Taxonomy structure not preserved, leading to inconsistent hierarchy mapping.
✅ Separating representation learning from classification improved accuracy.Independent classifiers per category group outperformed a global classifier.
✅ Hierarchical structure preserved, enabling robust multi-label outputs.
End-to-End Fine-Tuning
Fine-Tuned Encoder + Classification Heads
Macro F1 Score Improvement
Same data. Structural changes only.
Finetuned Encoder + Two-Stage
0.78
Finetuned End-to-End Classifier
0.63
Frozen BGE + Two-Stage
0.55
Frozen BGE + Flat Classifier
0.27
MULTI-LABEL CLASSIFICATION IN A HIERARCHICAL SETTING
Handling Simultaneous Category Assignments
SOURCE-BASED CONFIDENCE THRESHOLDING
Real User Queries vs. Synthetic & LLM-Generated Data
Balancing Precision and Recall Across Data Sources
LEVERAGING LLMS FOR LABELING & SYNTHETIC DATA GENERATION
LLM-Assisted Data Enhancement
SYSTEM ARCHITECTURE OVERVIEW
Flow from query input through transformer encoder and classification heads, to LLM-assisted labeling and source-based confidence thresholding, producing final hierarchical category outputs.
PRESERVING HIERARCHY IN CLASSIFICATION
Why Taxonomy Hierarchy Is Critical
Multi-Level Classification & Taxonomy Constraints
IMPORTANCE OF DATA QUALITY OVER MODEL COMPLEXITY
Lessons Learned: Data Drives Performance
KEY TAKEAWAYS
Hierarchy Matters: Model architecture should reflect label taxonomy for accurate, consistent classification
Separate Tasks: Decoupling representation learning from classification heads improves overall performance
Data & Thresholding: Source-based confidence thresholding and high-quality data are critical to success
Extensibility and Future Scope
Low Scale Cost
03
Deeper Layers
02
Add / Remove Labels
01
THANK YOU
FOR YOUR ATTENTION
mohamed.ansar@glance.com
Questions & Feedback Welcome