-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_bias_vec.py
40 lines (30 loc) · 938 Bytes
/
convert_bias_vec.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
import os
import sys
import argparse
import numpy as np
import h5py
def load_vec(path):
with open(path, 'r') as f:
vals = []
for l in f:
if l.rstrip() == '':
continue
vals.append([float(k) for k in l.rstrip().split()])
return np.asarray(vals)
def write_hdf5(path, map):
print('writing data to {0}'.format(path))
f = h5py.File(path, "w")
for key, val in map.items():
f[key] = val
def main(arguments):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', help="Path to the vec text file, one value per line", default='')
parser.add_argument('--output', help="Prefix of the output file names. ", type=str, default = "data/nli_bias/bias")
opt = parser.parse_args(arguments)
vec = load_vec(opt.input)
m = {'bias': vec}
write_hdf5(opt.output + '.hdf5', m)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))