Skip to main content

Communicate your project updates via Telegram Bot!

Project description

ChaterJee

ChaterJee

Often, we need to run computational trial and error experiments by just tweaking one or two key parameters. In machine learning, you face similar problems during hyperparameter tuning experiments.

These are probably the most boring, time-consuming, yet unavoidable phases in our day-to-day research. But what if your experiments could keep working while you're at a date XD ? What if you could kick off a hyperparameter tuning run just before bed — and wake up with results and plots waiting on your phone, like a good morning message from your research? Real-time updates, one-tap reruns, and zero late-night debugging. It’s like having a research assistant in your pocket.

Let me introduce ChaterJee to you — a playful fusion of Chater, meaning one who chats, and Jee, an honorific used in Indian culture to show respect. Think of ChaterJee as the lab assistant you always wanted — one who actually responds, never crashes your code, doesn't ask for co-authorship, and definitely doesn't need coffee all the time, unlike you.

Installation

As a prerequisite you are required to install the jq library for reading JSON files from bash script.

sudo apt update
sudo apt install jq

Now, you need two things:

  1. The ChaterJee module
  2. A telegram BOT that you own

Installing the module

I recommend to install ChaterJee module inside your project's conda environment for a seamless experience.

conda activate yourenv
pip install ChaterJee

Get your telegram BOT

To use this ChaterJee, you'll need a Telegram Bot Token and your Chat ID. Follow these simple steps:

Create a Bot and Get the Token

  • Open Telegram and search for @BotFather.
  • Start a chat and send the command /newbot.
  • Follow the prompts: choose a name and a username for your bot.
  • Once done, BotFather will give you a bot token — a long string like 123456789:ABCdefGhiJKlmNoPQRsTuvWXyz.

Get Your Chat ID

  • Open Telegram and start a chat with your newly created bot by searching its username.

  • Send Hi (any message) to your bot.

  • Open your browser and visit this URL, replacing YOUR_BOT_TOKEN with your token: https://api.telegram.org/bot{YOUR_BOT_TOKEN}/getUpdates

    with the above token, this URL becomes: https://api.telegram.org/bot123456789:ABCdefGhiJKlmNoPQRsTuvWXyz/getUpdates

  • Look for "chat":{"id":...} in the JSON response. This number is your Chat ID.

Quick Start

ChaterJee has two components.

  • NoteLogs class: This stores log files, and save project locations for parsing updates.
  • ChatLogs class: This reads log files, the last line is sent to you via the BOT. It can also share you final plots that you need for your next rerun.

The minimal example

This will register your JOB with the given JOBNAME and logfiles into a JSON file, <your home>/.data/JOB_status.json.

script.py

# This is a minimal example

# Your imports
from pathlib import Path
import ChaterJee
import json

# your code here
with open("hyperparams.json","r") as ffr:
    HYPERPARAMS = json.load(ffr)
    # get your parameters
    JOBNAME = HYPERPARAMS["JOBNAME"]
    LOGDIR = HYPERPARAMS["LOGDIR"]
    LOGFILE = HYPERPARAMS["LOGFILE"]
    LOGIMAGE = HYPERPARAMS["LOGIMAGE"]

notelogs = ChaterJee.NoteLogs()
notelogs.write(
    jobNAME=JOBNAME,
    logDIR=LOGDIR,
    logFILE=LOGFILE,
    logIMAGE=LOGIMAGE
    )

### Your code that generates logs
print(f"{logs}")

### Your code that generates plot
logPath = Path(LOGDIR)
plt.savefig(logPath / LOGIMAGE)

The hyperparams.json file should look like the following. It must contain the last 4 {key: value} pairs to let our BOT access the log results.

hyperparams.json

{
    .
    .

    "JOBNAME": "model_2.4",
    "LOGDIR": "./run_2.4",
    "LOGFILE": "outFile.log",
    "LOGIMAGE": "outImage.png"
}

Save the following script in your working directory to rerun your tuning experiments quickly.

run.sh

#!/bin/bash

# Path to hyperparameter file
hyparam_file="hyperparams.json"

# Read values from config.json using jq
stdout_log=$(jq -r '.LOGFILE' "$hyparam_file")
stdout_dir=$(jq -r '.LOGDIR' "$hyparam_file")

# Create log directory
mkdir -p "$stdout_dir"

# Run the Python script with redirected logs
nohup python script.py --hyprm "$hyparam_file" > "$stdout_dir/$stdout_log" 2> "$stdout_dir/error.log" &

Next step is to receive updates on your projects.

updater.py

# Run this instance separately to parse job updates
# This is the one which actually communicates with your BOT.

import ChaterJee

if __name__ == '__main__':
    TOKEN = '123456789:ABCdefGhiJKlmNoPQRsTuvWXyz'
    CHATID = '123456789'

    cbot = ChaterJee.ChatLogs(TOKEN, CHATID)
    cbot.cmdTRIGGER()

Run the above script in a separate terminal session to start interacting with your BOT.

At your Telegram App

  • Think your inbox as the terminal.
  • cd, ls etc. works as expected. Therefore to go to parent directory, you simply type: cd .. , and to list contents type ls . You can run the run.sh executable just by typing ./run.sh .
  • texts starting with / are telegram-BOT commands.

At this stage the following 4 commands work:

  • /start : Starts the conversation with the BOT.
  • /jobs : List the jobs as Keyboard button options.
  • /clear : Clears the chat history once you allow.
  • /edit file.json : Let you edit and save the JSON file by the webapp Editor Babu.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chaterjee-0.4.9.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chaterjee-0.4.9-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file chaterjee-0.4.9.tar.gz.

File metadata

  • Download URL: chaterjee-0.4.9.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for chaterjee-0.4.9.tar.gz
Algorithm Hash digest
SHA256 d3f59b1a6557dd8ea9f8566b4eefb42f071ad85d92c432a1b60006352f427597
MD5 127cb69843cc029a6a80be48bc5702d0
BLAKE2b-256 93f66a33412f02581eb9ecf4dbc59dd9f7f3211797debad5a76baedb6beb9f97

See more details on using hashes here.

File details

Details for the file chaterjee-0.4.9-py3-none-any.whl.

File metadata

  • Download URL: chaterjee-0.4.9-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for chaterjee-0.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fa6f059312fb8ea6a2c96c56a859d00cbdd05926621698f500ec43c1e69969cf
MD5 ee882ebd392d9528e8189861a9251ce3
BLAKE2b-256 2e8beb4d172eecc366e0ad4981dc0e2d59699d7c96d001fd2eb6bad3d471f892

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page