A New Approach to Text Classification in Chatbots

Ivan Chetverikov20 Aug 2024

Problem

A car dealer's chatbot receives hundreds of customer messages a day and must tell what each is about: a VIN lookup, car search, credit or trade-in question, office hours, or a request for an operator. The team had about 20 topics and wanted an MVP fast, without collecting labeled data first. An ML classifier would have taken months, an LLM prompt was not accurate enough and gets expensive at volume, and retraining the ML model needed an ML engineer.

Example from the article: "Any trade-in options?" must go to the knowledge-base topic, while "Need to discuss personal discount and car customization" must go to an operator.

Solution in brief

The team went through three classifiers on the same task: an LLM few-shot prompt for the MVP (one to two weeks), a fine-tuned DistilBERT, and a semantic-router layer over OpenAI embeddings. The router needs no training: it embeds a K-means-reduced example set per topic and matches each message to the nearest topic. It gave the best accuracy at low cost.

Questions this case answers
  • How to classify short user messages into a fixed set of intents when labeled data appears only after launch and a model retraining cycle is too slow
  • How to keep per-message classification cost and latency low when an LLM prompt is accurate enough but too expensive at volume
  • How to route incoming customer chat messages into about 20 topics before a labeled dataset exists?
  • How to choose between an LLM prompt, a fine-tuned BERT and an embedding router for intent classification?

Tools and methods

  • LLM few-shot classifier (gpt-3.5-turbo) — MVP classifier, 3-4 examples per topic in the prompt
  • DistilBERT multilingual cased — fine-tuned classifier over 20 topics
  • semantic-router with text-embedding-3-large — routes a message by embedding similarity to labeled examples
  • K-means (scikit-learn) — picks representative examples per topic
Continue reading — it's free

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