Robustní NLU s Rasa

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Rasa NLU

  • Knihovna pro rozpoznávání záměrů a extrakci entit
  • Postavena na spaCy, scikit-learn a dalších knihovnách
  • Vestavěná podpora pro úlohy specifické pro chatboty
Building Chatbots in Python

Formát dat 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" }
  ]
}
Building Chatbots in Python

Interpretery

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
    }
  ]
}
Building Chatbots in Python

Použití Rasa

# 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)
Building Chatbots in Python

Pipelines v Rasa

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>
Building Chatbots in Python

Podmíněná náhodná pole

  • Model strojového učení, oblíbený pro rozpoznávání pojmenovaných entit
    • dobře funguje i s malými trénovacími daty
Building Chatbots in Python

Zpracování překlepů

pipeline = [
    "nlp_spacy",
    "intent_featurizer_spacy",
    "intent_featurizer_ngrams",
    "intent_classifier_sklearn"
]
Building Chatbots in Python

Pojďme si procvičit!

Building Chatbots in Python

Preparing Video For Download...