Building a bot using Rasa NLU & Core

Fig 1. rasa-stack
#NLU
python -m pip install rasa_nlu[spacy]
#Core
python -m pip install -U rasa_core == 0.9.6
#Language Model
python -m spacy download en_core_web_md
python -m spacy link en_core_web_md en --force;
## intent:greet
- Hi
- Hey
- Hi bot
- Hey bot
- Hello
## intent:thanks
- Thanks
- Thank you
- Thank you so much
- Thanks bot
- Thanks for that
- cheers
- cheers bro
## intent:name
- My name is [Juste](name)
- I am [Josh](name)
- I'm [Lucy](name)
- People call me [Greg](name)
- It's [David](name)
- Usually people call me [Amy](name)
- My name is [John](name)
- You can call me [Sam](name)
- Please call me [Linda](name)
## intent:joke
- Can you tell me a joke
- I would like to hear a joke
- Tell me a joke
- A joke please
- Tell me a joke please
- I would like to hear a joke
- I would loke to hear a joke, please
- Can you tell jokes?
- Please tell me a joke
- I need to hear a joke
language: "en"
pipeline: spacy_sklearn
.PHONY: clean train-nlu train-core cmdline server
TEST_PATH=./
help:
@echo " clean"
@echo " Remove python artifacts and build artifacts."
@echo " train-nlu"
@echo " Trains new nlu model using the projects Rasa NLU config"
@echo " train-core"
@echo " Trains new dialogue model using the story training data"
@echo " action-server"
@echo " Starts the server for custom action."
@echo " cmdline"
@echo " Will load the assistant in your terminal for you to chat."
clean:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
rm -rf build/
rm -rf dist/
rm -rf *.egg-info
rm -rf docs/_build
train-nlu:
python -m rasa_nlu.train -c nlu_config.yml --data data/nlu_data.md -o models --fixed_model_name nlu --project current --verbose
train-core:
python -m rasa_core.train -d domain.yml -s data/stories.md -o models/current/dialogue -c policies.yml
cmdline:
python -m rasa_core.run -d models/current/dialogue -u models/current/nlu --endpoints endpoints.yml
action-server:
python -m rasa_core_sdk.endpoint --actions actions
make train-nlu
Fig 2. training-flu
## story_goodbye
* goodbye
- utter_goodbye
## story_thanks
* thanks
- utter_thanks
## story_name
* name{"name":"Sam"}
- utter_greet
## story_joke_01
* joke
- action_joke
## story_joke_02
* greet
- utter_name
* name{"name":"Lucy"}
- utter_greet
* joke
- action_joke
* thanks
- utter_thanks
* goodbye
- utter_goodbye
intents:
- greet
- goodbye
- thanks
- deny
- joke
- name
entities:
- name
slots:
name:
type: text
actions:
- utter_name
- utter_thanks
- utter_greet
- utter_goodbye
- action_joke
templates:
utter_name:
- text: "Hey there! Tell me your name."
utter_greet:
- text: "Nice to you meet you {name}. How can I help?"
utter_goodbye:
- text: "Talk to you later!"
utter_thanks:
- text: "My pleasure."
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import requests
import json
from rasa_core_sdk import Action
logger = logging.getLogger(__name__)
class ActionJoke(Action):
def name(self):
return "action_joke"
def run(self, dispatcher, tracker, domain):
request = json.loads(requests.get('https://api.chucknorris.io/jokes/random').text)
joke = request['value']
dispatcher.utter_message(joke)
return []
make train-core
Fig 3. training-core
make cmdline
Fig 4. cmdline

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store