Use NLU pipeline programmatically

Hi,

I would like to use the NLU pipeline only, programmatically, and obtain at the end of the process a list of intents and entities detected along with confidence scores. I’m not interested in making use of the policy and the response modules. Essentially I’d like to do something like this:

nlu_classification_response = rasa.<???>(user_input)

where nlu_classification_response is the output of the DIET classifier after having run the entire NLU pipeline defined in the config.yml file. I would also like to maintain the ability to train the model from the command line, without the need for stories and rules though. Is this possible ?

Thanks

I figured out the training part, which is literally two lines of code, pretty impressive. Having an empty stories file will only train the NLU model according to the logs, which is what I need.

import rasa

model_file = rasa.train("domain.yml", "config.yml", ["stories.yml", "rasa-dataset.json"], "./output", force_training=True)

Update:

Inference is also pretty easy:

import asyncio
from rasa.shared.utils.io import json_to_string
from rasa.core.agent import Agent
import rasa.model

latest_model = rasa.model.get_latest_model() # models must be in a folder called "models"
agent = Agent.load(latest_model)
prediction = asyncio.run(agent.parse_message("Hello"))

print(json_to_string(prediction))

Hope it helps others with the same problem.

2 Likes