OK I found a way, documenting here in the hope it’s useful. Full code to train model, create an interpreter and run against some sample utterances as follows:
import nest_asyncio
nest_asyncio.apply()
from rasa.train import train_nlu
model_path = train_nlu("config.yml", "data/nlu.yml", "models/")
from rasa import model
from rasa.nlu.model import Interpreter
unpacked_model = model.get_model("models/")
_core, nlu_model = model.get_model_subdirectories(unpacked_model)
interpreter = Interpreter.load(nlu_model)
import pandas as pd
from IPython.display import display, HTML
def test(utterances):
"""Utility function to run interpreter on a list of utterances and print the results"""
results = []
for utterance in utterances:
result = interpreter.parse(utterance)
intent = result["intent"]["name"]
confidence = result["intent"]["confidence"]
results.append([utterance, intent, confidence])
#Use a dataframe to print things out nicely
df = pd.DataFrame(results, columns=["Utterance", "Intent", "Confidence"])
display(HTML(df.to_html()))
utterances = [
"I want a pizza",
"I'm hungry, order me a pizza",
"please order pizza",
"call the pizza shop",
"I'm hungry, get me some food"
]
test(utterances)