0
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='weathernlu')
    return model_directory


def run_nlu(model_dir):
    interpreter = Interpreter.load(model_dir)
    print(interpreter.parse("hello"))

I want to load multiple models to run. how can I use Interpreter to load multiple models in my python program?

luffysup
  • 3
  • 3

2 Answers2

0

You can simply store the different models in different directories, and then load the two different models from their respective directories.

def run_nlu(model_dir):
    interpreter1 = Interpreter.load(model1_dir)
    print(interpreter.parse("hello"))
    interpreter2 = Interpreter.load(model2_dir)
    print(interpreter.parse("hello"))
Parth Sharma
  • 441
  • 4
  • 19
0

If you're using Rasa NLU 0.12.3, you can use the method merge of class TrainingData. For example

from rasa_nlu.training_data import TrainingData, load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config

training_data = TrainingData()
nlu_trainings = ["data/examples/domain1.md", "data/examples/domain2.md"]
for nlu_training in nlu_trainings:
  training_data = training_data.merge(load_data(nlu_training)))

trainer = Trainer(config.load("sample_configs/config_spacy.yaml"))
trainer.train(training_data)
trainer.persist("./projects/default/")
Huong
  • 107
  • 2
  • 10