Spacy - Rasa open source - Docker-compose

Hi,

I am deploying my agent via Rasa open source and docker-compose. I have two Dockerfiles, one for the action server and one for the rasa server. Now I want to add spacy for the French language and am not sure how to accomplish that. Am I correct that I need to add the installation of spacy to the Dockerfile for the rasa server? That Dockerfile currently looks like this:

FROM python:3.8

USER root

COPY requirements.txt .
RUN pip install -r requirements.txt

USER 1001

WORKDIR /app

COPY . /app

ENTRYPOINT ["rasa", "run", "--enable-api"]

Now I added the following lines in the Dockerfile (after the line about installing requirements):

RUN python -m spacy download fr_core_news_lg
RUN python -m spacy link fr_core_news_lg fr

And I also added spacy to my requirements.txt file. I tried both simply adding “spacy” as a requirement after my Rasa requirement and using “rasa[spacy]==2.8.3”.

But now I still get the following error when running docker-compose up:

rasa_server_1   | 2022-01-26 17:22:02 INFO     root  - Starting Rasa server on http://localhost:5005
rasa_server_1   | 2022-01-26 17:22:02 INFO     rasa.model  - Loading model models/20220126-170257.tar.gz...
rasa_server_1   | 2022-01-26 17:22:04 ERROR    rasa.core.agent  - Could not load model due to Not all required importable packages are installed to use the configured NLU pipeline. To use this pipeline, you need to install the missing modules:
rasa_server_1   |   - spacy (needed for rasa.nlu.utils.spacy_utils.SpacyNLP)
rasa_server_1   | Please install the packages that contain the missing modules..
rasa_server_1   | /usr/local/lib/python3.8/site-packages/rasa/shared/utils/io.py:97: UserWarning: The model at 'models' could not be loaded. Error: <class 'rasa.exceptions.MissingDependencyException'>: Not all required importable packages are installed to use the configured NLU pipeline. To use this pipeline, you need to install the missing modules:
rasa_server_1   |   - spacy (needed for rasa.nlu.utils.spacy_utils.SpacyNLP)
rasa_server_1   | Please install the packages that contain the missing modules.
rasa_server_1   | /usr/local/lib/python3.8/site-packages/rasa/shared/utils/io.py:97: UserWarning: Agent could not be loaded with the provided configuration. Load default agent without any model.

It would be great if somebody could explain to me what I am missing here. Everything worked fine before I trained my model by also using spacy. Everything also works fine locally without docker.

Thanks a lot in advance!

Hello @annaf, it means you want to add the spacy pipeline using docker-compose?

@annaf you had planned for local machine or server?

Hi, @nik202, thanks a lot for the quick response!

Yes, exactly. I followed the instructions (Tuning Your NLU Model) for changing my config.yml-file when wanting to add a spacy language model. Then I locally trained the model based on this new pipeline. I then tested the model locally without docker-compose, and it worked.

Our application will run on a server in the end (it also has lots of other components besides rasa), and we are using docker-compose for that. Right now I just tested if the docker-compose approach worked locally (we do not yet have the server set up) - and that is where I got the error I described above. So I think I do not understand properly where I need to add spacy in the docker-compose approach. Would be very much appreciated if you could help me with that!

@annaf I guess your Dockerfile is correct whilst using the spacy. Can you check on Dockerhub does Rasa open source have some image with spacy?

I wish this thread will help you: How i can use Spacy fr package with Docker? - #2 by matthiask

@nik202 , thanks a lot, I will have a look!

I am not sure why it suddenly worked in the end, but I tried some things and once I finally made a separate requirement for spacy in my requirements.txt rather than using rasa[spacy]==2.8.3 it worked.

My final Dockerfile was like this:

FROM python:3.8

USER root

COPY requirements.txt .
RUN pip install -r requirements.txt

# Spacy language model
RUN python -m spacy download fr_core_news_lg
RUN python -m spacy link fr_core_news_lg fr

USER 1001

WORKDIR /app

COPY . /app

ENTRYPOINT ["rasa", "run", "--enable-api"]