MODULE 15 ยท Middle-track ยท 2.5 hours

The bigger model is more accurate โ€” and does not pay for itself

Five thousand tickets a day and 55 person-hours spent purely on sorting them. We choose between three options on F1 together with latency and hardware.

Open this module in the simulator All 23 lessons

The first two modules are free, no card. The rest are $20/month.

๐Ÿข The situation

The head of support comes to Lena:

"5,000 tickets a day. Agents spend the first 40 seconds of every ticket figuring out where it belongs: payments, delivery, returns, account, fraud. That's 55 person-hours a day just on sorting!"

Lena:

"Auto-classification of tickets โ€” the perfect first NLP task. We have 200,000 historical tickets with categories assigned by agents. Start with TF-IDF + a linear model, then compare with a pre-trained transformer. Real language, typos, slang โ€” welcome to real-world NLP."

๐ŸŽฏ Your task

  1. Understand how text becomes numbers: from bag-of-words to embeddings.
  2. Build the TF-IDF + logreg baseline.
  3. Compare with a fine-tuned transformer and decide what goes to production.

๐Ÿ“š Theory

Text โ†’ numbers: the evolution of approaches

  1. Bag of Words: text = a vector of word counts. Loses word order.
  2. TF-IDF: counts weighted by corpus rarity. A word frequent in a document but rare in the corpus ("refund") matters more than one frequent everywhere ("hello"). Still the strongest classification baseline.
  3. Word embeddings (word2vec, fastText): word โ†’ dense vector; semantically similar words are close. fastText learns vectors from character n-grams โ€” robust to typos.
  4. Transformers (BERT and heirs): a word's vector depends on context ("the card is blocked" vs "a card of the city"). Pre-trained on huge corpora, fine-tuned for the task.
"charged twice, refund me!" Path 1: TF-IDF bag of words weighted by rarity [0, 0.8, 0, 0.4, 0, โ€ฆ] โ€” sparse Path 2: transformer a word's vector depends on context [0.21, โˆ’0.77, โ€ฆ] โ€” dense, 312d classifier softmax over 5 classes Payments P = 0.93 TF-IDF: 2 ms, CPU, F1 0.86 ยท Transformer: 40 ms, F1 0.91 โ€” choose by requirements
Both paths turn text into numbers. The TF-IDF baseline is mandatory; the transformer adds context understanding at the cost of latency and complexity.

The classic NLP pipeline

When to use what

Approach Pros Cons
TF-IDF + linear model fast, cheap, interpretable, CPU doesn't understand context or synonyms
Fine-tuned transformer best quality, robust to phrasing GPU, latency, harder maintenance

The decision, as always, comes from the requirements: latency, budget, size of the win.


What to remember

  • TF-IDF + a linear model is the mandatory NLP classification baseline.
  • Lemmatization and n-grams help a lot with morphologically rich languages.
  • Transformers add context; choose the model size from latency requirements.
  • Confidence threshold + a manual queue = safe automation.

Next in this module: Practice

Open the module โ†’

Nearby lessons

14 The warehouse is overstocked: demand forecasting 16 Meet neural networks

The whole program โ€” 23 lessons