This repository provides you with some code examples on how to live tweet or message model optimization results. The callbacks should work out of the box both for keras and tensorflow keras / tf.keras, although I only tested with tf.keras.
Below, I will point you towards the resources required to set up a Telegram or Twitter bot. You need to get API tokens for each, but the process is pretty straight forward and should only take a couple of minutes.
Setting up the Twitter bot worked more smoothly for me than Telegram.
-
Install the
Twython
package with$ pip install twython
-
Follow the steps as described in this explanation to get developer access and to get the required API tokens.
-
Save the tokens to
auth.py
if you want to run the example attached. Adhere to the variable names that are already set.
Telegram was a bit trickier to set up, mainly recovering the chat_id
. I will elaborate on that later.
-
Install
python-telegram-bot
with$ pip install python-telegram-bot --upgrade
-
Message the BotFather as described here to set up a new bot. Basically, you just need to message
/newbot
in the chat that pops up upon clicking this link. BotFather will send you a token for your bot. Save this toauth.py
. You will also receive a link to your bot similar as for the BotFather. If you click it, a chat with your bot will start. -
Next, you need to obtain the
chat_id
of the conversation with your bot. Now this part proved a bit tricky for me. Send a message to your bot from the phone that you want to use to monitor the model fitting. This can in theory be done by messaging the bot once and then openinghttps://api.telegram.org/bot<bot_token>_/getUpdates
where you replace<bot_token>
by the token you got from the BotFather. For me, following this link at first displayed a link with a true request message but nothing else. After approximately two hours, it displayed the messages that I sent to the bot and I could read theid
field, as e.g. described here.. However, I got a bit frustrated at this step because I initially could not see any reason why theid
didn't show as described. Probably it is best to be a bit patient. Once you got theid
, add it aschat_id
toauth.py
to run the example.