-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique_labels.py
57 lines (35 loc) · 1.01 KB
/
unique_labels.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
## Script computes the unique lables inthe dataset
## Do not run this, check in the labels.json file
import cPickle as cp
import json
def load_data(path_to_data = ""):
print "Loading data"
sentence_dict = cp.load(open(path_to_data+"labeld_data.pkl"))
print "Done..."
return sentence_dict
def get_labels(label_set,data_dict_l2):
sentence_labels = data_dict_l2['sentence_labels']
for label in sentence_labels :
label_set.add(label)
def unique_labels(sentence_dict):
label_set = set()
count = 0
for k,v in sentence_dict.iteritems() :
data_dict_l1 = v
for k1,v1 in data_dict_l1.iteritems():
data_dict_l2 = v1
get_labels(label_set,data_dict_l2)
count += 1
print count
## Creating a label dictioanry
label_dict = {}
uid = 1
for labels in label_set :
label_dict[str(labels)] = uid
uid+=1
return label_dict
if __name__ =="__main__" :
sentence_dict = load_data("data/")
label_dict = unique_labels(sentence_dict)
print len(label_dict)
json.dump(label_dict,open("labels.json","w+"))