Two's Company, Three's a Community: How Graph Algorithms Help Assemble Groups of Products

Ivan Antipov7 Feb 2024

Problem

A marketplace matching team needs groups of identical products offered by different sellers, so shoppers can compare offers. A candidate search and a pair model give a table of product pairs with an is_duplicate flag, but search and pricing need whole groups, not pairs. Merging pairs transitively into connected components multiplies the model's errors, because one wrong pair joins two groups. Ordinary clustering needs hyperparameters, compares every product with every other, and loses precision on image and title embeddings, which carry no attributes.

Example from the article: two groups of 8 listings each (iPhone 14 and iPhone 15 Plus) give 56 correct pairs. One false pair [3, 15] merges them into a single 16-item cluster.

Solution in brief

Treat predicted duplicate pairs as edges of a graph whose vertices are products, then find communities with label propagation. Pair models usually have precision close to 1, so a few false edges between dense groups do not outweigh the many true edges inside them. Static Label Propagation needs no hyperparameters except the iteration limit, and it runs distributed on Spark.

Questions this case answers
  • How to turn noisy pairwise same-entity predictions into entity groups when transitive closure lets a single wrong pair merge two groups
  • How to assign new records to already known groups at scale without reclustering everything from scratch
  • How to group pairwise duplicate predictions into clusters of the same product without one false pair merging two groups?
  • How to cluster a graph of matched products when the number of clusters is unknown and there are millions of vertices?

Tools and methods

  • Static Label Propagation — unsupervised clustering of the product graph
  • Label Spreading / Label Propagation — semi-supervised variants for graphs with some known labels
  • GraphFrames (Apache Spark) — distributed labelPropagation and aggregateMessages
  • NetworkX — synthetic graphs and small-scale experiments
  • ANN (HNSW, IVF, LSH) — candidate selection before the pair model
Continue reading — it's free

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