Incremental slot filling and negation

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Incremental filters

Building Chatbots in Python

Basic memory

def respond(message, params):
   # update params with entities in message
   # run query
   # pick response
   return response, params

# initialise params
params = {}

# message comes in
response, params = respond(message, params)
Building Chatbots in Python

Negation

"where should I go for dinner?"

"no I don't like sushi"

"what about Sally's Sushi Place?"

"ok, what about Joe's Steakhouse?"

Building Chatbots in Python

Negated entities

  • assume that "not" or "n't" just before an entity means user wants to exclude this
  • normal entities in green, negated entities in purple
Building Chatbots in Python

Catching negations

doc = nlp('not sushi, maybe pizza?')

indices = [1, 4]
ents, negated_ents = [], []
start = 0 for i in indices: phrase = "{}".format(doc[start:i]) if "not" in phrase or "n't" in phrase: negated_ents.append(doc[i]) else: ents.append(doc[i]) start = i
Building Chatbots in Python

Let's practice!

Building Chatbots in Python

Preparing Video For Download...