This project seeks to facilitate the exchange and diffusion of NER models built with different architectures. We strongly used the code from NCRF++ which allow to build various NER neural models in pytorch.
The tag_serve
repo adapts the ner model from NCRF++ and wrap it in a flask API to allow live demo via a web page and a deployment for medium scale production.
You can install tag_serve
from source by cloning the git repository:
git clone https://github.com/strayMat/tag_serve.git
Create a Python 3.6 virtual environment, and install the necessary requirements by running:
scripts/install_requirements.sh
(Add FR_MODEL=true before the script if you want to load the spacy language modele for french)
- Launch the API:
python app.py
- Open in the client in browser:
firefox client/pred_client.html
- Launch the API:
python app.py
- Launch call function:
python client/call.py -i decoding/ins/ -o decoding/outs/
(add-v
to get visualization.html
:python client/call.py -i decoding/ins/ -o decoding/outs/ -v
)
In your terminal, run :
curl -H 'Content-type:application/json' -d '{"file":"Paris is wonderful!"}' localhost:5000/predict
You can either give a specific model to the api, when launching the python code app.py
or replace the default model in the pretrained
directory.
-
Specify a model to
app.py
: Launch the api with the-m
option and specify yournew_model
name,python app.py -m myModel/new_model
where the foldermyModel
should containnew_model.xpt
andnew_model.model
(the architecture and the weights of the model). -
Replace the baseline model: Replace directly the baseline files in the pretrained directory: put new
baseline.xpt
andbaseline.model
in thepretrained/
folder (you can check that the default model of the app ispretrained/baseline
by typingpython app.py --help
)
You can deploy the model with docker. Go on docker website to install docker and docker-compose. Then build the docker with:
sudo docker build --build-arg http_proxy=$yourProxy -t yourTag .
Run the docker with :
sudo docker run -d -p 5000:5000 --name tagger yourTag python3 /app/app.py
You can now access the docker API with the call methods of your choice (client/call.py
, client/predict_client.html
or curl
)
Go see the demonstration notebook: train_decode_template.ipynb
-
NCRF++ : An Open-source Neural Sequence Labeling Toolkit, Yang et Zhang, 2018
-
Many thanks to Guillaume Genthial for the excellent blog post on python web-api with flask.