Telegram bot to monitor and control deep learning experiments
Deep learning training processes can run for many hours/days, and you are not always near your station to see how it's progressing or to make adjustments. Using this Telegram bot you can seamlessly get constant updates and even control your training process, all through your phone.
Works with TensorFlow & Keras (with Keras, all you need is to include a dedicated callback). Should also be good for Pytorch though I did not try. PRs are welcome!
- Get per epoch updates on the loss, accuracy etc.
- Change the learning rate
- Get loss convergence plots
- Kill the training process
- Query the latest LR or metrics
- Limit access to a specific Telegram user id
To start interacting with the bot, send
/start. At any time you can send
/help to see all available commands.
Automatic Epoch Updates:
Once you send
/start from your Telegram app, the bot will send you updates every epoch:
Modifying the learning rate:
Plotting convergence graphs
Stop training process
If you want, you can stop your training process from the app. Just send
/stoptraining and click on the Yes button.
With the Keras callback, training is stopped safely. Other operations that needed to happen after training will still take place:
- Keras (optional, if you want to use the Keras callback)
- matplotlib (optional, to send convergence plots )
Tested in the following environment:
- Python 3.5
- Tensorflow 1.11
- Keras 2.2.4
- Windows OS
$ pip install python-telegram-bot --upgrade
Clone this repository
dl_bot.pyto your project
telegram_bot_callback.pyto your project (optional, only if you use Keras)
First, create a Telegram bot using the Telegram app. It is very simple, just follow the steps in the dedicated section below. Once you have created your bot, search for it and start a conversation with it on the Telegram app.
You can supply a
user_id to restrict interaction with your bot only to a specific user. This is highly recommended.
(Instructions on how to find your user id are provided below)
You can either use the Keras callback to automatically interact with the bot, or to customize the interactions yourself.
Note that the bot will start sending messages only after you send it the
/start message from the app.
The following block is all you need in order to use the Keras Telegram bot callback:
# Telegram Bot imports from dl_bot import DLBot from telegram_bot_callback import TelegramBotCallback telegram_token = "TOKEN" # replace TOKEN with your bot's token # user id is optional, however highly recommended as it limits the access to you alone. telegram_user_id = None # replace None with your telegram user id (integer): # Create a DLBot instance bot = DLBot(token=telegram_token, user_id=telegram_user_id) # Create a TelegramBotCallback instance telegram_callback = TelegramBotCallback(bot)
telegram_callback to the list of callbacks passed to model.fit:
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_data=(x_test, y_test), callbacks=[telegram_callback])
That's all, you are good to go!
An example usage is included in
If you are using TensorFlow (or using Keras and want to customize interactions with the bot). Start by including the following code in your script:
# Telegram Bot imports from dl_bot import DLBot telegram_token = "TOKEN" # replace TOKEN with your bot's token # user id is optional, however highly recommended as it limits the access to you alone. telegram_user_id = None # replace None with your telegram user id (integer): # Create a DLBot instance bot = DLBot(token=telegram_token, user_id=telegram_user_id) # Activate the bot bot.activate_bot()
Then you will need to implement responses for the
Also, you will need to send the bot the loss values each epoch in order to use the
It is fairly easy to include these responses, a full example is included in
Implementation examples are included for both Keras and TensorFlow in
Both examples include all bot functions over the official keras/tf MNIST examples.
Creating a Telegram bot
To create a Telegram bot using the Telegram app, follow these steps:
- Open the Telegram app
- Search for the BotFather user (@botfather):
- Send /newbot and follow instructions on screen:
Finding your Telegram user id:
- Open the Telegram app
- Search for the userinfobot user (@userinfobot):