forked from yangze01/DPAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_train_dev_dataset.py
More file actions
32 lines (29 loc) · 962 Bytes
/
Copy pathmake_train_dev_dataset.py
File metadata and controls
32 lines (29 loc) · 962 Bytes
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
#coding=gb18030
import json
import jieba
import sys,os
import numpy as np
from data_helper import *
def get_one_hot_y_label(laws_dict, y_src):
y_src = y_src.split(" ")
y_ret = np.array([0]*70)
one_hot = [laws_dict[one] for one in y_src if one in laws_dict]
y_ret[one_hot] = 1
return y_ret
if __name__ == "__main__":
laws_dict_path = sys.argv[1]
laws_dict = load_laws_dict(laws_dict_path)
train_dev_y_array = list()
for line in sys.stdin:
try:
line = line.rstrip()
if not line:
continue
content, raw_labels = line.split('\t')
cut_content = ' '.join(rm_tokens(list(jieba.cut(content))))
y_labels = get_one_hot_y_label(laws_dict, raw_labels)
print(cut_content.encode('utf8'))
train_dev_y_array.append(y_labels)
except:
continue
np.savetxt("./data/train_dev_y.txt", np.array(train_dev_y_array))