So It Only Works If I Talk Like You
I demoed my first chatbot to a friend last month, feeling fairly pleased with myself. His first message worked. His second worked. His third got “I didn’t understand that,” and so did his fourth. He looked up from the laptop and said, without any malice at all, “so it only works if I talk like you.” It’s the most useful thing anyone has ever said to me about software, and I’ve spent three weeks trying to work out everything it implies.
Version one: a very confident parrot
The first build was pure pattern matching. A list of regular expressions, each mapped to a canned reply: if the message mentioned booking and a slot, reply about booking; if it said cancel, reply about cancelling; if nothing matched, apologise. I’d picked chatbots as my way into AI for an unscientific reason. Conversation seemed like the most human thing a machine could fake, and I wanted to see the trick up close. The trick, it turns out, is several increasingly desperate tricks stacked on top of each other.
Building the rule-based version was still worth it, because it shows you exactly why the real problem is hard. One intention has an unlimited number of surface forms. “Book a slot” matched my pattern. “Can I reserve something for Friday” didn’t, because it never said “slot.” Neither did “i wanna schedule smth,” and “u free tmrw?” matched nothing at all. I was playing whack-a-mole against an infinite supply of moles. The good news is that I’d hand-written, badly, the exact logic that intent classification exists to automate, so when I got to intent classification I already understood the pain it was solving.
The fallback message taught me something too. My bot said “I didn’t understand that” crudely, but it said it. A system that admits confusion is irritating. A system that confidently answers the wrong question is dangerous, because people act on the wrong answer. I didn’t know at the time how often that idea would come back.
Version two: the week papers became useful
The second build used actual machine learning, and it’s where my habit of reading one paper a week badly finally paid off. The difference was that I now had a question. I needed a way to represent sentences so that two different phrasings of the same request would land near each other, and with a real question in hand, the Word2Vec and GloVe papers stopped being impenetrable and started being instructions. That was the first time research felt less like a performance of seriousness and more like a toolbox.
The pipeline was the classical NLP stack: clean and tokenise the text, turn it into vectors, classify the intent, pull out the details like dates and names, and track what the conversation still needed. Every stage taught me something by breaking. I stripped punctuation during preprocessing and quietly destroyed the bot’s ability to tell a question from a statement. TF-IDF turned out to be a small, elegant idea about information: words that appear often in one message are probably what it’s about, and words that appear everywhere, like “the,” are probably about nothing. Then came word embeddings, where words become points in space and meaning becomes distance. You can take the vector for “king,” subtract “man,” add “woman,” and land somewhere close to “queen.” I’ve thought about that more than any other idea this year. It’s the first time I’ve understood meaning as something geometric, and I suspect it’s going to matter a great deal.
The test set I wrote myself
Version two was much better on my test data and still failed on real people, and the reason was so obvious that I’m slightly embarrassed to write it down. I had written the test data. I write like someone who knows exactly what the bot expects, because I built the bot. My friend wrote like a person: fragments, typos, three questions in one message, abbreviations I’d never considered. My evaluation was measuring how well the bot understood me, which was not the question anyone cared about.
That’s the first real answer to the question I left myself in September, about how I’d know whether something actually works. Not by testing it on examples I invented. The data you evaluate on has to come from the people who will actually use the thing, or the number you get back is a flattering fiction.
The two-thirds nobody mentions
The model turned out to be about a third of the work. The rest was everything around it. A single-turn bot is a function, but a conversation is a state machine: “book me a slot,” then “for when?”, then “tomorrow” only means something if the system remembers the first two lines, and it has to cope when the user changes their mind halfway through. Wrapping the bot in a small Flask app taught me the distance between “works in my notebook” and “works when someone else clicks it.” The first crash from an outside user was an emoji, which in hindsight was inevitable. And my first-ever performance work happened because I watched my friend get bored waiting for a reply and pick up his phone. Loading the model once at startup instead of on every message fixed most of it.
That bored friend is the thread I want to pull next. In text, a slow reply is mildly annoying. In speech, silence is unbearable, because you can’t even tell whether the thing is still working. That sounds like a different engineering problem altogether, so next semester I’m going to give my chatbot a voice.
Leave a Reply