-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnlu_model.py
More file actions
25 lines (18 loc) · 815 Bytes
/
nlu_model.py
File metadata and controls
25 lines (18 loc) · 815 Bytes
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
# Prepare Rasa Interpreter (models/nlu)
from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer, Interpreter
import os
def train_nlu(data, configs, model_dir):
training_data = load_data(data)
trainer = Trainer(config.load(configs))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name='grandmarecipes')
# Test Rasa Interpreter
def run_nlu():
interpreter = Interpreter.load('./models/nlu/default/grandmarecipes')
print(interpreter.parse(u"I have chicken and rice")) # Successfully identified 'chicken' and 'rice' as ingredients
if __name__ == '__main__':
if not os.path.isdir(os.getcwd() + "/models"):
train_nlu('./data/data.json', 'config_spacy.json', './models/nlu')
run_nlu()