-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
248 lines (206 loc) · 6.47 KB
/
config.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# coding=utf-8
# !/usr/bin/python3.6 # Please use python 3.6
"""
__synopsis__ : Contains system configuration details and other global variables.
__description__ : Benefit: We can print the configuration on every run and get the hyper-parameter configuration for each run.
__project__ : MNXC
__author__ : Samujjwal Ghosh <[email protected]>
__version__ : ": 0.1 "
__date__ : "04-03-2019"
__copyright__ : "Copyright (c) 2019, All rights reserved."
__license__ : "This source code is licensed under the MIT-style license found in the LICENSE file in the root
directory of this source tree."
__classes__ : config
__variables__ : configuration, seed, platform
__methods__ :
__last_modified__:
"""
import json
from logger.logger import logger
global seed
seed = 0
global configuration
configuration = {
"data" :{
"dataset_name":"Wiki10-31K_onehot",
"val_split" :0.1,
"test_split" :0.3,
"show_stat" :False
},
"xc_datasets" :{
"Wiki10-31K" :"html",
"Wiki10-31K_onehot" :"html",
"Wiki10-31K_fixed5" :"html",
"Wiki10-31K_pointer":"html",
"AmazonCat-14K" :"json",
"Amazon-3M" :"json",
"Delicious-T140" :"html",
"AmazonCat-13K" :"txt",
"Amazon-670K" :"txt",
"EurLex" :"uniq"
},
"model" :{
"num_folds" :5,
"max_sequence_length" :100,
"max_vec_len" :5000,
"dropout" :0.1,
"dropout_external" :0.0,
"clipnorm" :1.0,
"data_slice" :5120,
"g_encoder" :"cnn",
"use_cuda" :False,
"normalize_inputs" :False,
"tfidf_avg" :False,
"kernel_size" :1,
"stride" :1,
"padding" :1,
"context" :10,
"classify_count" :0,
"fce" :True,
"optimizer" :{
"optimizer_type":"adam",
"learning_rate" :3e-4,
"lr_decay" :0,
"weight_decay" :0,
"momentum" :0.9,
"dampening" :0.9,
"alpha" :0.99,
"rho" :0.9,
"centered" :False
},
"view_grads" :False,
"view_train_precision":True
},
"lstm_params" :{
"num_layers" :1,
"bias" :True,
"batch_first" :True,
"bidirectional":True,
"hid_size" :3,
},
"cnn_params" :{
"padding" :1,
"stride" :1,
"kernel_size":1,
"bias" :True,
},
"sampling" :{
"num_epochs" :20,
"num_train_epoch" :5,
"batch_size" :2,
"categories_per_batch" :2,
"supports_per_category":2,
"targets_per_category" :2
},
"prep_vecs" :{
"max_nb_words" :20000,
"min_word_count" :1,
"window" :7,
"min_count" :1,
"negative" :10,
"num_chunks" :10,
"vectorizer" :"doc2vec",
"sample_repeat_mode":"append",
"input_size" :7,
"tfidf_avg" :False,
"idf" :True
},
"text_process":{
"encoding" :'latin-1',
"sents_chunk_mode":"word_avg",
"workers" :5
},
"paths" :{
"result_file" :"result.txt",
"log_dir" :"/logs",
"pretrain_dir":{
"Windows":"D:\\Datasets\\Extreme Classification",
"OSX" :"/home/cs16resch01001/datasets/Extreme Classification",
"Linux" :{
"sam" :"/media/sam/Data/Datasets/pretrain", ## Code path: /home/cs14resch11001/codes/MNXC
"cs14resch11001":"/raid/ravi/pretrain"
}
},
"dataset_dir" :{
"Windows":"D:\\Datasets\\Extreme Classification",
"OSX" :"/home/cs16resch01001/datasets/Extreme Classification",
"Linux" :{
"sam" :"/media/sam/Data/Datasets/Extreme Classification",
"cs14resch11001":"/raid/ravi/Datasets/Extreme Classification"
}
}
},
"html_parser" :{
"alt_text" :True,
"ignore_table" :True,
"decode_errors" :"ignore",
"default_alt" :"<IMG>",
"ignore_link" :True,
"reference_links" :True,
"bypass_tables" :True,
"ignore_emphasis" :True,
"unicode_snob" :True,
"no_automatic_links" :True,
"no_skip_internal_links":True,
"single_line_break" :True,
"escape_all" :True
}
}
class Config(object):
""" Contains all configuration details of the project. """
def __init__(self):
super(Config,self).__init__()
self.configuration = configuration
def get_config(self):
"""
:return:
"""
return self.configuration
def print_config(self,indent=4,sort=True):
""" Prints the config. """
logger.info("[{}] : {}".format("Configuration",json.dumps(self.configuration,indent=indent,sort_keys=sort)))
@staticmethod
def get_platform():
""" Returns dataset path based on OS.
:return: str
"""
import platform
if platform.system() == 'Windows':
return platform.system()
elif platform.system() == 'Linux':
return platform.system()
else: ## OS X returns name 'Darwin'
return "OSX"
@staticmethod
def get_username():
"""
:returns the current username.
:return: string
"""
try:
import os,pwd
username = pwd.getpwuid(os.getuid()).pw_name
except Exception as e:
import getpass
username = getpass.getuser()
# finally:
# username = os.environ.get('USER')
return username
config_cls = Config()
config_cls.print_config()
global platform
platform = config_cls.get_platform()
global username
username = config_cls.get_username()
def main():
"""
Main module to start code
:param args:
Type: tuple
Required
Read Only
:return:
"""
pass
if __name__ == "__main__":
main()