How do I extract the contents of the NLU file as a dictionary or list?

I would like to gather all training examples into a list. Currently, I have

from rasa.shared.nlu.training_data.training_data import TrainingData

training_data = TrainingData()
training_examples = training_data.training_examples

but this returns an empty list since no arguments are passed to the TrainingData constructor, defaulting to None. I’m not sure what arguments I should pass in order to get the NLU file’s contents, or if this is even the right way to go about doing this.

Could you help me understand a little bit more about your use-case? Is this in a custom component? Or an action? Or something else entirely? Asking because depending on what objects you already have might affect the answer to “if this is even the right way to go about doing this.”

Hi @fkoerner, my use-case is that I have a custom NLU component which corrects misspelled words. Since there are certain names and abbreviations in the NLU data which are not typical English words, I want to add them all to my custom component’s list of recognized words. So I plan on doing this within the Component class that I built.

Okay, training_data is passed into the train method of components (see here). You should be able to access training examples like so: training_data.training_examples. Can you use this?

Note this will give you a list of Message objects. You may want to access the text attribute of each Message.

That works, thank you! There were some actions included with the NLU examples, so I had to use a list comprehension:

training_examples = [[“text"] 
                     for message in training_data.training_examples 
                     if "text" in]