Building Chatbots in Python
Alan Nichol
Co-founder and CTO, Rasa
from rasa_nlu.converters import load_data
training_data = load_data("./training_data.json")
import json print(json.dumps(data.training_examples[22], indent=2))
{ "text": "i'm looking for a place in the north of town",
"intent": "restaurant_search",
"entities": [
{ "start": 31,
"end": 36,
"value": "north",
"entity": "location" }
]
}
message = "I want to book a flight to London"
interpreter.parse(message))
{ "intent": {
"name": "flight_search",
"confidence": 0.9
},
"entities": [
{ "entity": "location",
"value": "London",
"start": 27,
"end": 33
}
]
}
# Creating a model from rasa_nlu.config import RasaNLUConfig from rasa_nlu.model import Trainer
config = RasaNLUConfig( cmdline_args={"pipeline": "spacy_sklearn"})
trainer = Trainer(config)
interpreter = trainer.train(training_data)
spacy_sklearn_pipeline = [
"nlp_spacy",
"ner_crf",
"ner_synonyms",
"intent_featurizer_spacy",
"intent_classifier_sklearn" ]
# These two statements are identical:
RasaNLUConfig(cmdline_args={"pipeline": spacy_sklearn_pipeline})
<rasa_nlu.config.RasaNLUConfig at 0x10f60aa90>
RasaNLUConfig(cmdline_args={"pipeline": "spacy_sklearn"})
<rasa_nlu.config.RasaNLUConfig at 0x10f60aa20>
pipeline = [
"nlp_spacy",
"intent_featurizer_spacy",
"intent_featurizer_ngrams",
"intent_classifier_sklearn"
]
Building Chatbots in Python