-
Notifications
You must be signed in to change notification settings - Fork 46
/
nlu_model.py
executable file
·27 lines (23 loc) · 979 Bytes
/
nlu_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''
Author: Nahid Alam
Works with Rasa NLU 0.12.3
Rasa Core version 0.9.0a3 (master)
'''
from rasa_nlu.training_data import load_data
#from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu import config
from rasa_nlu.model import Metadata, Interpreter
def train_nlu(data, configuration, model_dir):
training_data = load_data(data)
trainer = Trainer(config.load(configuration))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name = 'customernlu')
return model_directory
def run_nlu(model_directory):
#interpreter = Interpreter.load('./models/nlu/default/customernlu', RasaNLUModelConfig('config_spacy.yml'))
interpreter = Interpreter.load(model_directory)
print(interpreter.parse(u"I am planning my to order an 829 router. How much does it cost?"))
if __name__ == '__main__':
model_directory = train_nlu('./data/data.json', 'config_spacy.yml', './models/nlu')
run_nlu(model_directory)