I have trained a Rasa NLU model for intent classification and entity extraction and uploaded it to a S3 bucket.
Now how do I load it to Rasa Server using a python script?
For example, using a CLI cmd: rasa run --model spacynlu.tar.gz --remote-storage aws I can start the rasa server and load the model.
How do I achieve this using a python script?
A bit late to the party, but here is a solution for rasa 3.2.6.
I'm not sure about your exact use case - whether you want to launch the Rasa server from a Python script, or to load a model and use it for predictions. The solution below is for the later case. However, it should also help for the former use case - in general, you will need to set the environment variables as described below, and then use
os.system(server_cmd)for launching the server, whereserver_cmdis the command you usually use for running the server, for examplejust make sure that the value of
--modelis the full path in S3 to your model.Using
rasafor parsing messages in a Python script, using a model stored on AWS S3Rasa is using
boto3for accessing S3, so you need to have it installed. Then you need to set the environment variables used byboto3for accessing and authenticating. For example:You can, of course, set these variables in the shell, just make sure you export them.
For knowing the correct value for
AWS_ENDPOINT_URLyou can consult AWS documentation at https://docs.aws.amazon.com/general/latest/gr/s3.html.Now you can initialize an agent
load_agentis a global function inrasa.core.agent. Note themodel_pathis the full path to the model, starting from the S3 bucket. Also note the use ofasyncio.run- this could probably be done in other ways, for example, for loading multiple agents/models simultaneously.Once you obtain an agent instance, you can call, for example, the
parse_messagemethod on it(again, you can use
asyncioin other ways.)You can read the Rasa official documentation at https://rasa.com/docs/rasa/model-storage/#load-model-from-cloud, but it lacks some details.