I created this app to serve our English to Fongbe translation model, but you can use it as a template to serve your model too without much coding. The model used was created using this notebook from the Masakhane project.
git clone https://github.com/kevindegila/flask-joey
cd into the repo and Create a python 3.7 virtual environment with your desired env manager. Here is an exemple with conda:
cd flask-joey && conda create --name translator python=3.7
Activate the environment and install all the requirements:
conda activate translator && pip install -r requirements.txt
Run Python at your terminal
python3
Inside Python run the following command
>>> import sqlite3,os
>>> conn = sqlite3.connect("trReviews.sqlite")
>>> c = conn.cursor()
>>> c.execute('DROP TABLE IF EXISTS trReviews')
<sqlite3.Cursor object at 0x7f0fff6c2f10>
>>> c.execute('CREATE TABLE trReviews'\
... '(date TEXT, OriginalText TEXT, translationSuggested TEXT)')
<sqlite3.Cursor object at 0x7f0fff6c2f10>
>>> conn.commit()
>>> conn.close()
>>> exit()
To view each contribution run the following command
>>> for row in c.execute('SELECT * FROM trReviews'):
... print(row)
-
Your model : A checkpoint file named
best.ckpt
should be in thetransformer
older -
The source and target vocabulary named
src_vocab.txt
andtrg_vocab.txt
should be in thetransformer
folder. -
You don't need to change the config.yaml if you have a BPE based model.
-
Change the flag if your language is not from Benin 😄 . Just replace the image in the
static
folder and don't forget to update the name of the file in theindex.html
present in thetemplates
folder. No need to say you should change the title as well.
The model can be quite big and Github have restrictions on the size of your free repos. You can host your model on google drive as I do. If you want to try the English to fongbe model 😊 , you can download it here: https://drive.google.com/open?id=1PbrojtNSeZf8QpYmgJXtbcgYijVUU7Ay
I've left the vocab files in the repo. Just replace them with yours if you want to try your trained model.
You can run the app with this commmand and start making predictions
gunicorn -b 0.0.0.0:8080 app:app
and go to localhost:8080 to interact with the app
Thanks to the Masakhane community for providing everything needed to start this project: data, code and guidance. Join us in our effort to bring Africa on the Machine Translation Map
Thanks to Julia for JoeyNMT and Slack-joey. This is based of her work. I just added a simple front end and the flask code.