Predicting a Listing Category from Its Description and Photo

Ruslan Gilyazev25 May 2024

Problem

A classifieds marketplace has thousands of categories arranged in a tree, and the tree never stands still. Business teams add categories, deepen branches and move nodes between branches. Each category has its own parameters and monetization, so a wrong one costs money, and some sellers pick a cheaper one on purpose. One flat classifier over about 1000 classes is workable, but it must be retrained and relaunched whenever the tree changes, which can disturb unrelated categories.

Example from the article: at Avito, "hammer" must land under "Home and Garden" → "Repair and Construction" → "Tools" → "Hand Tools" → impact-lever tools. About 40% of buyer contacts go through category or parameter filters.

Solution in brief

Train a separate model for every non-leaf node of the tree, on top of one shared BERT backbone, and read the category by walking the tree from the top while keeping about five candidates per step. A new category is a new node: an automated pipeline trains its model without touching the others. Content managers supply data, a DS engineer approves the rollout.

Questions this case answers
  • How to predict the leaf node of a deep, frequently restructured hierarchy from short text by walking the tree and training one small head per branch on a shared encoder
  • How to add a new class to a hierarchical classifier without retraining the whole model when nodes are added or moved
  • How to predict the category of a listing when the category tree changes all the time
  • How to add a new category to a classifier without retraining the whole model

Tools and methods

  • Shared BERT backbone — trained on Avito listings, computes features once
  • Per-attribute heads — about 250 models, run in parallel with torch.vmap
  • Hierarchical classifier — tree walk with candidate ranking by a comparison function
  • Aqueduct — open-source library that splits inference into steps with separate CPU and GPU budgets
  • Airflow + MLflow — training and tracking for new nodes
Continue reading — it's free

Google or a one-time email code. No password.