Skip to content

Commit db9db8c

Browse files
committed
feat(slack-noti): add when terminated learning, send message to Slack
1 parent 7db918a commit db9db8c

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This code implements [Convolutional Neural Networks for Sentence Classification]
1313
- TensorFlow 1.4
1414
- [hb-config](https://github.com/hb-research/hb-config) (Singleton Config)
1515
- tqdm
16+
- requests
17+
- [Slack Incoming Webhook URL](https://my.slack.com/services/new/incoming-webhook/)
1618

1719
## Project Structure
1820

@@ -80,6 +82,9 @@ train:
8082
loss_hook_n_iter: 1000
8183
check_hook_n_iter: 1000
8284
min_eval_frequency: 1000
85+
86+
slack:
87+
webhook_url: "" # after training notify you using slack-webhook
8388
```
8489
8590

config/check_tiny.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ model:
2020
train:
2121
learning_rate: 0.001
2222

23-
train_steps: 10000
23+
train_steps: 100
2424
model_dir: 'logs/rt-check_tiny'
2525

2626
save_checkpoints_steps: 100
@@ -30,3 +30,6 @@ train:
3030

3131
print_verbose: True
3232
debug: False
33+
34+
slack:
35+
webhook_url: ""

config/kaggle_movie_review.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ train:
3333

3434
print_verbose: True
3535
debug: False
36+
37+
slack:
38+
webhook_url: ""

config/rt-polarity.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ train:
3333

3434
print_verbose: True
3535
debug: False
36+
37+
slack:
38+
webhook_url: ""

main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#-- coding: utf-8 -*-
22

33
import argparse
4+
import atexit
45
import logging
56

67
from hbconfig import Config
@@ -9,6 +10,7 @@
910
import data_loader
1011
import hook
1112
from model import Model
13+
import utils
1214

1315

1416
def experiment_fn(run_config, params):
@@ -92,7 +94,15 @@ def main(mode):
9294

9395
tf.logging._logger.setLevel(logging.INFO)
9496

97+
# Print Config setting
9598
Config(args.config)
9699
print("Config: ", Config)
100+
if Config.get("description", None):
101+
print("Config Description")
102+
for key, value in Config.description.items():
103+
print(f" - {key}: {value}")
104+
105+
# After terminated Notification to Slack
106+
atexit.register(utils.send_message_to_slack, config_name=args.config)
97107

98108
main(args.mode)

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
hb-config
2-
tqdm
2+
tqdm
3+
requests

utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import json
3+
import os.path
4+
5+
from hbconfig import Config
6+
import requests
7+
8+
9+
10+
def send_message_to_slack(config_name):
11+
project_name = os.path.basename(os.path.abspath("."))
12+
13+
data = {
14+
"text": f"The learning is finished with *{project_name}* Project using `{config_name}` config."
15+
}
16+
17+
webhook_url = Config.slack.webhook_url
18+
if webhook_url == "":
19+
print(data["text"])
20+
else:
21+
requests.post(Config.slack.webhook_url, data=json.dumps(data))

0 commit comments

Comments
 (0)