NER for E-Commerce Text: Design, Models, and Evaluation
Machine LearningModel answerLast updated
Design a named entity recognition system for short e-commerce text, covering task framing, model families, data pipeline, and the right metrics.
You are designing a named entity recognition (NER) system for an e-commerce platform. The input is short, often noisy text — product listing titles like "Nike Air Max 90 Men's Running Shoe Size 10 White/Black" and search queries like "red adidas hoodie medium". The entities you care about are product attributes: brand, product type, color, size, and model name.
Answer the three parts below in order. Before diving in, briefly state any clarifying questions you would ask in a real design session.
Part 1 — Frame the task
Define NER as an ML problem for this setting. Cover:
- What goes in, what comes out, and how the output is represented as labels on tokens
- Which tagging scheme you would use and how spans are recovered from tags
- At least three reasons this setting is harder than standard NER benchmarks
Part 2 — Pick a modeling approach
Walk through the main families of NER methods. For each, give its strengths, weaknesses, and when it fits. Then commit to a specific choice for this use case and explain your reasoning. Include a fallback.
The families to address:
- Rule-based and dictionary lookup
- Feature-engineered sequence models (e.g., CRF)
- Neural sequence taggers (e.g., BiLSTM-CRF)
- Fine-tuned transformer encoders (e.g., BERT-family)
- Generative LLM extraction (e.g., prompted GPT-style models)
Part 3 — Data and metrics
Explain how you would build a training set and measure success. Cover:
- How to get labeled data, keep it consistent, and reduce its cost
- The preprocessing steps specific to this setting (subword alignment, normalization, class imbalance, train/test splits)
- Which metrics you report at the entity span level and which downstream metrics tell you whether the system is actually useful
Hints
Hint 1
For Part 1, think carefully about what happens at token boundaries when the same surface form can belong to different entity types depending on context — 'Black' is a color in one listing and part of a model name in another.
Hint 2
For Part 2, latency matters differently depending on whether NER runs at indexing time over a fixed catalog or in the live query path. That constraint can rule out entire model families before you weigh accuracy.
Hint 3
For Part 3, exact-match F1 can look poor even when the system is practically useful — a span that gets the right entity type but wrong boundary still helps downstream filtering. Think about whether you need strict or relaxed matching, and why micro vs. macro F1 tells different stories on a skewed label distribution.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Clarifying Questions
Before designing anything, you would want to know: Is the entity type list frozen, or will new types be added over time? How much labeled data already exists? Does NER run offline at catalog indexing time, online in the query path (with a latency budget), or both? What languages are in scope? And how are the extracted entities consumed — search filters, ranking features, catalog normalization?
The answers shift the model choice significantly. A frozen type list and offline-only use case lets you optimize purely for accuracy. An online path with a 10 ms budget rules out large transformers without distillation or caching.
Part 1 — Task Definition
NER takes a sequence of tokens as input and produces a set of typed spans as output. Each span has a start index, an end index, and an entity type (brand, color, size, etc.).
Tagging scheme. The standard way to encode this as a per-token classification problem is IOB2 (also called BIO): B-TYPE marks the first token of a span, I-TYPE continues it, and O marks tokens outside any entity. For example:
Nike B-BRAND
Air B-MODEL
Max I-MODEL
90 I-MODEL
Size O
10 B-SIZE
White B-COLOR
/ O
Black I-COLOR ← ambiguous: color or part of model name?
Spans are recovered by collecting consecutive B/I tags of the same type. BIOES (adding E for end and S for single-token spans) can help models learn cleaner boundaries, though IOB2 is more common.
Why this setting is hard:
- Minimal context. A five-word query gives the model almost nothing to disambiguate from. Standard NER datasets like CoNLL have full sentences.
- Ambiguity.
"Black"is a color or part of a model name."Jordan"is a brand or a person's name in a gift query. - Noise. Sellers concatenate words (
"whiteshirt"), use non-standard capitalization, omit spaces, and make inconsistent abbreviations ("sz","S/M/L"). - Class imbalance and label skew. The
Otag dominates; rare entity types likeMODELmay appear far less thanBRANDorCOLOR. - Unseen surface forms. New brands and model names appear constantly and won't be in any pretrained vocabulary.
Part 2 — Modeling Approaches
Rule-based and dictionary lookup. Fast, fully interpretable, zero training data needed. Works well when the entity vocabulary is stable and small — a brand dictionary with ~10k entries covers most traffic. Breaks on misspellings, multi-word matches, and anything not in the dictionary. Good as a baseline or a complement to a learned model.
Feature-engineered CRF. A linear-chain CRF over hand-crafted features (capitalization, suffix patterns, character n-grams, gazetteer membership). Trains quickly, handles small datasets reasonably well, and is easy to debug. Its ceiling is low because features need manual curation and don't generalize to new surface forms.
BiLSTM-CRF. Learns character and word embeddings jointly, better at morphological variation than CRFs. Needs more labeled data (~10k–50k sentences) and is slower to train. Still outperformed by transformers on most benchmarks, but can run faster at inference.
Fine-tuned transformer encoder (BERT-family). The current standard for production NER. A pretrained encoder (BERT, RoBERTa, or a domain-specific variant) is fine-tuned on labeled spans. Handles ambiguity well through context, though context is thin in short queries. Accuracy is high. Latency for a base model (~110M params) is roughly 10–30 ms per batch on CPU; with distillation (DistilBERT, TinyBERT) you can halve that. This is the right primary choice for this use case.
Generative LLM extraction. Prompting a large generative model to return JSON with entity spans. Flexible — you can add a new entity type with a sentence in the prompt. Latency and cost are high, output format can be unreliable, and evaluation is harder because the model may paraphrase. Best suited for low-volume annotation tasks or bootstrapping labels, not for serving millions of queries per day.
Decision. Fine-tune a distilled transformer (e.g., DistilBERT or a domain-pretrained variant if one exists for e-commerce text) for the primary model. Use a dictionary layer on top for high-confidence brand lookups to recover recall on tail brands. If a new entity type needs to be added before retraining, an LLM can generate noisy labels to seed annotation.
Part 3 — Data and Metrics
Building training data
Labeling. Annotation guidelines must define boundary rules explicitly — does "Air Max 90" span include "90"? Yes. Hire domain-familiar annotators and measure inter-annotator agreement (Cohen's kappa) before scaling. Target kappa > 0.8 before trusting the label set.
Cheaper label sources. Distant supervision against product catalogs (match known brand strings and auto-label them as B-BRAND) generates a large noisy dataset quickly. Combine it with a smaller clean-annotated set and use a noise-robust training objective or confident-learning filtering.
Preprocessing specifics:
- Subword alignment. Transformer tokenizers split
"Nike"into["Ni", "##ke"]. Assign theB-BRANDtag to the first subtoken andI-BRANDto the rest, or use only the first subtoken's logit for the span boundary. Be consistent. - Normalization. Lowercase, Unicode normalization (NFKC), expand common abbreviations (
"sz"→"size") before tokenization. - Class imbalance. Weighted loss on rare entity types; oversample listings rich in rare types.
- Leakage-free splits. Split by product ID or seller, never by listing. If two listings describe the same product, they must be in the same split.
Metrics
Entity-level (offline eval):
- Exact-match F1 per type — a span is a true positive only if both boundaries and the type match exactly. Strict but noisy for boundary-sensitive types like model names.
- Partial / relaxed match F1 — credit a prediction that gets the right type and overlaps with the gold span. Useful for downstream tasks that only need the entity type, not the precise boundaries.
- Micro F1 (weighted by span count) reflects performance on frequent types. Macro F1 (unweighted average over types) reveals problems on rare types. Report both.
Downstream / product-level metrics:
- Attribute fill rate: what fraction of listings have a non-null value for each attribute after extraction?
- Filter precision: when a user applies a color filter, what fraction of returned listings actually match? A/B test against the baseline.
- Search relevance impact: measure NDCG or click-through rate when NER-derived attributes are used as ranking features.
Error analysis should drive iteration: look at per-type confusion matrices, surface common boundary errors, and check whether errors cluster on specific sellers or query patterns.