MCPcopy Create free account
hub / github.com/debjitpaul/refiner / Negative_Examples

Class Negative_Examples

data_preprocessing/create_negative_examples_mwp.py:9–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9class Negative_Examples:
10 def __init__(self,
11 data_file):
12 self.data_file = data_file
13
14 def create(self, data_file):
15 """
16 Create Negative Examples
17 """
18 data = []
19 for i, pair in tqdm(enumerate(json.load(open(data_file, 'r')))):
20 text_a = pair['Body'] + pair['Question']
21 label = str(pair['Linear_Formula'])
22 label = label.replace("'","")
23 perturbed_numbers, perturbed_operations, perturbed_label_removed, perturbed_label_add = self.perturb(label)
24
25 print("************")
26 print(label)
27 print(perturbed_numbers)
28 print(perturbed_operations)
29 print(perturbed_label_removed)
30 print(perturbed_label_add)
31
32 feedback_numbers = self._critique_function(perturbed_numbers, label)
33 feedback_operations = self._critique_function(perturbed_operations, label)
34 feedback_add = self._critique_function(perturbed_label_removed, label)
35 feedback_remove = self._critique_function(perturbed_label_add, label)
36
37 #print(feedback_add, feedback_remove)
38
39 print(feedback_numbers, feedback_operations, feedback_remove, feedback_add)
40
41 instance_1 = self.get_new_instances(pair, perturbed_numbers, feedback_numbers[0])
42 #if " <hint> No" not in feedback_numbers[0]:
43 data.append(instance_1)
44 print(instance_1)
45 instance_2 = self.get_new_instances(pair, perturbed_operations, feedback_operations[0])
46 #if " <hint> No" not in feedback_operations[0]:
47 data.append(instance_2)
48 instance_3 = self.get_new_instances(pair, perturbed_label_removed, feedback_add[0])
49 #if " <hint> No" not in feedback_add[0]:
50 data.append(instance_3)
51 instance_4 = self.get_new_instances(pair, perturbed_label_add, feedback_remove[0])
52 #if " <hint> No" not in feedback_remove[0]:
53 data.append(instance_4)
54
55 with open('refiner/data/finetune_feedback_data.json', 'w') as json_file:
56 json.dump(data, json_file, indent=0, sort_keys=True)
57 print('Successfully appended to the JSON file')
58
59
60
61 def get_new_instances(self, pair, perturbed_label, feedbacks):
62 instance = {}
63 instance['Body'] = pair['Body'] + ' ' + pair['Question']
64 instance['Question'] = " Previous Answer: " + str(perturbed_label) +' ' + str(feedbacks)
65 instance['Linear_Formula'] = pair['Linear_Formula']
66 return instance

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected