How to use a trained supervised_embeddings NLU pipeline to get the embedding of a user-inputted message?

I have trained an NLU model using the supervised_embedding pipeline. For my specific use case, I would now like to use the trained model to extract the embeddings for new messages, and then compare them with the embeddings of messages in the training data.

Through reading through the source code, I have tried different things such as:

from rasa.nlu.model import Interpreter
import os

interpreter = Interpreter.load(
    os.path.join('models', 'nlu-20200127-101026/nlu'),  # Had to extract the tar.gz model file before running this code
)

result = interpreter.parse('hello world')

print(result)

As expected, this just outputs the classified intent and the other most probable intents. I a not sure if I am heading in the correct direction.

How can I use the Python API to load a trained model, input a string of text, and receieve as output the embedding of this string?

If you add only_output_properties=False as an argument to interpreter.parse, the result returned will include text_sparse_features which I think is what you’re looking for. e.g.

 result = interpreter.parse('hello world',only_output_properties=False)
 print(result.get("text_sparse_features"))