-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgregarious-cli.py
More file actions
70 lines (65 loc) · 2.55 KB
/
gregarious-cli.py
File metadata and controls
70 lines (65 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import warnings
print("Setting up...")
with warnings.catch_warnings():
from gregarious.network import Gregarious
from keras.optimizers import Adam
from gregarious.data import io
from tqdm import tqdm
import argparse
import pickle
import keras
def checkycheck(net):
a = input("Username: ")
b = input("User's Name: ")
c = input("User's Description: ")
d = input("Status: ")
pred = net.predict([a], [b], [c], [d])
r = pred[0]
val = "Bot" if r[0] > r[1] else "Human"
print("Prediction:", val, "| Confidence:", max(r))
parser = argparse.ArgumentParser("(Easy) Gregarious-CLI by @jemoka")
parser.add_argument("command", help="[create] corpus, [train] model, [tag] data, [interactive] discrimination")
parser.add_argument("-i", "--input", help="input file (csv)")
parser.add_argument("-s", "--seed", help="network seed (h5)")
parser.add_argument("-d", "--handler", help="data handler seed (gregariousdata)")
parser.add_argument("-o", "--output", help="output file (corpus name, h5, csv)")
parser.add_argument("-m", help="manual parametre input", action="store_true")
args = parser.parse_args()
if args.command == "create":
dd = io.DataDescription()
df = io.DataFile(args.input, dd, name=args.output)
if args.m:
encoder = df.make_encoder(vocab_size=int(input("BPE Vocab Size: ")))
else:
encoder = df.make_encoder(vocab_size=12000)
df.compile(encoder, target_lang=None)
elif args.command == "train":
with open(args.handler, "rb") as data:
df = pickle.load(data)
net = Gregarious(df, optimizer=Adam(3e-3))
if args.m:
print("Let's train a model...")
print("======================")
e = int(input("Epochs: "))
bs = int(input("Batch Size: "))
vs = int(input("Validation Split: "))
else:
e = 6
bs = 128
vs = 0.2
net.train(epochs=e, batch_size=bs, validation_split=vs, callbacks=[keras.callbacks.EarlyStopping(monitor="val_acc", patience=4, restore_best_weights=True)], save=args.output)
elif args.command == "tag":
with open(args.handler, "rb") as data:
df = pickle.load(data)
net = Gregarious(df, df_seed=df, seed_model=args.seed)
net.predict_csv(args.input, args.output)
elif args.command == "interactive":
with open(args.handler, "rb") as data:
df = pickle.load(data)
net = Gregarious(df, df_seed=df, seed_model=args.seed)
while True:
checkycheck(net)
r = input("Quit (Q) or Continue (enter) => ")
if "q" in r.lower():
break
print("Closing down...")