Hierarchical Query Classification in E-commerce Search

Bing He, Sreyashi Nag, Limeng Cui, Suhang Wang, Zheng Li 0018, Rahul Goutam, Zhen Li, Haiyang Zhang

Introduction

In modern e-commerce, the ability to accurately categorize search queries into a hierarchical taxonomy is fundamental to both user experience and platform safety. Whether identifying "sensitive" queries—such as those related to self-harm or restricted items—or simply improving product discovery, classification systems must navigate complex taxonomies. However, traditional classification methods often struggle with the unique constraints of search data.

This paper, presented at the WWW '24 Conference, introduces a novel semi-supervised framework designed to address these challenges. By integrating hierarchical contrastive representation learning with a "neighborhood-aware" sampling strategy for unlabeled data, the authors provide a robust solution for classifying short, ambiguous, and highly imbalanced search queries.

Query classification in e-commerce faces two primary hurdles:

  1. Extreme Class Imbalance: In safety-critical contexts, sensitive categories may represent less than 0.15% of total query volume. Standard models often optimize for majority classes, effectively ignoring these critical minority categories.
  2. Brevity and Ambiguity: The average search query consists of only three words. This lack of linguistic context makes it difficult for models to discern intent, especially when queries are typographically similar but semantically distinct.

While existing methods often treat labels as flat categories, this research posits that the hierarchical structure of the taxonomy itself contains valuable information that can be leveraged to improve classification accuracy.

Methodology: A Three-Pillar Framework

The proposed framework utilizes three distinct strategies to enrich the model's understanding of both the data and the labels.

1. Label Hierarchy and Semantic Enrichment

Rather than treating labels as opaque identifiers, the model treats them as semantic data. Using BERT, the framework embeds the text of the labels (e.g., "Adult Content" or "Electronics > Mobile Phones"). A Graph Convolutional Network (GCN) is then employed to capture the structural relationships between parent and child categories. Finally, an attention mechanism weighs these enriched label features against the query embedding, providing the model with a "semantic map" of the taxonomy.

2. Instance Hierarchy via Contrastive Learning

To improve the model's discriminative power, the authors implement contrastive loss at two levels:

  • Intra-class Contrast: The model learns to pull together queries from the same child category while pushing apart queries from different child categories that share a parent.
  • Inter-class Contrast: The model pulls together queries from the same parent category while pushing apart queries from entirely different branches of the taxonomic tree.

3. Neighborhood-aware Sampling

To leverage the vast amount of unlabeled search logs, the framework uses a semi-supervised approach. It identifies unlabeled queries that are "neighbors" to labeled ones using a combination of K-Nearest Neighbors (KNN) and Edit Distance. If an unlabeled query’s predicted label aligns with the labels of its neighbors, it is deemed "high-quality" and incorporated into the training set for subsequent iterations of self-training.

Experimental Evaluation

The framework was evaluated against three datasets: a proprietary Amazon dataset (9–10 million queries), the Web of Science (WoS) academic dataset, and the RCV1-V2 news dataset.

On the Amazon dataset, which is characterized by extreme imbalance (some categories appearing in only 0.003% of the data), the proposed method significantly outperformed the fine-tuned BERT baseline, achieving a +3.26 increase in Micro-F1 and a +4.10 increase in Macro-F1. It also surpassed specialized hierarchical models such as HiTIN and HGCLR.

Ablation studies revealed that the "Label Hierarchy" component was the most critical factor; its removal led to the most significant performance degradation, confirming that the semantic meaning of the taxonomy is a vital signal for short-form query classification.

Discussion and Future Directions

While the framework sets a new benchmark for hierarchical query classification, the authors note several avenues for future research. The current system is a multi-stage pipeline, and transitioning to a single end-to-end "plug-and-play" model would improve usability. Additionally, the authors suggest exploring adversarial training to mitigate "evasion" tactics where users intentionally misspell words to bypass safety filters.

Finally, while the model outperformed ChatGPT in preliminary tests on the WoS dataset, the researchers emphasize the need for continued, rigorous comparison with evolving Large Language Models (LLMs) and the development of few-shot learning techniques to reduce the reliance on expensive annotated data.

Conclusion

By treating labels as semantic data and exploiting the inherent hierarchy of e-commerce taxonomies, this framework provides a powerful tool for managing the "long tail" of search queries. Its success in boosting Macro-F1 scores demonstrates that even in the face of extreme class imbalance and query brevity, structural and semantic context can lead to significant gains in classification performance.

Summary updated

BibTeX
@inproceedings{he2024hierarchical,
  author = {Bing He and Sreyashi Nag and Limeng Cui and Suhang Wang and Zheng Li and Rahul Goutam and Zhen Li and Haiyang Zhang},
  title = {{Hierarchical Query Classification in E-commerce Search}},
  booktitle = {The Web Conference},
  year = {2024},
  doi = {10.1145/3589335.3648332},
}
Figure