This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
forked from peacecorps/PC-Prep-Kit
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shifted to RASA NLU + Integrated Bot with Angular Application
- Loading branch information
Showing
60 changed files
with
18,956 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
run: | ||
python bot.py run | ||
|
||
train-nlu: | ||
python bot.py train-nlu | ||
|
||
train-dialogue: | ||
python bot.py train-dialogue | ||
|
||
describe: | ||
python visualize.py | ||
|
||
learn: | ||
python train_online.py | ||
|
||
server: | ||
python -m rasa_core.server -d models/current/dialogue -u models/nlu/default/current -o out.log --cors "*" | ||
|
||
train-dialogue-default: | ||
python -m rasa_core.train -d domain.yml -s data/stories.md -o models/current/dialogue --epochs 200 | ||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import argparse | ||
import logging | ||
|
||
from policy import CustomPolicy | ||
from rasa_core import utils | ||
from rasa_core.actions import Action | ||
from rasa_core.agent import Agent | ||
from rasa_core.channels.console import ConsoleInputChannel | ||
from rasa_core.events import SlotSet | ||
from rasa_core.interpreter import RasaNLUInterpreter | ||
from rasa_core.policies.memoization import MemoizationPolicy | ||
from rasa_core.actions.forms import ( | ||
EntityFormField, | ||
FormAction, | ||
FreeTextFormField | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ActionPatientInformation(FormAction): | ||
RANDOMIZE = False | ||
|
||
@staticmethod | ||
def required_fields(): | ||
return [ | ||
EntityFormField("gender", "gender"), | ||
EntityFormField("age", "age"), | ||
] | ||
|
||
@classmethod | ||
def name(self): | ||
return 'action_patient_information' | ||
|
||
@classmethod | ||
def submit(self, dispatcher, tracker, domain): | ||
return [SlotSet("matches", "text")] | ||
|
||
|
||
class ActionSuggestNormal(Action): | ||
@classmethod | ||
def name(self): | ||
return 'action_suggest_normal' | ||
|
||
@classmethod | ||
def run(self, dispatcher, tracker, domain): | ||
medicines = ['Atovaquone', 'Chloroquine', 'Doxycycline', 'Mefloquine', 'Primaquine'] | ||
age = int(tracker.get_slot("age")) | ||
if age < 8: | ||
medicines.remove("Doxycycline") | ||
dispatcher.utter_message("You can take these medicines:\n" + ' '.join(medicines)) | ||
return [] | ||
|
||
|
||
class ActionSuggestPregnant(Action): | ||
def name(self): | ||
return 'action_suggest_pregnant' | ||
|
||
def run(self, dispatcher, tracker, domain): | ||
medicines = ['Chloroquine', 'Doxycycline', 'Mefloquine'] | ||
age = int(tracker.get_slot("age")) | ||
if age < 8: | ||
medicines.remove("Doxycycline") | ||
dispatcher.utter_message("You can take these medicines:\n" + ' '.join(medicines)) | ||
return [] | ||
|
||
|
||
class CheckAge(FormAction): | ||
RANDOMIZE = False | ||
|
||
@staticmethod | ||
def required_fields(): | ||
return [ | ||
EntityFormField("age", "age") | ||
] | ||
|
||
def name(self): | ||
return 'check_age' | ||
|
||
def submit(self): | ||
return | ||
|
||
|
||
def train_dialogue(domain_file="domain.yml", | ||
model_path="models/dialogue", | ||
training_data_file="data/stories.md"): | ||
agent = Agent(domain_file, | ||
policies=[MemoizationPolicy(max_history=3), | ||
CustomPolicy()]) | ||
|
||
training_data = agent.load_data(training_data_file) | ||
agent.train( | ||
training_data, | ||
epochs=400, | ||
batch_size=100, | ||
validation_split=0.2 | ||
) | ||
|
||
agent.persist(model_path) | ||
return agent | ||
|
||
|
||
def train_nlu(): | ||
from rasa_nlu.training_data import load_data | ||
from rasa_nlu import config | ||
from rasa_nlu.model import Trainer | ||
|
||
training_data = load_data('data/nlu_data/') | ||
trainer = Trainer(config.load("nlu_model_config.yml")) | ||
trainer.train(training_data) | ||
model_directory = trainer.persist('models/nlu', fixed_model_name="current") | ||
|
||
return model_directory | ||
|
||
|
||
def run(serve_forever=True): | ||
interpreter = RasaNLUInterpreter("models/nlu/default/current") | ||
agent = Agent.load("models/current/dialogue", interpreter=interpreter) | ||
|
||
if serve_forever: | ||
agent.handle_channel(ConsoleInputChannel()) | ||
return agent | ||
|
||
|
||
if __name__ == '__main__': | ||
utils.configure_colored_logging(loglevel="INFO") | ||
|
||
parser = argparse.ArgumentParser( | ||
description='starts the bot') | ||
|
||
parser.add_argument( | ||
'task', | ||
choices=["train-nlu", "train-dialogue", "run"], | ||
help="what the bot should do - e.g. run or train?") | ||
task = parser.parse_args().task | ||
|
||
# decide what to do based on first parameter of the script | ||
if task == "train-nlu": | ||
train_nlu() | ||
elif task == "train-dialogue": | ||
train_dialogue() | ||
elif task == "run": | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## intent:Female | ||
- Female | ||
- female | ||
- woman | ||
- Girl | ||
- Gal | ||
- Lady |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## intent:Male | ||
- male | ||
- man | ||
- Boy | ||
- Guy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## intent:affirm | ||
- yes | ||
- ya | ||
- Yes | ||
- Yup | ||
- Yes I am | ||
- It's true | ||
- Correct | ||
- Right | ||
- indeed | ||
- affirmative | ||
- agreed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## intent:botPlace | ||
- Where do you live | ||
- where are you | ||
- where can I meet you? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## intent:deny | ||
- No | ||
- no | ||
- not | ||
- no! | ||
- What!! No! | ||
- Nah | ||
- i deny that | ||
- impossible | ||
- not possible | ||
- that’s not correct | ||
- that’s a mistake | ||
- that’s incorrect | ||
- that’s not right | ||
- i disagree | ||
- i don’t think so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## intent:goodbye | ||
- bye | ||
- goodbye | ||
- good bye | ||
- stop | ||
- end | ||
- farewell | ||
- have a good one | ||
- lets close this conversation | ||
- have a good day | ||
- good night | ||
- talk to you later | ||
- ttyl | ||
- ciao | ||
- I’ve got to get going | ||
- I must leave now | ||
- I will leave now | ||
- I’m done | ||
- have a nice day | ||
- nice talking to you | ||
- until next time | ||
- gotta go now | ||
- see you | ||
- see ya | ||
- catch you later | ||
- later | ||
- I’m out of here | ||
- I gotta head out | ||
- I gotta take off now | ||
- maybe tomorrow then | ||
- we’ll continue some other time | ||
- shall we continue at a later time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## intent:greet | ||
- hey | ||
- howdy | ||
- hey there | ||
- hello | ||
- hi | ||
- good morning | ||
- good evening | ||
- dear sir | ||
- hi doctor | ||
- hi doc | ||
- how’s it going? | ||
- how are you doing? | ||
- What’s up? | ||
- What’s going on? | ||
- good afternoon | ||
- long time no see | ||
- lets chat | ||
- yo | ||
- Sup? | ||
- Wassup? | ||
- Wazzup? | ||
- Good day mate | ||
- Hiya | ||
- Hola | ||
- Ola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## intent:identity | ||
- Who are you | ||
- what's your name | ||
- what are you called | ||
- how are you called | ||
- your name | ||
- who you | ||
- you? | ||
- do i know you | ||
- may i know who this is | ||
- may i know who i am talking to | ||
- who am i talking to? | ||
- am i talking to a doctor? | ||
- am i talking to a human? | ||
- are you a girl? | ||
- are you a female? | ||
- are you a lady? | ||
- are you a man? | ||
- are you a boy? | ||
- are you a guy? | ||
- what is your gender? | ||
- may i know your name? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## intent:informAge | ||
- [18](age) | ||
- I am [17](age) | ||
- [17](age) years old | ||
- I’m [17](age) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## intent:informThird | ||
- Not applicable | ||
- third gender | ||
- Don’t wish to specify | ||
- Third gender | ||
- not applicable | ||
- not specifying | ||
- does not apply | ||
- not necessary | ||
- other | ||
- shall not specify | ||
- why specify? | ||
- will not tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## intent:intro | ||
- malaria | ||
- what is malaria | ||
- teach me malaria | ||
- everything about malaria | ||
- introduce malaria | ||
- tell me something about malaria | ||
- tell me more on malaria | ||
- Got any idea about malaria? | ||
- Definition of malaria | ||
- What does malaria mean? | ||
- Need help on malaria | ||
- Need info on malaria | ||
- Need information on malaria | ||
- What is this? | ||
- Mosquito transmitted diseases | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## intent:medicines | ||
- anti-malarial pills | ||
- suggest me medicines to prevent malaria | ||
- doctor, suggest me medicines to prevent malaria | ||
- what medicines I take to prevent it | ||
- medicines that I can take for malaria prevention | ||
- what medicines should I take to keep me safe from Malaria | ||
- are there any medicines that can keep me away from malaria? | ||
- are there any malaria resistant pills? | ||
- are there any pills that will keep me immune from malaria? | ||
- what medicines can I take to prevent malaria ? | ||
- malaria preventive pills | ||
- are there any pills that will cure malaria? | ||
|
Oops, something went wrong.