Building Chatbots in Python
Alan Nichol
Co-founder and CTO, Rasa
atis_flight
atis_airfare
sentences_train[:2]
labels_train[:2]
[ "atis_flight",
"atis_flight"]
["i want to fly from boston at
838 am and arrive in denver at
1110 in the morning",
"what flights are available
from pittsburgh to baltimore
on thursday morning"]
import numpy as np X_train_shape = ( len(sentences_train), nlp.vocab.vectors_length)
X_train = np.zeros(X_train_shape)
for sentence in sentences_train: X_train[i,:] = nlp(sentence).vector
from sklearn.metrics.pairwise import cosine_similarity test_message = """ i would like to find a flight from charlotte to las vegas that makes a stop in st. louis""" test_x = nlp(test_message).vector
scores = [ cosine_similarity(X[i,:], test_x) for i in range(len(sentences_train) ]
labels_train[np.argmax(scores)]
'atis_flight'
from sklearn.svm import SVC
clf = SVC()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
Building Chatbots in Python