AI Hints
Home›NLP Tutorial›Understanding Customers
NLP · Lesson 82 of 106

Spotting Trends

Catching problems early.

⏱ 2 min read▶ Video at 2:19:49🎓 Free
Watch this lesson in the NLP courseWatch on YouTube ↗Full NLP course

A courier changes depots, and late delivery complaints start to climb. Nobody notices for two months, because each support agent only sees their own tickets. If you've labelled your messages, then the whole company can see that shift, in the first week.

Spotting Trends
From the video: Spotting Trends
  • A courier changes depots
  • Complaints start climbing
  • See it in the first week

Topic counts over time

We count weekly tickets for each topic. Here, in week eight, late delivery complaints jump. We compare the latest week with the first eight, using standard deviations, so that we know how unusual it is. Run it. Late delivery is about six and a half standard deviations above normal. That's a real alarm. Torn cover is flat, at minus point two. Connect your classifier to a simple check like this one, and customer complaints become an early warning system for the entire business.

trends.pypython
import numpy as np
import pandas as pd

rng = np.random.default_rng(0)
weeks = pd.date_range("2026-01-05", periods=12, freq="W")
late = rng.poisson(30, 12); late[8:] += 45
torn = rng.poisson(20, 12)
t = pd.DataFrame({"late delivery": late, "torn cover": torn}, index=weeks.strftime("%m-%d"))

base, sd = t.iloc[:8].mean(), t.iloc[:8].std()
print(t.tail(4).to_string())
print(((t.iloc[-1] - base) / sd).round(1).to_string())
Output
       late delivery  torn cover
03-08             78          24
03-15             77          26
03-22             78          18
03-29             78          19
late delivery    6.6
torn cover      -0.2

From alarm to answer

A number says that something changed. Now you need to know why. Pull a sample of the tickets from that spike, and send them to a language model, asking what changed. Group by region and product, to find where. And close the loop, by telling the courier team. A dashboard that nobody acts on isn't worth building.

Pull a samplewhy did it spike?
Slice itwhere is it?
Summarisewith an LLM
Tell the ownerclose the loop

Summary

Labels plus time equals early warning. Next, you'll build your own question answering bot.

Key takeaways
  • Count topics weekly
  • Compare with a baseline
  • Ask why, then act
Next up: An FAQ Bot — know when not to answer