Facebook Messenger built-in Natural Language Processing

Tom from the Bot Division at Etic Lab explores FaceBook Messenger’s built-in Natural Language Processing.

“Sorry, I didn’t quite understand that?”

So chatbots are great…

 

…press some buttons and get a response. Very useful most of the time. You can build all kinds of complex question/response paths for a user to traverse. But what if we need more than just predefined responses? What if we want to chat to the Chatbot?

Bring on Natural Language Processing (or NLP). In short, it’s a method of analysing human-readable text and extracting, with confidence, the fundamental entities from that text.

For example, take this message from a user:

“Hello, please can you call me back on 01686 629901 next Tuesday at 2?”

Let’s break this down into its key pieces of data or entities

  • “Hello” is a greeting entity
  • “01686 629901” is a phone number entity
  • “Tuesday at 2” is a DateTime entity

Now if we can find and extract these entities then we’re on to some useful data – say, for example, booking a callback into a Customer Relationship Management or similar useful CRM or booking tool.

Ok, this is great, now let’s build our NLP Engine

…on second thoughts let’s use Facebook Messenger’s built-in NLP engine instead.

Origin story: some of you may have come across Wit.ai, a cool AI company with a platform for building bots with their NLP engine. I played around with their “order a pizza” demo, was fun, never got further than that (nor did my pizza ever arrive). Anyway, long story short, at some point FaceBook acquired Wit.ai and then lo and behold, in July 2017, Facebook announced that Messenger now has built-in NLP.

Turning it on is easy, just assign a Facebook Page within the Messenger settings of your FaceBook App. Flick the switch, and you’re good to go (ignore Advanced settings for now)

 

Now if we send our message to Messenger, our response now includes an “NLP” object:

 

Excellent, so we have machine-readable DateTime and phone number! We could respond with:

“Thanks, we will call you back Tuesday 28th November at 2:00 AM on 01686 629901 Is this correct?”

Moreover, we can use the DateTime to pop a reminder into our CRM or booking tool.

My own experience using Messenger’s NLP out the box; some entities work great, the DateTime, email, greeting and bye for instance. When dealing with times, if the user doesn’t specify AM / PM, just make sure you make an educated guess (“Are you sure you want a callback at 2AM?”).

Other entities are a tad more clunky. The phone entity, for instance, seems to pick up any number the user types (e.g. “987654”) as a phone number. The solution to this is to check the confidence value is significantly high, and perhaps do some validation of your own.

The most confusing entity by far is location. Don’t get me wrong, I type in my address, 221B Baker Street, and get a hit on the location entity with confidence ~0.92. I type my postcode/zipcode, SW1A 1AA, and again get a hit on the location entity with confidence ~0.85. Neither confidence values are particularly statistically relevant, nor is the response that impressive – I’m struggling to see a useful application. A helpful response would be to return a breakdown of the address into its constituent parts (e.g. Street, City, Postcode). In the end, I just needed postcodes so used a regex.

Perhaps that’s where the Advanced NLP settings come in – would love to hear from anyone that’s had a go at customising these settings for a project?

Etic Lab will soon be launching a production Messenger bot leveraging the features mentioned above, so look out for the upcoming case study.