-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_agnews.py
More file actions
106 lines (74 loc) · 3.84 KB
/
run_agnews.py
File metadata and controls
106 lines (74 loc) · 3.84 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# import os
# pyfile='main.py'
# gpu = 2
# dp = 0.2
# run_command = 'python3 '+pyfile+ ' --task agnews --num_class 4 --gpu '+str(gpu) + ' --batch_size 32 --dropout '+str(dp)+ ' --model_file_name full_ori.pth.tar --num_units 4'#+ ' --early_stop 2'
# print (run_command)
# os.system(run_command)
import os
gpu = 1
task = 'agnews'
dropout = [0.2]
write_to_file = 0
resume=0
# max_example = 10000
save_selection = 1
full_classifier = 0
pyfile = 'rt_main.py'
# pyfile = 'bcn_rt_main.py'
server = 'nlp'
# pyfile = 'imdb_test.py'
sparsity_list = [0.00075, 0.0005, 0.00025, 0.0001]#[0.1, 0.25, 0.5, 0.75, 0.025, 0.05, 0.075, 0.00025, 0.00075, 0.0005] # [0.5 , 0.05, 0.02, 0.015, 0.01, 0.001, 0.00075, 0.0005, 0.00025, 0.0001]
coherent_list = [ 2.0, 5.0]
debug=0
SAG = 0
WAG = 0
load_model = 2# -1 for no load, 0 for load selector only, 1 for load classifier only
classifier_file_name = 'full_ori.pth.tar'
nhid= 300
ffnn_dim = 300
for dp in dropout:
for sparsity in sparsity_list:
for coherent in coherent_list:
# model_file_name = 'modle_sparsity_'+str(sparsity)+'_coherent_'+str(coherent)+'.pth.tar'
model_file_name = 'model_sparsity_'+str(sparsity)+'_coherent_'+str(coherent)+'.pth.tar'
options = ''
if WAG==1:
if full_classifier ==1:
pyfile = 'imdb_main_WAG_full_classifier.py'
# model_file_name = 'full_WAG_classifier_crf'+'_dp_'+str(dp)+'.pth.tar'
model_file_name = 'full_WAG_classifier_'+server+'.pth.tar'
else:
# classifier_file_name = 'full_WAG_classifier_crf'+'_dp_'+str(dp)+'.pth.tar'
classifier_file_name = 'full_WAG_classifier_'+server+'.pth.tar'
options+=' --classifier_file_name '+classifier_file_name
model_file_name += 'WAG_'
options+= ' --WAG '
elif SAG==1:
if full_classifier == 1:
pyfile = 'imdb_main_SAG_full_classifier.py'
model_file_name = 'full_SAG_classifier_crf'+'.pth.tar'
else:
classifier_file_name = 'full_SAG_classifier_crf'+'.pth.tar'
options+=' --classifier_file_name '+classifier_file_name
options+= ' --SAG '
options+=' --model_file_name '+model_file_name +' --load_model ' + str(load_model)+' --num_units 4 --num_class 4'+\
' --sparsity ' +str(sparsity)+ ' --coherent '+str(coherent) + ' --task '+task# +' --dropout '+str(dp)+' --print_every 500 --plot_every 500'+\
# ' --nhid '+ str(nhid) + ' --ffnn_dim '+str(ffnn_dim) #+' --classifier_file_name '+classifier_file_name+ ' --selector_file_name '+selector_file_name#--batch_size 32 --max_norm 4.9' #+' --lr '+str(lr)#+' --selector_file_name '+selector_file_name+' --classifier_file_name '+classifier_file_name+
if save_selection==1:
if task=='IMDB':model_file_name = 'modle_sparsity_'+str(sparsity)+'_coherent_'+str(coherent)+'.pth.tar'
classifier_file_name = model_file_name
selector_file_name = model_file_name
options+= ' --save_selection '+ str(save_selection) +' --batch_size 32' + ' --selector_file_name '+selector_file_name
if load_model>0 and pyfile=='imdb_test.py': classifier_file_name = model_file_name
if load_model>-1 and pyfile=='imdb_test.py': selector_file_name = model_file_name
if load_model>0 : options += ' --classifier_file_name '+classifier_file_name
if load_model>-1 and pyfile=='imdb_test.py': options += ' --selector_file_name '+selector_file_name
if debug==1:options+= ' --debug '
run_command = ' python3 '+pyfile+' --gpu '+str(gpu)+options
if resume==1: run_command+=' --resume '+model_file_name
if 'test' not in pyfile and write_to_file ==1:run_command += ' >> ../bcn_output/' + task+'/'+model_file_name+'_output.txt'
print (run_command)
os.system(run_command)
# exit()
#python3 main.py --gpu 2 --no_train --task IMDB --batch_size 32 --dropout 0.3 --num_class 2 --lr 0.001 --num_units 5 --max_norm 3.0 --save_model model_task_IMDB_batch_size_32_dropout_0.3_num_class_2_lr_0.001_num_units_5_best.pth.tar