Lessons Learnt Building a Medical ChatBot in Python

London Python
4 min readAug 11, 2017

Date: June 29 2017
Location: babylon health
Details: https://www.meetup.com/LondonPython/events/240079951/

For the second time London Python were relaxing in the Hanging Gardens of babylon with cold beers and a giant Pret-A-Manger picnic. For those of you who have not visited babylon health before (for a MeetUp or otherwise) then I can tell you now that the setup there is a little unique and rapidly becoming one of our favourite venues. Personally, I much prefer networking and mingling with people who don’t have greasy pizza hands.

Spoiler alert: I work for babylon.

The subject of the evening was ChatBots (a hot topic these days) and specifically building a medical ChatBot. Can a ChatBot actually practice medicine? Well, we were about to find out. The speaker, from babylon Health, was Wilhelm Van Der Walt, and he was actually doing a dry run of the talk he was about to do in front of hundreds more at EuroPython, Rimini.

We had a great turnout that evening; standing room only.

Why are people so interested in ChatBots? Is there a technical challenge behind them that makes this subject so fascinating? Or maybe it’s the fact that healthcare is probably the last big bastion of industry yet to have a technological revolution — having resisted it (else cocked it up spectacularly) in the UK at least for as long as I’ve been watching the news. I suspect this evening that it’s the former, although I’m actually more excited by the latter.

So let’s cut to the chase. We didn’t learn any of the secret sauce from babylon’s ChatBot architecture (babylon have a heavy-duty AI backend setup that sadly wasn’t on the agenda) but we got some fascinating insights and context into their problems, the drive behind what they’re working towards and why it’s so important to everyone there. babylon want to make healthcare affordable and accessible to everyone on the planet (slightly ambitious) and a ChatBot is helping them do this.

How is this so? It’s because the ChatBot is the user interface to the clever stuff that actually can practice medicine. The design and architecture behind this is fascinating and I’ll finish up with some links to other blogs that talk about this. But this blog is about the lessons that were learnt building this UI — and I hope babylon don’t mind me repeating them!

Lesson #1
Be careful modelling conversational data on a graph database.

Obviously graph databases are really cool and super trendy, but this does make them a rather big gotcha for your next project if you’re not careful. Turns out that a relational database probably suits a conversational model better than long chains of related nodes on a graph. Furthermore, writing schema and data migrations is pretty gnarly on systems like Neo4j. So don’t head down this road unless it’s the relationships between your data points that are paramount. Also beware the super-node!

Lesson #2
Don’t forget about the non-medical stuff.

babylon have stacks of medical data to use NLP and machine learning techniques against, but then a simple piece of dialogue such as “thank you” would arrive and the medical ChatBot would be stumped.

Lesson #3
Testing a ChatBot is hard.

It’s easy to start writing thousands and thousands of tests to validate all the conversations that you can feasibly worry about because the possible inputs are basically almost infinite. Then one change to the app might then affect all of these…. And because theirs is a medical ChatBot, everything has to be validated by real doctors. babylon are building an AI backed ChatBot to help scale doctors — but you need to make sure your testing strategy scales too.

Lesson #4
Content is as important as the AI

Unless the ChatBot actually returns something of value no one is going to want to come back and use the ChatBot again. As the AI improves, don’t forget to keep improving the content.

You can see the entire talk here on youtube (which is actually the EuroPython version) and I recommend that you do so.

The talk was indeed fascinating, not just because of the honesty and frankness of the speaker, but also because of the welcome from and view into an ambitious health tech startup — even if the lessons learned are applicable across any language and not just Python.

Thanks for reading.

Here are some resources that you might find of interest.

The understanding Robot
https://blog.babylonhealth.com/the-understanding-robot-1dc915c957cd

How The ChatBot understands words
https://blog.babylonhealth.com/how-the-chatbot-understands-words-c05a22f03af

How The ChatBot understands sentences
https://blog.babylonhealth.com/how-the-chatbot-understands-sentences-fe6c5deb6e81

Contextual ChatBots
https://chatbotsmagazine.com/contextual-chat-bots-with-tensorflow-4391749d0077

We look forward to seeing you at the next London Python MeetUp.

, on behalf of the London Python team.

--

--