Training the black box, unleashing the branded chat bots. #clojure #nlp #slack #brands #marketing

Are chatbots the beginning of the new internet? No, I don’t believe so, it’s just another realignment of how users interact with the internet. “The new websites” is something I don’t buy into, a chatbot is just another black box dependent on an input stream of information from a user. Let me explain….

Slack is just another input layer

Like our own input devices; eyes, ears, nose, skin etc the internet has worked within a set of input devices of its own. Web forms, SMS messages (and WhatsApp, iMessage, Kik etc), voice recognition, Slack channels and so on. In common though is there is information fed through these channels that has to be handled, interpreted and in some cases responded to.


The early days were pretty basic call and response stuff. And chatbots of one type or another have been around for a long time. Who remembers writing bots for IRC and AIM Messenger back in the day, just me…. I don’t think so.

Slack offers the addition of a signed up audience, you’ve already registered an interest to join the channel so that’s a lot of work done already. Especially if you are interacting with a brand, the rest is a matter of reading the input. To be fair brands should be doing this with all the input channels they have, web forms, email, slack and Twitter etc. And in most cases it can be automated.

The important part of all of this is the black box which is decoding and defining the response.

Reading the Input Streams of Customer Thought

Let’s consider the following….

“Hi, my name is Jason and I’d like to book a restaurant table in Belfast please on 1st July”.


There’s an action (a user wants to book something), a type (in this case a restaurant) a date (1st July) and a location. The type could be interchangeable at this point, it could be a hair appointment or a flight booking. All we need is an AI that can handle all this things coming in. At this point we know the phone number, email address or slack name of the user so we don’t need to go finding that, we’ve already got it.

Using NLP to find the who, what, when and where

I’m using the Clojure OpenNLP and the NLP models to tokenize and extract the details that I’m looking for. And for ease I’ll do it all from the REPL.

First thing I have at my disposal is some predefined models that have been trained. So for things like names and location I’m not having to do lots of work.

wibble.chatty> (require '[opennlp.nlp :as nlp])
;; => nil
wibble.chatty> (def tokenizer (nlp/make-tokenizer "/opt/models/en-token.bin"))
;; => #<Var@6eb72feb: #function[opennlp.nlp/eval689$fn--690$tokenizer--691]>
wibble.chatty> (def names (nlp/make-name-finder "/opt/models/en-ner-person.bin"))
;; => #<Var@16ede515: #function[opennlp.nlp/eval719$fn--721$name-finder--723]>
wibble.chatty> (def locations (nlp/make-name-finder "/opt/models/en-ner-location.bin"))
;; => #<Var@15b5b602: #function[opennlp.nlp/eval719$fn--721$name-finder--723]>

Let’s define our input text, we’d normally be reading this from an API of some form or via email reading which can be easily automated.

wibble.chatty> (def input-text "Hi, my name is Jason and I'd like to book a restaurant table in Belfast please on 1st July")
;; => #<Var@62be6517: 
 "Hi, my name is Jason and I'd like to book a restaurant table in Belfast please on 1st July">

With my models loaded and my input text defined we can have a go at extracting some information.

wibble.chatty> (def enquiry-name (names (tokenizer input-text)))
;; => #<Var@2081c12: ("Jason")>
wibble.chatty> (def enquiry-location (locations (tokenizer input-text)))
;; => #<Var@7d92da99: ("Belfast")>

Even with that information alone we can form a response and say “we’re on it” and send that back to the user. Keep in mind the response mechanism is only another API to the input sensor provider (email, Slack, SMS etc). In other words it can be easily handled programatically.

wibble.chatty> (format "Hi %s - looking for restaurants in %s." (first enquiry-name) (first enquiry-location))
;; => Hi Jason - looking for restaurants in Belfast.

Remember that OpenNLP is returning sequences of words that are in the model. At this point we could fire off an API call to Yelp or Open Table and look for restaurants in that location with the resulting first ten results being sent back to the user with TripAdvisor reviews.

This is the surface scratched.

Chat bots as they currently stand are an easy technology. Input data from an API going into do some decoding model and a response being generated. The challenge is to have a meaningful conversation, do I hear Turing Test anyone?

So the question remains, why Slack as an input medium. Well it’s an easy route to knowing who the customer is in the first instance. Plus the UI is built, the API is defined and it’s easy to integrate to.

If you’re looking for the real holy grail, you want to raise the UI to the next level and start looking at speech as the input sensor. And that means waiting for Apple to release a Siri API (developers have been waiting a long time for that) and Google to release the Now API.

I’ll be tinkering with this a little more in the future.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: