-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgen_data_for_ace2004.py
executable file
·77 lines (64 loc) · 2.42 KB
/
gen_data_for_ace2004.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
#!/usr/bin/env python
from typing import Tuple, List
from collections import defaultdict
import pickle
from config import config
from reader.reader import Reader
from util.utils import save_dynamic_config
def batch_stat(batches: Tuple[List[List[List[int]]],
List[List[List[int]]],
List[List[List[List[int]]]],
List[List[List[Tuple[int, int, int]]]],
List[List[List[bool]]]]) -> None:
all_num = 0
start_num = 0
end_num = 0
for token_iv_batch, token_ooev_batch, char_batch, label_batch, mask_batch in zip(*batches):
for labels in label_batch:
start_dic = defaultdict(list)
end_dic = defaultdict(list)
for ent in labels:
start_dic[(ent[0], ent[2])].append(ent)
end_dic[(ent[1], ent[2])].append(ent)
all_num += 1
for k, v in start_dic.items():
if len(v) > 1:
start_num += len(v)
for k, v in end_dic.items():
if len(v) > 1:
end_num += len(v)
print("All {}, start {}, end {}".format(all_num, start_num, end_num))
if __name__ == "__main__":
reader = Reader()
reader.read_and_gen_vectors_glove(config.embed_path)
reader.read_all_data("./data/ace2004/", "ace2004.train", "ace2004.dev", "ace2004.test")
# print reader.train_sents[0]
train_batches, dev_batches, test_batches = reader.to_batch(config.batch_size)
f = open(config.train_data_path, 'wb')
pickle.dump(train_batches, f)
f.close()
f = open(config.dev_data_path, 'wb')
pickle.dump(dev_batches, f)
f.close()
f = open(config.test_data_path, 'wb')
pickle.dump(test_batches, f)
f.close()
batch_stat(train_batches)
batch_stat(dev_batches)
batch_stat(test_batches)
# random_text
# random_batch = 1
# random_n = 4
# reader.debug_single_sample(
# train_batches[0][random_batch][random_n],
# train_batches[1][random_batch][random_n],
# train_batches[2][random_batch][random_n],
# train_batches[3][random_batch][random_n],
# train_batches[4][random_batch][random_n]
# )
# misc config
misc_dict = save_dynamic_config(reader)
f = open(config.config_data_path, 'wb')
pickle.dump(misc_dict, f)
f.close()
print("Remember to scp word vectors as well")