RoBERTa for Large-Scale Merchant Classification

square · Finance · 2025 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Merchant categorization for payments and business services

Square needed more accurate merchant categorization because self-selected onboarding categories were noisy and downstream product, marketing, compliance, forecasting, and interchange-fee decisions depended on knowing what business each seller actually ran.

Constraints:

Architecture

Square built a RoBERTa-large merchant categorization model trained on more than 20,000 manually reviewed sellers. The pipeline removes misleading auto-created services, ranks catalog items by purchase frequency to fit token limits, formats business/category/catalog signals into a structured input string, fine-tunes RoBERTa for sequence classification on GPU-backed Databricks, and runs daily batch inference with multiple GPU workers, PySpark parallelism, batch-size tuning, and incremental predictions.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  A["Merchant profile signals"] --> B["Data preprocessing pipeline"]
  C["Manual review labels"] --> D["RoBERTa training job"]
  B --> D
  D --> E["Trained merchant classifier"]
  B --> F["Daily inference job"]
  E --> F
  F --> G["Historical prediction table"]
  F --> H["Latest prediction table"]
  G --> I["Business analytics systems"]
  H --> I
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Merchant profile signals Business names, onboarding categories, subcategories, and catalog/service data. Data preprocessing pipeline
Data preprocessing pipeline Removes noisy auto-created services, ranks catalog items, and formats structured text inputs. RoBERTa training job, Daily inference job
Manual review labels High-quality ground truth labels for training and evaluation. RoBERTa training job
RoBERTa training job Fine-tunes a Hugging Face RoBERTa sequence classifier on GPU-backed Databricks. Trained merchant classifier
Trained merchant classifier Predicts seller business categories from processed text inputs. Daily inference job
Daily inference job Runs batch merchant predictions with multiple GPU workers, PySpark, batch tuning, and incremental prediction skipping. Historical prediction table, Latest prediction table
Historical prediction table Stores daily partitions for troubleshooting, monitoring, and drift checks. Business analytics systems
Latest prediction table Serves current merchant-category predictions to stakeholders and business systems. Business analytics systems
Business analytics systems Product strategy, marketing, segmentation, compliance, and interchange-fee use cases that consume predictions. —

Data flow

Merchant business names, self-selected categories, and catalog items feed preprocessing. Auto-created services that were never manually modified are removed, catalog items are ranked by purchase frequency and truncated under token limits, and the remaining signals are formatted into an input string. A Hugging Face RoBERTa sequence classifier is trained on manually reviewed labels, then daily inference runs across merchants on GPU/PySpark infrastructure and writes historical and latest prediction tables.

3 supporting quotes
“the model code would generate a single text called the “Input String”.”article, stated
“From there, we instantiated our model using the AutoModelForSequenceClassification class from Huggingface and then loaded it onto our GPU.”article, stated
“The model produced two key output tables to serve distinct purposes:”article, stated

Why this architecture

Square chose a supervised RoBERTa classifier because the problem was language understanding over merchant text, not generation. Manually reviewed labels fixed the weak-label problem, post-onboarding signals gave richer evidence than onboarding self-selection, and GPU/PySpark batch infrastructure made daily inference practical at tens-of-millions scale.

3 supporting quotes
“The model is trained on a random sample of over 20,000 manually reviewed sellers, ensuring high-quality ground truth labels for our training and evaluation data.”article, stated
“Our approach uses a wide array of post-onboarding signals, including business names, self-selected onboarding information, and the entire catalog of items and/or services offered by the sellers”article, stated
“given the vast number of sellers on the platform (in the tens of millions!), was another area that demanded even more GPU support.”article, stated

Models used: RoBERTa-large · AutoModelForSequenceClassification

Scale

Alternatives considered (roads not taken)

Rely on merchant self-selection

Rejected because: Self-selected categories are frequently wrong and misrepresent a meaningful portion of sellers.

“Via extensive manual review of individual sellers, we noticed that merchant self-selection is highly susceptible to miscategorization.”article, stated

Use auto-created catalog services as ordinary product evidence

Rejected because: Auto-created services can reflect the wrong onboarding category rather than the merchant's real offerings.

“However, this also creates additional noise: if a merchant accidentally selects the wrong category info, it will receive auto-created services that don’t represent their business.”article, stated

Run every merchant through inference every day

Rejected because: Incremental prediction skipping reduces inference time by avoiding unchanged inputs.

“We avoided running predictions for sellers whose inputs remained unchanged from the previous day.”article, stated

Use one fixed inference batch size

Rejected because: Batch size improves GPU efficiency only up to a point and can create memory issues when too large.

“Larger batch sizes can improve efficiency by making better use of GPU resources, however this benefit is only realized up to a certain point, as excessively large batch sizes can cause memory issues.”article, stated

Patterns

fine-tuning-adaptation (model-adaptation)

Square fine-tuned RoBERTa for merchant category sequence classification using manually reviewed merchant labels and domain-specific inputs.

“By utilizing the RoBERTa architecture, we harness the power of LLMs to achieve superior categorization accuracy.”article, stated
“it initializes the model with weights that have been pre-trained on a large corpus of text which we will further train using our specific data.”article, stated

data-quality-loop (data)

The team replaced noisy self-selected labels with manually reviewed ground truth and cleaned catalog signals before training.

“The model is trained on a random sample of over 20,000 manually reviewed sellers, ensuring high-quality ground truth labels for our training and evaluation data.”article, stated
“As part of data preprocessing, we remove all auto-created services that were not later manually modified by the seller (taking the view that services that were altered are typically ones where the merchant actually wants to keep them).”article, stated

batch-offline-processing (serving)

Square runs daily large-scale inference jobs with GPU workers, PySpark parallelism, batch tuning, and incremental prediction skipping.

“This model performed inference daily and, given the vast number of sellers on the platform (in the tens of millions!), was another area that demanded even more GPU support.”article, stated
“PySpark excels at parallel processing by efficiently distributing computations across multiple GPUs or nodes in a cluster.”article, stated

observability-tracing (operations)

Historical daily prediction partitions support troubleshooting, monitoring, and model-drift validation.

“Historical Table: Stored daily partitions of predictions, enabling troubleshooting and monitoring over time for things such as model drift”article, stated

structured-output-contract (outputs)

The production model writes category predictions into defined historical and latest prediction tables for business systems.

“Latest Predictions Table: Contains the most up-to-date predictions, readily available for stakeholders to use in decision-making”article, stated

Tradeoffs

Ground truth strategy

Chose manual review labels over self-selected onboarding categories.

Rationale: Manual review costs more up front but avoids training on inaccurate seller self-selection.

“The model is trained on a random sample of over 20,000 manually reviewed sellers, ensuring high-quality ground truth labels for our training and evaluation data.”article, stated

Catalog truncation signal

Chose purchase-frequency-ranked catalog items over arbitrary catalog truncation or all items.

Rationale: Purchase frequency preserves the items most representative of what the merchant actually does while staying under token limits.

“This ensures the model is categorizing a merchant based on what they sell the most, which should also be more indicative of what they actually do.”article, stated

Inference optimization

Chose incremental predictions for changed inputs only over rerunning every seller every day.

Rationale: Skipping unchanged inputs reduces daily inference time at tens-of-millions scale.

“if a seller’s business name, services, and self-selected activation info had not been updated, we retained their existing business category prediction without rerunning inference.”article, stated

Gotchas (what bit them)

Self-selected merchant categories were unreliable training targets.

Root cause: Sellers can rush onboarding, misunderstand granular choices, or select the wrong category.

Resolution: Train and evaluate on a manually reviewed seller sample instead of treating self-selection as truth.

“Via extensive manual review of individual sellers, we noticed that merchant self-selection is highly susceptible to miscategorization.”article, stated
“They often over-indexed on self-selected information as the source of truth for labels; as discussed previously, self-selection is highly inaccurate”article, stated

Auto-created catalog items created false evidence.

Root cause: Square creates default services from the selected onboarding category, so a wrong selection can create catalog items that do not represent the business.

Resolution: Remove auto-created services that merchants never manually modified.

“if a merchant accidentally selects the wrong category info, it will receive auto-created services that don’t represent their business.”article, stated
“As part of data preprocessing, we remove all auto-created services that were not later manually modified by the seller (taking the view that services that were altered are typically ones where the merchant actually wants to keep them).”article, stated

Catalog length could exceed transformer token limits.

Root cause: Some merchants sell very large numbers of items.

Resolution: Rank catalog items by purchase frequency and truncate after the token threshold.

“Some merchants sell a lot of things (e.g. possibly tens of thousands), and so we need to truncate their catalog items”article, stated
“for each merchant, we rank their catalog by the amount of times that item was purchased, and subsequently cut off any items beyond the token threshold.”article, stated

Daily inference at tens-of-millions scale could take too long.

Root cause: Running predictions for all sellers without parallelism or skipping unchanged inputs would create large delays.

Resolution: Use multiple GPU workers, PySpark, batch-size optimization, and incremental predictions.

“To generate predictions for all of these merchants without weeks of delay, we leveraged 4 different techniques:”article, stated
“This approach significantly reduced inference time by focusing only on sellers with updated inputs.”article, stated

Evaluation

Square evaluated the classifier against held-out manually reviewed samples and compared category accuracy gains to merchant self-selection, while also storing daily historical predictions for monitoring and drift validation.

Metrics: Absolute approximately 30% accuracy improvement over existing methods · Accuracy gains summarized across major business categories · Daily historical partitions for troubleshooting and model drift checks

3 supporting quotes
“The model is estimated to have an absolute ~30% improvement in accuracy of determining seller business category than existing methods.”article, stated
“By examining model performance on our test data (randomly selected samples that were held-out and not part of our training data), we summarize the accuracy gains”article, stated
“Historical Table: Stored daily partitions of predictions, enabling troubleshooting and monitoring over time for things such as model drift”article, stated

Outcomes

The system performs daily inference for tens of millions of sellers and handles merchants with catalogs that can contain tens of thousands of items.

“The model output, which refreshes on a daily basis, is now utilized by Square to power all business metrics that require segmentation by merchant categories/audiences.”article, stated
“this has important implications for product strategy, GTM strategy + targeting (including email campaigns), as well as numerous additional applications.”article, stated