Building Chatbots in Python
Alan Nichol
Co-founder and CTO, Rasa
"can you help me please?"
Units | examples | vectors |
---|---|---|
characters | "c", "a", "n",... |
v_c, v_a, v_n, ... |
words | "can", "you", ... |
v_{can}, v_{you}, ... |
sentences | "can you help..." |
v_{can you help ...} |
Context | Candidates |
---|---|
let's meet at the ___ tomorrow | office, gym, park, beach, party |
I love going to the ___ to play with the dogs | beach, park |
import spacy
nlp = spacy.load('en')
nlp.vocab.vectors_length
300
doc = nlp('hello can you help me?')
for token in doc: print("{} : {}".format(token, token.vector[:3]))
hello : [ 0.25233001 0.10176 -0.67484999]
can : [-0.23857 0.35457 -0.30219001]
you : [-0.11076 0.30785999 -0.51980001]
help : [-0.29370001 0.32253 -0.44779 ]
me : [-0.15396 0.31894001 -0.54887998]
? : [-0.086864 0.19160999 0.10915 ]
import spacy nlp = spacy.load('en')
doc = nlp("cat")
doc.similarity(nlp("can"))
0.30165292161215396
doc.similarity(nlp("dog"))
0.80168555173294953
Building Chatbots in Python