-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanswer.py
More file actions
66 lines (50 loc) · 1.32 KB
/
Copy pathanswer.py
File metadata and controls
66 lines (50 loc) · 1.32 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
#!/usr/bin/env python3
# Author: Armit
# Create Time: 2023/05/03
from pathlib import Path
from subprocess import Popen
import numpy as np
import pandas as pd
BASE_PATH = Path(__file__).parent
import sys ; sys.path.append(str(BASE_PATH))
from run_quantum import get_args, go_train, go_infer
def get_args_best_config():
''' yes you just tune everything manually and fix the best... '''
args = get_args()
# preprocess
args.analyzer = 'kgram'
args.min_freq = 10
# model
args.model = 'YouroQ'
args.onehot = True
args.n_len = 8
args.n_repeat = 4
# train
args.batch_size = 4
args.epochs = 4
args.lr = 0.01
# infer
args.n_vote = 5
return args
def train():
''' call for preprocess & train '''
# preprocess
PREPROCESS_SCRIPT = BASE_PATH / 'mk_vocab.py'
assert PREPROCESS_SCRIPT.exists()
cmd = f'python {PREPROCESS_SCRIPT}'
p = Popen(cmd, shell=True, encoding='utf-8', stdout=sys.stdout)
p.wait()
# train
args = get_args_best_config()
go_train(args)
def question1(fp: str) -> np.ndarray:
''' call for inference '''
# query data
df = pd.read_csv(fp)
T = df[df.columns[-1]].to_numpy().tolist()
# inference
args = get_args_best_config()
pred = go_infer(args, T)
return np.asarray(pred, dtype=np.int32)
if __name__ == '__main__':
train()