Nyanko Bot - Build a chat bot with Telegram Bot API

Nyanko Bot can translate from English to Vietnamese using a pretrained model generated by tensor2tensor To build a Telegram bot, refer to this tutorial Here are steps This is the remake chatbot, for the origin and most detailed, refer to this repo

Repo's structure

  • NyankoBot
    • colab/: stores data and model needed for translation
    • decodeF2F.py: main script using decode from file to file
    • decodeWServing: main script using decode with tensorflow server
    • Translator.py: function for decode from file to file
    • TranslateWithServing: function for decode with serving

Running

Using decode from file to file

python decodeF2F.py

Using decode with serving

Please refer to this page for more information

  • Requirements: tensorflow-model-server, tensorflow-serving-api
sudo apt install tensorflow-model-server
pip install tensorflow-serving-api
  • export model for serving
t2t-exporter \
  --model=transformer \
  --hparams_set=transformer_base \
  --problem=translate_envi_iwslt32k \
  --data_dir=colab/data \
  --output_dir=colab/train

you should have export/ directory inside colab/train/ now

  • launch server
tensorflow_model_server \
  --port=9000 \
  --model_name=translator\
  --model_base_path=absolute_path_to_export_folder
  • query the server
t2t-query-server \
  --server=localhost:9000 \
  --servable_name=translator \
  --problem=translate_envi_iwslt32k \
  --data_dir=~colab/data
  --inputs_once='your sentence'

for interactive querying, remove flag --inputs_once

  • Deployment with chatbot The deployment is inside decodeWServing.py To run the bot:
    • launch server as above
    • python decodeWServer.py