Understanding intents and entities

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

An example

Building Chatbots in Python

Intents

A restaurant_search can be expressed many different ways:

  • I'm hungry
  • Show me good pizza spots
  • I want to take my boyfriend out for sushi
    • Can also be request_booking
Building Chatbots in Python

Entities

  • NER = Named Entity Recognition
Building Chatbots in Python

Regular expressions to recognize intents

  • Simpler than machine learning approaches
  • Highly computationally efficient
  • Drawback:
    • Debugging regular expressions can become difficult
Building Chatbots in Python

Using regular expressions

  • '|' is equivalent to OR
re.search(r"(hello|hey|hi)", "hey there!") is not None
True
re.search(r"(hello|hey|hi)", "which one?") is not None
True
Building Chatbots in Python

Using regular expressions

  • \b matches the beginning or end of a word
    re.search(r"\b(hello|hey|hi)\b", "hey there!") is not None
    
True
re.search(r"\b(hello|hey|hi)\b", "which one?") is not None
False
Building Chatbots in Python

Using regex for entity recognition

pattern = re.compile('[A-Z]{1}[a-z]*')

message = """ Mary is a friend of mine, she studied at Oxford and now works at Google"""
pattern.findall(message)
['Mary', 'Oxford', 'Google']
Building Chatbots in Python

Let's practice!

Building Chatbots in Python

Preparing Video For Download...