-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
28 lines (26 loc) · 1.04 KB
/
Copy pathmodel.py
File metadata and controls
28 lines (26 loc) · 1.04 KB
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
28
import os
import re
from rasa_nlu import config
from rasa_nlu.training_data import load_data
from rasa_nlu.model import Interpreter, Trainer
from settings import models_path, reg_rule, config_file, data, saving_path
class nlu_model(object):
def __init__(self, models_path=models_path, reg_rule=reg_rule):
if os.path.exists(models_path):
models_name = os.listdir(models_path)
if models_name:
model_name = models_name[0]
if re.match(reg_rule, model_name):
model_path = models_path + '/' + model_name
self.interpreter = Interpreter.load(model_path)
else:
self.train()
else:
self.train()
else:
self.train()
def train(self, config_file=config_file, data=data, saving_path=saving_path):
trainer = Trainer(config.load(config_file))
training_data = load_data(data)
self.interpreter = trainer.train(training_data)
trainer.persist(saving_path)