SlideShare a Scribd company logo
1 of 69
dd
Chatbots from First Principles
Data Day Seattle
October 19, 2017
Jonathan Mugan
@jmugan
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
The Slides from this talk
are on SlideShare
https://www.slideshare.net/jmugan
/chatbots-from-first-principles
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Conversation requires shared reference
Language begins with shared attention by pointing to things
in the world. Words then point to shared ideas in our minds
[Gärdenfors, 2014].
3
2
1
Language as shared convention
A
B
Wittgenstein and his language games,
Philosophical Investigations, 1958
block
pillar
slab
beam
Two people building something.
“Bring me a beam.”
Eventually turns into a shared convention for a
community
Our brains map community conventions to
personal sensations and actions
sensation representation action
• When someone says “beam,” we map that to our experience with beams.
• We understand each other because we have had similar experiences.
See: Benjamin Bergen, Steven Pinker,
Mark Johnson, Jerome Feldman, and
Murray Shanahan
“beam”
This is what is means for language to be grounded.
We negotiate language and meaning as we go
Modified from Gärdenfors (2014), which was based on Winter (1998)
Coordination
of meaning
Coordination
of inner worlds
Instruction
Acknowledgement
Acknowledgement
Break
Break
• Levels of discourse
• Complicated to go
up and down the pyramid
We negotiate language and meaning as we go
A fishing pole
is a stick, string
and hook
You can catch fish
with a fishing pole
Get me some fish
Acknowledgement
Acknowledgement
Break
Break
• Levels of discourse
• Complicated to go
up and down the pyramid
Modified from Gärdenfors (2014), which was based on Winter (1998)
Conversation has its own rules (pragmatics)
• Conversational maxims: Grice (1975, 1978)
• Breaking these rules is a way to communicate more than the meaning of the words.
Maxim of Quantity: Say only what is not implied.
Yes: “Bring me the block.”
No: “Bring me the block by transporting it to my location.”
What did she mean by that?
Maxim of Quality: Say only things that are true.
Yes: “I hate carrying blocks.”
No: “I love carrying blocks, especially when they are covered in fire ants.”
She must be being sarcastic.
Maxim of Relevance: Say only things that matter.
Yes: “Bring me the block.”
No: “Bring me the block and birds sing.”
What did she mean by that?
Maxim of Manner: Speak in a way that can be understood.
Yes: “Bring me the block.”
No: “Use personal physical force to levitate the block and transport it to me.”
What did she mean by that?
Sometimes meaning isn’t even in the words but
how they are spoken (prosody)
Example from Voice User Interface Design
by Giangola and Balogh [2004]
``
1. You know. I don’t. [So don’t ask me.]
2. You know. I don’t. [As a matter of fact, I really don’t.]
3. You know I don’t. [You know that I don’t.]
‘’
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
We’ve all heard of Eliza
Python implementation at https://www.smallsurething.com/implementing-the-
famous-eliza-chatbot-in-python/
I want to buy a car.  How much does a car cost?
Simple substitutions to mimic a psychologist from the 1960s
“My mother wants me to buy a bazooka.” …
“Tell me why your mother wants you to buy a bazooka.”
You can extend it as much as you want
Modern mimicry agents are example based
Take a bunch of dialogs and use machine learning to predict
what the next statement will be given the last statement.
• Movie and TV subtitles
• OpenSubtitles
http://opus.lingfil.uu.se/OpenSubtitles.php
• Can mine Twitter
• Look for replies to tweets using the API
• Ubuntu Dialog Corpus
• Dialogs on people wanting technical support
https://arxiv.org/abs/1506.08909
Sequence-to-sequence model
The sequence-to-sequence (seq2seq) model can encode
sequences of tokens, such as sentences, into single
vectors.
It can then decode these vectors into other sequences
of tokens.
Both the encoding and decoding are done using
recurrent neural networks (RNNs).
The initial big application for this was machine
translation. For example, where the source sentences
are English and the target sentences are Spanish.
Encoding sentence meaning into a vector
h0
How
“How are you?”
Encoding sentence meaning into a vector
h0
How
h1
are
“How are you?”
Encoding sentence meaning into a vector
h0
How
h1
are
h2
you
“How are you?”
Encoding sentence meaning into a vector
h0
How
h1
are
h2
you
h3
?
“How are you?”
Decoding sentence meaning
I
h3
Decoding sentence meaning
I
h3 h4
Decoding sentence meaning
I
h3
am
h4
Decoding sentence meaning
I
h3
am
h4
great
h5
!
h5
[Cho et al., 2014]
It keeps generating until it generates a stop symbol. Note that the lengths don’t
need to be the same.
• Treats this task like it is devoid of meaning.
• Great that this can work on just about any kind of seq2seq
problem, but this generality highlights its limitation for use
as language understanding.
Seq2seq implementation
Enterprise ready seq2seq implementation
https://google.github.io/seq2seq/
Code is here
https://github.com/google/seq2seq
Generative adversarial networks (GANs)
Adversarial Learning for Neural Dialogue Generation, Li et al., 2017.
https://arxiv.org/pdf/1701.06547.pdf
Code in Torch (not Python!) for neural dialog generation
https://github.com/jiweil/Neural-Dialogue-Generation
• GANs have a discriminator that tries to tell if the generated
response was from a real conversation or generated by the model
• All the rage in image processing
• Still a work in progress for language
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Intention-based agents
Amazon Echo
Image by https://www.flickr.com/photos/turoczy/
License https://creativecommons.org/licenses/by/2.0/legalcode
Examples: Amazon Echo, Google
Assistant, Siri, Cortana
Like a command language
1. Identify what the user wants the
machine to do (the “intent”)
2. Figure out the details of the
intent so the machine can take
action
How to determine the intent?
With a bag-of-words in scikit-learn (library for Python)
http://scikit-
learn.org/stable/auto_examples/applications/plot_out_of_core_classification
.html
Using deep learning with a convolutional neural network (CNN) in
TensorFlow (use this if you have a lot of data)
https://github.com/dennybritz/cnn-text-classification-tf
“Get me
fourteen
chickens.”
keywords or
text-based
classification
adjust lights
order groceries
make appointment
raise army
Use keywords or text-based classification
What to do with the intent
Convert the squishiness of language into a Python dictionary
“Get me
fourteen
chickens.”
Natural language
understanding
{‘domain’: ‘purchase’,
‘item’:‘chicken_id344’,
‘quantity’: 14}
Called a frame and slot semantics
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Natural language understanding with context
free grammars (compositional semantics)
$Order  $Purchase $ItemAmount, dunion(s[0],s[1])
$Purchase  is_purchase(tokens), {‘domain’: ’purchase’}
$ItemAmount  $Amount $Item, dunion(s[0],s[1])
$Amount  is_number(tokens), {‘amount’: get_number(tokens)}
$Item  is_item(tokens), {‘item’: get_item(tokens)}
def is_purchase(tokens):
return tokens in [‘get me’, ‘buy’, ‘grab me some’]
get_item(‘chickens’)  ‘chicken_id344’
get_item(‘soap’)  ‘soap_id143’
get_number(fourteen)  14
dunion: dictionary union
s[0] is the semantic value of the first item on rule right hand side
s[1] is the semantic value of the second item on rule right hand side
Parsing: applying rules to text to get semantics
Get me fourteen chickens
[Get:chickens]
[me:chickens]
[fourteen:chickens]
[chickens:chickens]
[Get:fourteen]
[me:fourteen]
[fourteen:fourteen]
[Get:me]
[me:me]
[Get:Get]
• Parsing is done using bottom-up dynamic programming.
• For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4)
• This is why the rules have to have two non-terminals on RHS. Not a problem. You can
always put a context free grammar in this form (called Chomsky Normal Form).
Parsing: applying rules to text to get semantics
7. $Item
4. $Amount 8. $ItemAmount
2. ‘me’ 5. $Amount 9. $Order
1. ‘get’ 3. $Purchase 6. $Amount 10. $Order
Get me fourteen chickens
• Parsing is done using bottom-up dynamic programming.
• For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4)
• This is why the rules have to have two non-terminals on RHS. Not a problem. You can
always put a context free grammar in this form (called Chomsky Normal Form).
Parsing: applying rules to text to get semantics
7. {‘item’:
‘chicken_id344’}
4. {‘amount’:14} 8. {‘item’:
‘chicken_id344’,
‘amount’:14}
2. ‘me’ 5. {‘amount’:14} 9. {‘domain’: ’purchase’,
‘item’: ‘chicken_id344’,
‘amount’:14,}
1. ‘get’ 3. {‘domain’:
’purchase’}
6. {‘amount’:14} 10. {‘domain’: ’purchase’,
‘item’: ‘chicken_id344’,
‘amount’:14,}
Get me fourteen chickens
• Parsing is done using bottom-up dynamic programming.
• For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4)
• This is why the rules have to have two non-terminals on RHS. Not a problem. You can
always put a context free grammar in this form (called Chomsky Normal Form).
Python code for natural language understanding
Code is available in Python in the SippyCup library
https://github.com/wcmac/sippycup
There can be many valid parses, and a scoring algorithm can be
used to choose which one to use
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Conversational agents
Extended, meaningful conversations. Have to be able to keep track of the state
of the conversation and know when the person wants to talk about something else.
A teacher for the young
• Starts out as a cell phone app for a child
• Child can talk to its cartoon face and show it her toys
• Teaches her things
• “If you have 7 giraffes and bought 3 more, how many would you have?”
• “If you eat your chocolate bear today, how are you going to feel tomorrow when
you no longer have it?”
A guide for the adult
• As the child grows, so does the app, so it becomes her operating system
• Knows what you know. Can give turn-by-turn directions on fixing the washing machine
An advocate for the old
• Could advocate for us and guide us through government and healthcare bureaucracies
• Could help us live independently longer.
• Imagine it sees you confused. Could talk you through making coffee.
Blog post I wrote, You and Your Bot: A New Kind of Lifelong Relationship
https://chatbotsmagazine.com/you-and-your-bot-a-new-kind-of-lifelong-relationship-6a9649feeb71
How could a machine manage such conversations?
A dialog manager needs to
Take the person through all the things it wants to talk about
• Teach her math
• Then talk about planets
Recognize when she wants to talk about something else
and queue the current topics for later
RavenClaw from CMU is probably the best known dialog manager
Principles of RavenClaw
RavenClaw dialog manager.
Part of CMU Olympus system http://wiki.speech.cs.cmu.edu/olympus/index.php/Olympus
Listening phase
Take what the person said and see which dialog agent can respond
Dialog agents
Little programs organized hierarchically that correspond to different bits of conversation
E.g., general dialog agent about cooking, wants to discuss multiple things
Dialog stack
Stack of dialog agents to keep track of all the things the machine wants to talk about
Expectation agenda
Data structure of dialog agents to keep track of what the machine expects to hear
Execution phase
Take top dialog agent off dialog stack and let it talk. Also, set up what the
machine expects to hear in the expectation agenda
Hierarchy of dialog agents
Ask 4+5
Teach Arithmetic
Teach Planets
Tell Stories
Dialog Stack Expectation Agenda
9
Teach Arithmetic
Teach Planets
Tell Stories
Talk about toys
Talk about
toys always
there.
Hierarchy of dialog agents
Ask 4+5
Teach Arithmetic
Teach Planets
Tell Stories
Dialog Stack Expectation Agenda
9
Teach Arithmetic
Teach Planets
Tell Stories
Talk about toys
Robot just finished asking, “What is 4 + 5?”
Child says: “Do you like Mr. Fluffles?”
Hierarchy of dialog agents
Robot just finished asking, “What is 4 + 5?”
Child says: “Do you like Mr. Fluffles?”
Robot responds: “Very nice. Is he your favorite?”
Ask 4+5
Teach Arithmetic
Teach Planets
Tell Stories
Dialog Stack Expectation Agenda
9
Teach Arithmetic
Teach Planets
Tell Stories
Talk about toys
Hierarchy of dialog agents
Robot just finished asking, “What is 4 + 5?”
Child says: “Do you like Mr. Fluffles?”
Robot responds: “Very nice. Is he your favorite?”
Now we are
talking about
toys.
Talk about toys
Teach Arithmetic
Teach Planets
Tell Stories
Dialog Stack
Yes or No
Teach Arithmetic
Teach Planets
Tell Stories
Talk about toys
Expectation Agenda
Hierarchy of dialog agents
Robot just finished asking, “What is 4 + 5?”
Child says: “Do you like Mr. Fluffles?”
Robot responds: “Very nice. Is he your favorite?”
Now we are
talking about
toys.
Child says, “Of course!”
Update database
with new favorite toy.
Talk about toys
Teach Arithmetic
Teach Planets
Tell Stories
Dialog Stack
Yes or No
Teach Arithmetic
Teach Planets
Tell Stories
Talk about toys
Expectation Agenda
State-based dialog agents
Markov decision process
Set of states
Set of actions
Get a reward for being in a state s and taking an action a
States are things such as what the bot knows (questions it has answered),
the last thing the bot said, and the last thing the user said.
Actions are making particular statements.
Reward comes from meeting a goal state, such as child giving correct answer to a
math problem or successfully completing a travel reservation.
Use reinforcement learning to learn a policy that gives the best action a for being
in state s.
Beginning with random exploration
In reinforcement learning, the agent begins by
randomly exploring until it reaches its goal.
Reaching the goal
• When it reaches the goal, credit is propagated back to its previous states.
• The agent learns the function Q(s,a), which gives the cumulative expected
discounted reward of being in state s and taking action a and acting according
to the policy thereafter.
Eventually, the agent learns the value of being in each state and
taking each action and can therefore always do the best thing in
each state.
Learning the behavior
But there is limited observability
• Since speech-to-text and natural language
understanding are error prone, you actually don’t
know for sure which state you are in.
• Does she want to talk about her toys, or is she
telling me that I should be fluffier?
• Partially Observable Markov Decision Process (POMDP)
• As you can guess, these need a lot of training data. Generally
have to create a simulation of a person for the bot to talk to.
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Basic working with text
spaCy is good for general text
processing.
O’Reilly video course I made on doing
NLP in Python (not free)
http://shop.oreilly.com/product/063692
0061007.do
Free video I made on tokenizing
text in spaCy
https://www.oreilly.com/learning/how-
can-i-tokenize-a-sentence-with-python
https://demos.explosion.ai/displacy
Tokenization result:
['Get', 'me', 'fourteen', 'chickens', '.']
Speech-to-Text in Python
Use SpeechRecognition 3.6.5 Python library
https://pypi.python.org/pypi/SpeechRecognition/
Good blog post by Gurwinder Gulati here
https://ggulati.wordpress.com/2016/02/24/coding-jarvis-in-python-3-in-2016/
Can also use WaveNet. TensorFlow implementation: https://github.com/buriburisuri/speech-to-text-wavenet
WaveNet paper: https://arxiv.org/abs/1609.03499
Sphinx doesn’t work well for me. I use Google Cloud Speech API
https://cloud.google.com/speech/
Look at:
https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/__init__.py
My modified version of Gurwinder’s blog post
Text-to-Speech in Python
Can also use WaveNet https://github.com/ibab/tensorflow-wavenet
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Additional resources not previously mentioned
• Jurafsky https://web.stanford.edu/class/cs124/lec/chatbot.pdf
• Jurafsky and Martin, Speech and Language Processing, Ch. 24, 2009
• New edition in progress https://web.stanford.edu/~jurafsky/slp3/
• Cathy Pearl, Designing Voice User Interfaces, 2016
Detailed resources are surprisingly hard to find
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Talk outline
What conversation is
The current state of chatbots
• Purposeless mimicry agents
• Intention-based agents
• Conversational agents
Other plumbing
Additional resources
Conclusion
Conclusion (1 of 3)
A
B
block
pillar
slab
beam
We can program this in
Computers need to know our conventions
Conclusion (2 of 3)
sensation representation action
“beam”
• Conventions need to be grounded in a system of sensation and action
• Hard when machines don’t have our bodies and experience
• Blog post of wrote in using physics simulations for natural language understanding
https://chatbotslife.com/computers-could-understand-natural-language-using-
simulated-physics-26e9706013da
Conclusion (3 of 3)
A fishing pole
is a stick, string
and hook
You can catch fish
with a fishing pole
Get me some fish
Acknowledgement
Acknowledgement
Break
Break
Machines also need to know the rules of conversation, so they can understand meanings
beyond words. And they need to understand meanings from how words are said.
I want me and my bot to have our
own culture. This ability to negotiate
meaning is what we would need.
Thanks for listening
Questions?
Jonathan Mugan
@jmugan

More Related Content

What's hot

Gdc2013 macton usability_is_not_random
Gdc2013 macton usability_is_not_randomGdc2013 macton usability_is_not_random
Gdc2013 macton usability_is_not_random
Mike Acton
 
02 naive bays classifier and sentiment analysis
02 naive bays classifier and sentiment analysis02 naive bays classifier and sentiment analysis
02 naive bays classifier and sentiment analysis
Subhas Kumar Ghosh
 

What's hot (16)

NLP
NLPNLP
NLP
 
Google BERT - What SEOs and Marketers Need to Know
Google BERT - What SEOs and Marketers Need to KnowGoogle BERT - What SEOs and Marketers Need to Know
Google BERT - What SEOs and Marketers Need to Know
 
Intro to nlp
Intro to nlpIntro to nlp
Intro to nlp
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Natural language procssing
Natural language procssing Natural language procssing
Natural language procssing
 
Pycon ke word vectors
Pycon ke   word vectorsPycon ke   word vectors
Pycon ke word vectors
 
Lesson 41
Lesson 41Lesson 41
Lesson 41
 
Gdc2013 macton usability_is_not_random
Gdc2013 macton usability_is_not_randomGdc2013 macton usability_is_not_random
Gdc2013 macton usability_is_not_random
 
02 naive bays classifier and sentiment analysis
02 naive bays classifier and sentiment analysis02 naive bays classifier and sentiment analysis
02 naive bays classifier and sentiment analysis
 
A Panorama of Natural Language Processing
A Panorama of Natural Language ProcessingA Panorama of Natural Language Processing
A Panorama of Natural Language Processing
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
HackYale - Natural Language Processing (Week 0)
HackYale - Natural Language Processing (Week 0)HackYale - Natural Language Processing (Week 0)
HackYale - Natural Language Processing (Week 0)
 
HackYale - Natural Language Processing (Week 1)
HackYale - Natural Language Processing (Week 1)HackYale - Natural Language Processing (Week 1)
HackYale - Natural Language Processing (Week 1)
 
HackYale - Natural Language Processing (All Slides)
HackYale - Natural Language Processing (All Slides)HackYale - Natural Language Processing (All Slides)
HackYale - Natural Language Processing (All Slides)
 
NLP 101 + Chatbots
NLP 101 + ChatbotsNLP 101 + Chatbots
NLP 101 + Chatbots
 

Similar to Data Day Seattle, Chatbots from First Principles

How to build someone we can talk to
How to build someone we can talk toHow to build someone we can talk to
How to build someone we can talk to
Jonathan Mugan
 

Similar to Data Day Seattle, Chatbots from First Principles (20)

Dialogare con agenti artificiali
Dialogare con agenti artificiali  Dialogare con agenti artificiali
Dialogare con agenti artificiali
 
Beginners chatbotai workshopdbb_bitfusion
Beginners chatbotai workshopdbb_bitfusionBeginners chatbotai workshopdbb_bitfusion
Beginners chatbotai workshopdbb_bitfusion
 
James Coplien - Trygve - October 17, 2016
James Coplien - Trygve - October 17, 2016James Coplien - Trygve - October 17, 2016
James Coplien - Trygve - October 17, 2016
 
CFP workshop
CFP workshopCFP workshop
CFP workshop
 
aOS Moscow - E1 - Bots and language understanding - Rick van Rousselt
aOS Moscow - E1 - Bots and language understanding - Rick van RousseltaOS Moscow - E1 - Bots and language understanding - Rick van Rousselt
aOS Moscow - E1 - Bots and language understanding - Rick van Rousselt
 
Best Practices for Designing High-Fidelity Voice Experiences
Best Practices for Designing High-Fidelity Voice ExperiencesBest Practices for Designing High-Fidelity Voice Experiences
Best Practices for Designing High-Fidelity Voice Experiences
 
God Mode for designing scenario-driven skills for DeepPavlov Dream
God Mode for designing scenario-driven skills for DeepPavlov DreamGod Mode for designing scenario-driven skills for DeepPavlov Dream
God Mode for designing scenario-driven skills for DeepPavlov Dream
 
Pml3
Pml3Pml3
Pml3
 
Ux scot voice usability testing with woz - ar and sf - june 2019
Ux scot   voice usability testing with woz - ar and sf  - june 2019Ux scot   voice usability testing with woz - ar and sf  - june 2019
Ux scot voice usability testing with woz - ar and sf - june 2019
 
Voice usability testing with WOZ methodology - UX SCOT 2019
Voice usability testing with WOZ methodology - UX SCOT 2019Voice usability testing with WOZ methodology - UX SCOT 2019
Voice usability testing with WOZ methodology - UX SCOT 2019
 
Deep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDeep Learning for Natural Language Processing
Deep Learning for Natural Language Processing
 
How To "Speak Developer"
How To "Speak Developer"How To "Speak Developer"
How To "Speak Developer"
 
Cloud AI GenAI Overview.pptx
Cloud AI GenAI Overview.pptxCloud AI GenAI Overview.pptx
Cloud AI GenAI Overview.pptx
 
Edit My College Essay. 10 Most Common Co
Edit My College Essay. 10 Most Common CoEdit My College Essay. 10 Most Common Co
Edit My College Essay. 10 Most Common Co
 
The Art and Science of Computer Conversation: Talkabot 2016
The Art and Science of Computer Conversation: Talkabot 2016The Art and Science of Computer Conversation: Talkabot 2016
The Art and Science of Computer Conversation: Talkabot 2016
 
Watch your language, young man!
Watch your language, young man!Watch your language, young man!
Watch your language, young man!
 
Deep Learning for NLP: An Introduction to Neural Word Embeddings
Deep Learning for NLP: An Introduction to Neural Word EmbeddingsDeep Learning for NLP: An Introduction to Neural Word Embeddings
Deep Learning for NLP: An Introduction to Neural Word Embeddings
 
How to tell a better story (in code)(final)
How to tell a better story (in code)(final)How to tell a better story (in code)(final)
How to tell a better story (in code)(final)
 
How to build someone we can talk to
How to build someone we can talk toHow to build someone we can talk to
How to build someone we can talk to
 
Reading Street
Reading StreetReading Street
Reading Street
 

Recently uploaded

Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotecAbortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
fztigerwe
 
原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证
pwgnohujw
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
dq9vz1isj
 
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
yulianti213969
 
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
zifhagzkk
 
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
a8om7o51
 
Displacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second DerivativesDisplacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second Derivatives
23050636
 

Recently uploaded (20)

Aggregations - The Elasticsearch "GROUP BY"
Aggregations - The Elasticsearch "GROUP BY"Aggregations - The Elasticsearch "GROUP BY"
Aggregations - The Elasticsearch "GROUP BY"
 
Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotecAbortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
Abortion pills in Riyadh Saudi Arabia (+966572737505 buy cytotec
 
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
 
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
Data Visualization Exploring and Explaining with Data 1st Edition by Camm sol...
 
原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
 
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital AgeCredit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
 
社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
 
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
 
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
 
Formulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdfFormulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdf
 
MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI  MANAJEMEN OF PENYAKIT TETANUS.pptMATERI  MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting Techniques
 
Bios of leading Astrologers & Researchers
Bios of leading Astrologers & ResearchersBios of leading Astrologers & Researchers
Bios of leading Astrologers & Researchers
 
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
 
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
如何办理加州大学伯克利分校毕业证(UCB毕业证)成绩单留信学历认证
 
Displacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second DerivativesDisplacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second Derivatives
 
Data Analysis Project Presentation : NYC Shooting Cluster Analysis
Data Analysis Project Presentation : NYC Shooting Cluster AnalysisData Analysis Project Presentation : NYC Shooting Cluster Analysis
Data Analysis Project Presentation : NYC Shooting Cluster Analysis
 
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
 

Data Day Seattle, Chatbots from First Principles

  • 1. dd Chatbots from First Principles Data Day Seattle October 19, 2017 Jonathan Mugan @jmugan
  • 2. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion The Slides from this talk are on SlideShare https://www.slideshare.net/jmugan /chatbots-from-first-principles
  • 3. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 4. Conversation requires shared reference Language begins with shared attention by pointing to things in the world. Words then point to shared ideas in our minds [Gärdenfors, 2014]. 3 2 1
  • 5. Language as shared convention A B Wittgenstein and his language games, Philosophical Investigations, 1958 block pillar slab beam Two people building something. “Bring me a beam.” Eventually turns into a shared convention for a community
  • 6. Our brains map community conventions to personal sensations and actions sensation representation action • When someone says “beam,” we map that to our experience with beams. • We understand each other because we have had similar experiences. See: Benjamin Bergen, Steven Pinker, Mark Johnson, Jerome Feldman, and Murray Shanahan “beam” This is what is means for language to be grounded.
  • 7. We negotiate language and meaning as we go Modified from Gärdenfors (2014), which was based on Winter (1998) Coordination of meaning Coordination of inner worlds Instruction Acknowledgement Acknowledgement Break Break • Levels of discourse • Complicated to go up and down the pyramid
  • 8. We negotiate language and meaning as we go A fishing pole is a stick, string and hook You can catch fish with a fishing pole Get me some fish Acknowledgement Acknowledgement Break Break • Levels of discourse • Complicated to go up and down the pyramid Modified from Gärdenfors (2014), which was based on Winter (1998)
  • 9. Conversation has its own rules (pragmatics) • Conversational maxims: Grice (1975, 1978) • Breaking these rules is a way to communicate more than the meaning of the words. Maxim of Quantity: Say only what is not implied. Yes: “Bring me the block.” No: “Bring me the block by transporting it to my location.” What did she mean by that? Maxim of Quality: Say only things that are true. Yes: “I hate carrying blocks.” No: “I love carrying blocks, especially when they are covered in fire ants.” She must be being sarcastic. Maxim of Relevance: Say only things that matter. Yes: “Bring me the block.” No: “Bring me the block and birds sing.” What did she mean by that? Maxim of Manner: Speak in a way that can be understood. Yes: “Bring me the block.” No: “Use personal physical force to levitate the block and transport it to me.” What did she mean by that?
  • 10. Sometimes meaning isn’t even in the words but how they are spoken (prosody) Example from Voice User Interface Design by Giangola and Balogh [2004] `` 1. You know. I don’t. [So don’t ask me.] 2. You know. I don’t. [As a matter of fact, I really don’t.] 3. You know I don’t. [You know that I don’t.] ‘’
  • 11. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 12. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 13. We’ve all heard of Eliza Python implementation at https://www.smallsurething.com/implementing-the- famous-eliza-chatbot-in-python/ I want to buy a car.  How much does a car cost? Simple substitutions to mimic a psychologist from the 1960s “My mother wants me to buy a bazooka.” … “Tell me why your mother wants you to buy a bazooka.” You can extend it as much as you want
  • 14. Modern mimicry agents are example based Take a bunch of dialogs and use machine learning to predict what the next statement will be given the last statement. • Movie and TV subtitles • OpenSubtitles http://opus.lingfil.uu.se/OpenSubtitles.php • Can mine Twitter • Look for replies to tweets using the API • Ubuntu Dialog Corpus • Dialogs on people wanting technical support https://arxiv.org/abs/1506.08909
  • 15. Sequence-to-sequence model The sequence-to-sequence (seq2seq) model can encode sequences of tokens, such as sentences, into single vectors. It can then decode these vectors into other sequences of tokens. Both the encoding and decoding are done using recurrent neural networks (RNNs). The initial big application for this was machine translation. For example, where the source sentences are English and the target sentences are Spanish.
  • 16. Encoding sentence meaning into a vector h0 How “How are you?”
  • 17. Encoding sentence meaning into a vector h0 How h1 are “How are you?”
  • 18. Encoding sentence meaning into a vector h0 How h1 are h2 you “How are you?”
  • 19. Encoding sentence meaning into a vector h0 How h1 are h2 you h3 ? “How are you?”
  • 23. Decoding sentence meaning I h3 am h4 great h5 ! h5 [Cho et al., 2014] It keeps generating until it generates a stop symbol. Note that the lengths don’t need to be the same. • Treats this task like it is devoid of meaning. • Great that this can work on just about any kind of seq2seq problem, but this generality highlights its limitation for use as language understanding.
  • 24. Seq2seq implementation Enterprise ready seq2seq implementation https://google.github.io/seq2seq/ Code is here https://github.com/google/seq2seq
  • 25. Generative adversarial networks (GANs) Adversarial Learning for Neural Dialogue Generation, Li et al., 2017. https://arxiv.org/pdf/1701.06547.pdf Code in Torch (not Python!) for neural dialog generation https://github.com/jiweil/Neural-Dialogue-Generation • GANs have a discriminator that tries to tell if the generated response was from a real conversation or generated by the model • All the rage in image processing • Still a work in progress for language
  • 26. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 27. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 28. Intention-based agents Amazon Echo Image by https://www.flickr.com/photos/turoczy/ License https://creativecommons.org/licenses/by/2.0/legalcode Examples: Amazon Echo, Google Assistant, Siri, Cortana Like a command language 1. Identify what the user wants the machine to do (the “intent”) 2. Figure out the details of the intent so the machine can take action
  • 29. How to determine the intent? With a bag-of-words in scikit-learn (library for Python) http://scikit- learn.org/stable/auto_examples/applications/plot_out_of_core_classification .html Using deep learning with a convolutional neural network (CNN) in TensorFlow (use this if you have a lot of data) https://github.com/dennybritz/cnn-text-classification-tf “Get me fourteen chickens.” keywords or text-based classification adjust lights order groceries make appointment raise army Use keywords or text-based classification
  • 30. What to do with the intent Convert the squishiness of language into a Python dictionary “Get me fourteen chickens.” Natural language understanding {‘domain’: ‘purchase’, ‘item’:‘chicken_id344’, ‘quantity’: 14} Called a frame and slot semantics
  • 31. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 32. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 33. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 34. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 35. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 36. Natural language understanding with context free grammars (compositional semantics) $Order  $Purchase $ItemAmount, dunion(s[0],s[1]) $Purchase  is_purchase(tokens), {‘domain’: ’purchase’} $ItemAmount  $Amount $Item, dunion(s[0],s[1]) $Amount  is_number(tokens), {‘amount’: get_number(tokens)} $Item  is_item(tokens), {‘item’: get_item(tokens)} def is_purchase(tokens): return tokens in [‘get me’, ‘buy’, ‘grab me some’] get_item(‘chickens’)  ‘chicken_id344’ get_item(‘soap’)  ‘soap_id143’ get_number(fourteen)  14 dunion: dictionary union s[0] is the semantic value of the first item on rule right hand side s[1] is the semantic value of the second item on rule right hand side
  • 37. Parsing: applying rules to text to get semantics Get me fourteen chickens [Get:chickens] [me:chickens] [fourteen:chickens] [chickens:chickens] [Get:fourteen] [me:fourteen] [fourteen:fourteen] [Get:me] [me:me] [Get:Get] • Parsing is done using bottom-up dynamic programming. • For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4) • This is why the rules have to have two non-terminals on RHS. Not a problem. You can always put a context free grammar in this form (called Chomsky Normal Form).
  • 38. Parsing: applying rules to text to get semantics 7. $Item 4. $Amount 8. $ItemAmount 2. ‘me’ 5. $Amount 9. $Order 1. ‘get’ 3. $Purchase 6. $Amount 10. $Order Get me fourteen chickens • Parsing is done using bottom-up dynamic programming. • For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4) • This is why the rules have to have two non-terminals on RHS. Not a problem. You can always put a context free grammar in this form (called Chomsky Normal Form).
  • 39. Parsing: applying rules to text to get semantics 7. {‘item’: ‘chicken_id344’} 4. {‘amount’:14} 8. {‘item’: ‘chicken_id344’, ‘amount’:14} 2. ‘me’ 5. {‘amount’:14} 9. {‘domain’: ’purchase’, ‘item’: ‘chicken_id344’, ‘amount’:14,} 1. ‘get’ 3. {‘domain’: ’purchase’} 6. {‘amount’:14} 10. {‘domain’: ’purchase’, ‘item’: ‘chicken_id344’, ‘amount’:14,} Get me fourteen chickens • Parsing is done using bottom-up dynamic programming. • For each box, it loops over all n possible midpoints. E.g., (1,4) -> (1,2),(2,4) and (1,3),(3,4) • This is why the rules have to have two non-terminals on RHS. Not a problem. You can always put a context free grammar in this form (called Chomsky Normal Form).
  • 40. Python code for natural language understanding Code is available in Python in the SippyCup library https://github.com/wcmac/sippycup There can be many valid parses, and a scoring algorithm can be used to choose which one to use
  • 41. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 42. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 43. Conversational agents Extended, meaningful conversations. Have to be able to keep track of the state of the conversation and know when the person wants to talk about something else. A teacher for the young • Starts out as a cell phone app for a child • Child can talk to its cartoon face and show it her toys • Teaches her things • “If you have 7 giraffes and bought 3 more, how many would you have?” • “If you eat your chocolate bear today, how are you going to feel tomorrow when you no longer have it?” A guide for the adult • As the child grows, so does the app, so it becomes her operating system • Knows what you know. Can give turn-by-turn directions on fixing the washing machine An advocate for the old • Could advocate for us and guide us through government and healthcare bureaucracies • Could help us live independently longer. • Imagine it sees you confused. Could talk you through making coffee. Blog post I wrote, You and Your Bot: A New Kind of Lifelong Relationship https://chatbotsmagazine.com/you-and-your-bot-a-new-kind-of-lifelong-relationship-6a9649feeb71
  • 44. How could a machine manage such conversations? A dialog manager needs to Take the person through all the things it wants to talk about • Teach her math • Then talk about planets Recognize when she wants to talk about something else and queue the current topics for later RavenClaw from CMU is probably the best known dialog manager
  • 45. Principles of RavenClaw RavenClaw dialog manager. Part of CMU Olympus system http://wiki.speech.cs.cmu.edu/olympus/index.php/Olympus Listening phase Take what the person said and see which dialog agent can respond Dialog agents Little programs organized hierarchically that correspond to different bits of conversation E.g., general dialog agent about cooking, wants to discuss multiple things Dialog stack Stack of dialog agents to keep track of all the things the machine wants to talk about Expectation agenda Data structure of dialog agents to keep track of what the machine expects to hear Execution phase Take top dialog agent off dialog stack and let it talk. Also, set up what the machine expects to hear in the expectation agenda
  • 46. Hierarchy of dialog agents Ask 4+5 Teach Arithmetic Teach Planets Tell Stories Dialog Stack Expectation Agenda 9 Teach Arithmetic Teach Planets Tell Stories Talk about toys Talk about toys always there.
  • 47. Hierarchy of dialog agents Ask 4+5 Teach Arithmetic Teach Planets Tell Stories Dialog Stack Expectation Agenda 9 Teach Arithmetic Teach Planets Tell Stories Talk about toys Robot just finished asking, “What is 4 + 5?” Child says: “Do you like Mr. Fluffles?”
  • 48. Hierarchy of dialog agents Robot just finished asking, “What is 4 + 5?” Child says: “Do you like Mr. Fluffles?” Robot responds: “Very nice. Is he your favorite?” Ask 4+5 Teach Arithmetic Teach Planets Tell Stories Dialog Stack Expectation Agenda 9 Teach Arithmetic Teach Planets Tell Stories Talk about toys
  • 49. Hierarchy of dialog agents Robot just finished asking, “What is 4 + 5?” Child says: “Do you like Mr. Fluffles?” Robot responds: “Very nice. Is he your favorite?” Now we are talking about toys. Talk about toys Teach Arithmetic Teach Planets Tell Stories Dialog Stack Yes or No Teach Arithmetic Teach Planets Tell Stories Talk about toys Expectation Agenda
  • 50. Hierarchy of dialog agents Robot just finished asking, “What is 4 + 5?” Child says: “Do you like Mr. Fluffles?” Robot responds: “Very nice. Is he your favorite?” Now we are talking about toys. Child says, “Of course!” Update database with new favorite toy. Talk about toys Teach Arithmetic Teach Planets Tell Stories Dialog Stack Yes or No Teach Arithmetic Teach Planets Tell Stories Talk about toys Expectation Agenda
  • 51. State-based dialog agents Markov decision process Set of states Set of actions Get a reward for being in a state s and taking an action a States are things such as what the bot knows (questions it has answered), the last thing the bot said, and the last thing the user said. Actions are making particular statements. Reward comes from meeting a goal state, such as child giving correct answer to a math problem or successfully completing a travel reservation. Use reinforcement learning to learn a policy that gives the best action a for being in state s.
  • 52. Beginning with random exploration In reinforcement learning, the agent begins by randomly exploring until it reaches its goal.
  • 53. Reaching the goal • When it reaches the goal, credit is propagated back to its previous states. • The agent learns the function Q(s,a), which gives the cumulative expected discounted reward of being in state s and taking action a and acting according to the policy thereafter.
  • 54. Eventually, the agent learns the value of being in each state and taking each action and can therefore always do the best thing in each state. Learning the behavior
  • 55. But there is limited observability • Since speech-to-text and natural language understanding are error prone, you actually don’t know for sure which state you are in. • Does she want to talk about her toys, or is she telling me that I should be fluffier? • Partially Observable Markov Decision Process (POMDP) • As you can guess, these need a lot of training data. Generally have to create a simulation of a person for the bot to talk to.
  • 56. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 57. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 58. Basic working with text spaCy is good for general text processing. O’Reilly video course I made on doing NLP in Python (not free) http://shop.oreilly.com/product/063692 0061007.do Free video I made on tokenizing text in spaCy https://www.oreilly.com/learning/how- can-i-tokenize-a-sentence-with-python https://demos.explosion.ai/displacy Tokenization result: ['Get', 'me', 'fourteen', 'chickens', '.']
  • 59. Speech-to-Text in Python Use SpeechRecognition 3.6.5 Python library https://pypi.python.org/pypi/SpeechRecognition/ Good blog post by Gurwinder Gulati here https://ggulati.wordpress.com/2016/02/24/coding-jarvis-in-python-3-in-2016/ Can also use WaveNet. TensorFlow implementation: https://github.com/buriburisuri/speech-to-text-wavenet WaveNet paper: https://arxiv.org/abs/1609.03499 Sphinx doesn’t work well for me. I use Google Cloud Speech API https://cloud.google.com/speech/ Look at: https://github.com/Uberi/speech_recognition/blob/master/speech_recognition/__init__.py My modified version of Gurwinder’s blog post
  • 60. Text-to-Speech in Python Can also use WaveNet https://github.com/ibab/tensorflow-wavenet
  • 61. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 62. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 63. Additional resources not previously mentioned • Jurafsky https://web.stanford.edu/class/cs124/lec/chatbot.pdf • Jurafsky and Martin, Speech and Language Processing, Ch. 24, 2009 • New edition in progress https://web.stanford.edu/~jurafsky/slp3/ • Cathy Pearl, Designing Voice User Interfaces, 2016 Detailed resources are surprisingly hard to find
  • 64. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 65. Talk outline What conversation is The current state of chatbots • Purposeless mimicry agents • Intention-based agents • Conversational agents Other plumbing Additional resources Conclusion
  • 66. Conclusion (1 of 3) A B block pillar slab beam We can program this in Computers need to know our conventions
  • 67. Conclusion (2 of 3) sensation representation action “beam” • Conventions need to be grounded in a system of sensation and action • Hard when machines don’t have our bodies and experience • Blog post of wrote in using physics simulations for natural language understanding https://chatbotslife.com/computers-could-understand-natural-language-using- simulated-physics-26e9706013da
  • 68. Conclusion (3 of 3) A fishing pole is a stick, string and hook You can catch fish with a fishing pole Get me some fish Acknowledgement Acknowledgement Break Break Machines also need to know the rules of conversation, so they can understand meanings beyond words. And they need to understand meanings from how words are said. I want me and my bot to have our own culture. This ability to negotiate meaning is what we would need.