-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPARARULE_Plus.py
144 lines (130 loc) · 5.03 KB
/
PARARULE_Plus.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from datasets import load_dataset
import json
# Define a function to judge whether it contains the string
def contains_string(id_str, target_str):
return target_str in id_str
# import the dataset PARARULE_plus from huggingface
PARARULE_Plus_dataset = load_dataset("qbao775/PARARULE-Plus")
Data_People_step2 = []
Data_Animal_step2 = []
Data_People_step3 = []
Data_Animal_step3 = []
Data_People_step4 = []
Data_Animal_step4 = []
Data_People_step5 = []
Data_Animal_step5 = []
for i in PARARULE_Plus_dataset['train']:
if i['meta']['QDep'] == '2':
if contains_string(i['id'], "Animal"):
Data_Animal_step2.append(i)
else:
Data_People_step2.append(i)
if i['meta']['QDep'] == '3':
if contains_string(i['id'], "Animal"):
Data_Animal_step3.append(i)
else:
Data_People_step3.append(i)
if i['meta']['QDep'] == '4':
if contains_string(i['id'], "Animal"):
Data_Animal_step4.append(i)
else:
Data_People_step4.append(i)
if i['meta']['QDep'] == '5':
if contains_string(i['id'], "Animal"):
Data_Animal_step5.append(i)
else:
Data_People_step5.append(i)
for i in PARARULE_Plus_dataset['validation']:
if i['meta']['QDep'] == '2':
if contains_string(i['id'], "Animal"):
Data_Animal_step2.append(i)
else:
Data_People_step2.append(i)
if i['meta']['QDep'] == '3':
if contains_string(i['id'], "Animal"):
Data_Animal_step3.append(i)
else:
Data_People_step3.append(i)
if i['meta']['QDep'] == '4':
if contains_string(i['id'], "Animal"):
Data_Animal_step4.append(i)
else:
Data_People_step4.append(i)
if i['meta']['QDep'] == '5':
if contains_string(i['id'], "Animal"):
Data_Animal_step5.append(i)
else:
Data_People_step5.append(i)
for i in PARARULE_Plus_dataset['test']:
if i['meta']['QDep'] == '2':
if contains_string(i['id'], "Animal"):
Data_Animal_step2.append(i)
else:
Data_People_step2.append(i)
if i['meta']['QDep'] == '3':
if contains_string(i['id'], "Animal"):
Data_Animal_step3.append(i)
else:
Data_People_step3.append(i)
if i['meta']['QDep'] == '4':
if contains_string(i['id'], "Animal"):
Data_Animal_step4.append(i)
else:
Data_People_step4.append(i)
if i['meta']['QDep'] == '5':
if contains_string(i['id'], "Animal"):
Data_Animal_step5.append(i)
else:
Data_People_step5.append(i)
filename = 'PARARULE_plus_step2_People.json'
with open(filename, 'w') as file:
json.dump(Data_People_step2, file)
filename = 'PARARULE_plus_step3_People.json'
with open(filename, 'w') as file:
json.dump(Data_People_step3, file)
filename = 'PARARULE_plus_step4_People.json'
with open(filename, 'w') as file:
json.dump(Data_People_step4, file)
filename = 'PARARULE_plus_step5_People.json'
with open(filename, 'w') as file:
json.dump(Data_People_step5, file)
filename = 'PARARULE_plus_step2_Animal.json'
with open(filename, 'w') as file:
json.dump(Data_Animal_step2, file)
filename = 'PARARULE_plus_step3_Animal.json'
with open(filename, 'w') as file:
json.dump(Data_Animal_step3, file)
filename = 'PARARULE_plus_step4_Animal.json'
with open(filename, 'w') as file:
json.dump(Data_Animal_step4, file)
filename = 'PARARULE_plus_step5_Animal.json'
with open(filename, 'w') as file:
json.dump(Data_Animal_step5, file)
# PARARULE_Plus_dataset = [item for item in PARARULE_Plus_dataset if item['train']['meta']['QCat'] == '0']
# for i in range(3):
# print(PARARULE_Plus_dataset[i])
# print(PARARULE_Plus_dataset['train'][200]['label'])
# with the following index PARARULE_Plus_dataset['train'][0/1/2/3...]
# {'id': 'NegationRule-Animal-D2-3082',
# 'context': 'The bald eagle is sleepy. '
# 'The bald eagle is rough. '
# 'The leopard is heavy. '
# 'The leopard is fierce. '
# 'The bald eagle visits the rabbit. '
# 'The leopard sees the dog. '
# 'The rabbit is nice. '
# 'The dog is nice. '
# 'The dog is furry. '
# 'The dog is lovely. '
# 'If something is not nice then it needs the rabbit. '
# 'If something needs the rabbit then it is slow. '
# 'If something is not round then it is heavy. '
# 'If something is not strong then it is cute. '
# 'If something is furry then it is lovely. '
# 'If something is lovely and not big then it is small. '
# 'If something is heavy and not round then it is awful. '
# 'If something is sleepy and rough then it is big. '
# 'If something is big and not lovely then it is fierce. '
# 'All cute animals are beautiful.',
# 'question': 'The bald eagle is not awful.',
# 'label': 0, 'meta': {'QDep': '2', 'QCat': '0_0_not_notTrue'}}