forked from Ac-cool/AMAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test (2).py
33 lines (30 loc) · 1000 Bytes
/
test (2).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
import json
import numpy as np
from keras.utils.np_utils import to_categorical
LABELS = {'entailment': 0, 'contradiction': 1, 'neutral': 2}
def read_snli(path_t):
path_tt = "./datasets/"+path_t
texts1 = []
texts2 = []
labels = []
with open(path_tt,"r") as file_:
for line in file_:
eg = json.loads(line)
label = eg['gold_label']
if label == '-':
continue
texts1.append(eg['sentence1'])
texts2.append(eg['sentence2'])
#print(eg['sentence1'])
#print(eg['sentence2'])
#print(LABELS[label])
labels.append(LABELS[label])
return texts1, texts2, to_categorical(np.asarray(labels, dtype='int32'))
if __name__ =="__main__":
ll = read_snli("train.jsonl")
texts1, texts2,labels = ll
print(len(texts1),len(texts2),len(labels))
print(labels[0])
print(ll[0][0])
print(ll[1][0])
print(ll[2][0])