-
由 openaiops 创作于8183bb6e
public_function.py 1.66 KiB
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
import os
import pickle
import argparse
import yaml
def load(file):
with open(file, 'rb') as f:
data = pickle.load(f, encoding='bytes')
return data
def save(file, data):
with open(file, 'wb') as f:
pickle.dump(data, f)
def get_config():
parser = argparse.ArgumentParser()
parser.add_argument('--config')
args = parser.parse_args()
with open(os.path.join('./config', args.config), 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
return config
def min_max_normalized(feature):
feature_copy = feature.copy().astype(float)
for i in range(len(feature_copy)):
min_f, max_f = min(feature_copy[i]), max(feature_copy[i])
if min_f == max_f:
feature_copy[i] = [0]*len(feature_copy[i])
else:
feature_copy[i] = (feature_copy[i] - min_f) / (max_f - min_f)
return feature_copy
def deal_config(config, key):
new_config = {}
for k in config[key].keys():
if 'path' in k or 'dir' in k:
if config[key][k] or config[key][k] == '':
path = os.path.join(config['base_path'], config['demo_path'],
config['label'], config[key][k])
if 'dir' in k:
if not os.path.exists(path):
os.makedirs(path)
new_config[k] = path
else:
new_config[k] = config[key][k]
else:
new_config[k] = config[key][k]
return new_config
if __name__ == '__main__':
config = get_config()
print(config['fasttext']['vector_dim'])
cur_path = os.getcwd()
print(cur_path[:cur_path.find('unirca')])