aggr8 commited on
Commit
e70dfd2
·
verified ·
1 Parent(s): ac2c289

Add files using upload-large-folder tool

Browse files
Files changed (50) hide show
  1. README.md +101 -38
  2. change_colour/__pycache__/utils.cpython-314.pyc +0 -0
  3. circle_location/__pycache__/utils.cpython-314.pyc +0 -0
  4. circle_right_triangle/__pycache__/utils.cpython-314.pyc +0 -0
  5. circle_right_triangle/eval.py +139 -0
  6. circle_right_triangle/utils.py +84 -0
  7. colours_present/utils.py +30 -0
  8. comparing_size/__pycache__/utils.cpython-314.pyc +0 -0
  9. comparing_size/eval.py +73 -0
  10. count_coloured_circles/__pycache__/utils.cpython-314.pyc +0 -0
  11. count_coloured_circles/eval.py +74 -0
  12. counting_circles/__pycache__/utils.cpython-314.pyc +0 -0
  13. counting_circles/eval.py +71 -0
  14. counting_circles/utils.py +27 -0
  15. counting_locations/__pycache__/utils.cpython-314.pyc +0 -0
  16. counting_shapes/__pycache__/utils.cpython-314.pyc +0 -0
  17. cross_and_knots/eval.py +79 -0
  18. cross_and_knots/utils.py +99 -0
  19. graph_counting/__pycache__/utils.cpython-314.pyc +0 -0
  20. grid_path/__pycache__/utils.cpython-314.pyc +0 -0
  21. identifying_shapes/__pycache__/utils.cpython-314.pyc +0 -0
  22. identifying_shapes/eval.py +73 -0
  23. identifying_shapes/utils.py +53 -0
  24. layered_colours/__pycache__/utils.cpython-314.pyc +0 -0
  25. layered_colours/eval.py +75 -0
  26. layered_colours/utils.py +51 -0
  27. layered_shapes/__pycache__/utils.cpython-314.pyc +0 -0
  28. layered_shapes/utils.py +53 -0
  29. list_colours/__pycache__/utils.cpython-314.pyc +0 -0
  30. list_shapes/eval.py +77 -0
  31. list_shapes/utils.py +34 -0
  32. locate_circles_colour/__pycache__/utils.cpython-314.pyc +0 -0
  33. locate_circles_colour/eval.py +72 -0
  34. locate_circles_colour/utils.py +55 -0
  35. locate_circles_shape/__pycache__/utils.cpython-314.pyc +0 -0
  36. locate_circles_shape/eval.py +72 -0
  37. locate_circles_shape/utils.py +55 -0
  38. match_outline/__pycache__/utils.cpython-314.pyc +0 -0
  39. match_outline/eval.py +74 -0
  40. match_outline/utils.py +28 -0
  41. match_shadow/__pycache__/utils.cpython-314.pyc +0 -0
  42. maze_solving/__pycache__/utils.cpython-314.pyc +0 -0
  43. maze_solving/eval.py +70 -0
  44. mirror_image/__pycache__/utils.cpython-314.pyc +0 -0
  45. mirror_image/eval.py +71 -0
  46. sort_circles/__pycache__/utils.cpython-314.pyc +0 -0
  47. sort_lines/__pycache__/utils.cpython-314.pyc +0 -0
  48. sort_lines/eval.py +67 -0
  49. sort_lines/utils.py +18 -0
  50. vanishing_objects/utils.py +88 -0
README.md CHANGED
@@ -20,7 +20,7 @@ size_categories:
20
 
21
  Percept-V is a benchmark of **30 synthetic visual perception tasks**, 200 samples each (**6,000 samples total**), designed to isolate *perception* from *reasoning* in vision-language models. Every task is procedurally generated from simple primitives — circles, lines, grids, shapes, colours — so a model that genuinely sees the image should solve it near-perfectly, and failures point at perceptual rather than reasoning limits.
22
 
23
- Tasks span counting, colour identification, shape identification, spatial localisation, layering/occlusion, grid navigation, and two-image comparison.
24
 
25
  ## Repository layout
26
 
@@ -31,10 +31,12 @@ Each task is a self-contained directory:
31
  ├── data/ # 200 images (or 400 for two-image tasks)
32
  │ ├── 1.png ... 200.png
33
  ├── data.json # 200 ground-truth records, one per sample
34
- └── prompts/
35
- ├── input_prompt.txt # describes what the image contains
36
- ├── rules.txt # the task the model must perform
37
- └── output_prompt.txt # required output format
 
 
38
  ```
39
 
40
  ### Prompt construction
@@ -64,38 +66,40 @@ In both cases the partner image is recovered from the `id` by swapping the prefi
64
 
65
  ## Tasks
66
 
67
- | Task | Images/sample | `id` format | `data.json` fields |
68
- |---|---|---|---|
69
- | `change_colour` | 2 | `second1.png` | `num_differences` |
70
- | `circle_boxes` | 1 | `1.png` | `answer`, `num_objects` |
71
- | `circle_location` | 1 | `1.png` | `count`, `num_objects`, `quadrant` |
72
- | `circle_right_triangle` | 1 | `1.png` | `circles`, `cols`, `right`, `rows`, `triangles` |
73
- | `colours_present` | 2 | `1.png` | `colours_present`, `num_objects` |
74
- | `comparing_size` | 1 | `1.png` | `Gold_output`, `Rows` |
75
- | `count_coloured_circles` | 1 | `1.png` | `num_objects`, `red_circle` |
76
- | `counting_circles` | 1 | `1.png` | `num_objects` |
77
- | `counting_locations` | 1 | `1.png` | `num_objects_over_table`, `num_objects_under_table` |
78
- | `counting_shapes` | 1 | `1.png` | `circles`, `squares`, `triangles` |
79
- | `cross_and_knots` | 1 | `1.png` | `cross_positions`, `crosses`, `gold_output`, `n` |
80
- | `graph_counting` | 1 | `1.png` | `num_edges`, `num_nodes` |
81
- | `grid_path` | 1 | `1.png` | `gold_output`, `path_size`, `rows` |
82
- | `identifying_shapes` | 1 | `1.png` | `Gold_output`, `Gold_side`, `Rows` |
83
- | `inside_circles` | 1 | `1.png` | `inside_circles`, `num_circles` |
84
- | `layered_colours` | 1 | `1.png` | `colors`, `num_layers` |
85
- | `layered_shapes` | 1 | `1.png` | `num_layers`, `order` |
86
- | `list_colours` | 1 | `1.png` | `list_colours`, `num_objects` |
87
- | `list_shapes` | 1 | `1.png` | `list_shapes`, `num_objects` |
88
- | `locate_circles_colour` | 1 | `1.png` | `gold_output`, `n_circles`, `rows` |
89
- | `locate_circles_shape` | 1 | `1.png` | `gold_output`, `n_circles`, `rows` |
90
- | `match_outline` | 2 | `second1.png` | `Gold_output`, `Rows` |
91
- | `match_shadow` | 2 | `second1.png` | `Gold_output`, `Rows` |
92
- | `maze_solving` | 1 | `1.png` | `Columns`, `Rows`, `path` |
93
- | `mirror_image` | 2 | `second1.png` | `mirror_image`, `num_objects` |
94
- | `numbered_shapes` | 1 | `1.png` | `circles`, `num_objects`, `pentagons`, `rectangles`, `triangles` |
95
- | `sort_circles` | 1 | `1.png` | `Gold_output`, `Rows` |
96
- | `sort_lines` | 1 | `1.png` | `Gold_output`, `Lines` |
97
- | `vanishing_objects` | 2 | `second1.png` | `circles`, `squares`, `triangles`, `vanished` |
98
- | `water_image` | 2 | `second1.png` | `num_objects`, `water_image` |
 
 
99
 
100
  ## Usage
101
 
@@ -135,7 +139,66 @@ To fetch a single task instead of all 226 MB, pass `allow_patterns="counting_cir
135
 
136
  ## Evaluation
137
 
138
- Parse the **last line** of the model's response and compare it against the answer field for that task. Because answer-field names and formats differ per task, exact-match scoring needs a small per-task normaliser.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  ## Licence
141
 
 
20
 
21
  Percept-V is a benchmark of **30 synthetic visual perception tasks**, 200 samples each (**6,000 samples total**), designed to isolate *perception* from *reasoning* in vision-language models. Every task is procedurally generated from simple primitives — circles, lines, grids, shapes, colours — so a model that genuinely sees the image should solve it near-perfectly, and failures point at perceptual rather than reasoning limits.
22
 
23
+ Tasks span counting, colour identification, shape identification, spatial localisation, layering/occlusion, grid navigation, and two-image comparison. Each task ships with its images, ground truth, prompts, and the exact parsing and scoring scripts used to evaluate it.
24
 
25
  ## Repository layout
26
 
 
31
  ├── data/ # 200 images (or 400 for two-image tasks)
32
  │ ├── 1.png ... 200.png
33
  ├── data.json # 200 ground-truth records, one per sample
34
+ ├── prompts/
35
+ │ ├── input_prompt.txt # describes what the image contains
36
+ │ ├── rules.txt # the task the model must perform
37
+ │ └── output_prompt.txt # required output format
38
+ ├── utils.py # parses raw model text into a structured answer
39
+ └── eval.py # scores parsed answers against the ground truth
40
  ```
41
 
42
  ### Prompt construction
 
66
 
67
  ## Tasks
68
 
69
+ The last column is the field `eval.py` buckets by when reporting category-wise accuracy — in practice a difficulty axis for that task.
70
+
71
+ | Task | Images/sample | `id` format | `data.json` fields | Difficulty axis |
72
+ |---|---|---|---|---|
73
+ | `change_colour` | 2 | `second1.png` | `num_differences` | `num_differences` |
74
+ | `circle_boxes` | 1 | `1.png` | `answer`, `num_objects` | `num_objects` |
75
+ | `circle_location` | 1 | `1.png` | `count`, `num_objects`, `quadrant` | `num_objects` |
76
+ | `circle_right_triangle` | 1 | `1.png` | `circles`, `cols`, `right`, `rows`, `triangles` | `rows` |
77
+ | `colours_present` | 2 | `1.png` | `colours_present`, `num_objects` | `num_objects` |
78
+ | `comparing_size` | 1 | `1.png` | `Gold_output`, `Rows` | `Rows` |
79
+ | `count_coloured_circles` | 1 | `1.png` | `num_objects`, `red_circle` | `num_objects` |
80
+ | `counting_circles` | 1 | `1.png` | `num_objects` | `num_objects` |
81
+ | `counting_locations` | 1 | `1.png` | `num_objects_over_table`, `num_objects_under_table` | `num_objects_over_table` |
82
+ | `counting_shapes` | 1 | `1.png` | `circles`, `squares`, `triangles` | `circles` |
83
+ | `cross_and_knots` | 1 | `1.png` | `cross_positions`, `crosses`, `gold_output`, `n` | `n` |
84
+ | `graph_counting` | 1 | `1.png` | `num_edges`, `num_nodes` | `num_nodes` |
85
+ | `grid_path` | 1 | `1.png` | `gold_output`, `path_size`, `rows` | `rows` |
86
+ | `identifying_shapes` | 1 | `1.png` | `Gold_output`, `Gold_side`, `Rows` | `Rows` |
87
+ | `inside_circles` | 1 | `1.png` | `inside_circles`, `num_circles` | `num_circles` |
88
+ | `layered_colours` | 1 | `1.png` | `colors`, `num_layers` | `num_layers` |
89
+ | `layered_shapes` | 1 | `1.png` | `num_layers`, `order` | `num_layers` |
90
+ | `list_colours` | 1 | `1.png` | `list_colours`, `num_objects` | `num_objects` |
91
+ | `list_shapes` | 1 | `1.png` | `list_shapes`, `num_objects` | `num_objects` |
92
+ | `locate_circles_colour` | 1 | `1.png` | `gold_output`, `n_circles`, `rows` | `n_circles` |
93
+ | `locate_circles_shape` | 1 | `1.png` | `gold_output`, `n_circles`, `rows` | `n_circles` |
94
+ | `match_outline` | 2 | `second1.png` | `Gold_output`, `Rows` | `Rows` |
95
+ | `match_shadow` | 2 | `second1.png` | `Gold_output`, `Rows` | `Rows` |
96
+ | `maze_solving` | 1 | `1.png` | `Columns`, `Rows`, `path` | `len(path) - 2` |
97
+ | `mirror_image` | 2 | `second1.png` | `mirror_image`, `num_objects` | `num_objects` |
98
+ | `numbered_shapes` | 1 | `1.png` | `circles`, `num_objects`, `pentagons`, `rectangles`, `triangles` | `num_objects` |
99
+ | `sort_circles` | 1 | `1.png` | `Gold_output`, `Rows` | `Rows` |
100
+ | `sort_lines` | 1 | `1.png` | `Gold_output`, `Lines` | `Lines` |
101
+ | `vanishing_objects` | 2 | `second1.png` | `circles`, `squares`, `triangles`, `vanished` | `circles` |
102
+ | `water_image` | 2 | `second1.png` | `num_objects`, `water_image` | `num_objects` |
103
 
104
  ## Usage
105
 
 
139
 
140
  ## Evaluation
141
 
142
+ Each task ships the two scripts used to produce the numbers in the paper: `utils.py` (answer parsing) and `eval.py` (scoring). They are per-task — parsing and correctness rules differ across tasks — so always use the pair from the task directory you are scoring. Both are plain Python with no dependencies beyond the standard library.
143
+
144
+ Evaluation runs in three steps.
145
+
146
+ **1. Inference.** For each sample, build the prompt and record the model's raw text in a field named `gpt_response`, alongside all the original `data.json` fields. Write the list to `answer_<model>.json`:
147
+
148
+ ```json
149
+ [
150
+ {"id": "1.png", "num_objects": 1, "gpt_response": "COUNT:1"},
151
+ ...
152
+ ]
153
+ ```
154
+
155
+ **2. Parse.** `utils.output_from_text(text)` extracts the structured answer from the raw response, returning `{"OUTPUT": ..., "ERROR": ...}`. `OUTPUT` is `None` and `ERROR` is set when the response does not follow the format required by `output_prompt.txt`. Copy these into `Output` and `ERROR` on each record:
156
+
157
+ ```python
158
+ import json, importlib.util
159
+
160
+ task = "counting_circles"
161
+ spec = importlib.util.spec_from_file_location("u", f"{task}/utils.py")
162
+ utils = importlib.util.module_from_spec(spec); spec.loader.exec_module(utils)
163
+
164
+ records = json.load(open(f"{task}/answer_mymodel.json"))
165
+ for r in records:
166
+ parsed = utils.output_from_text(r["gpt_response"])
167
+ r["Output"], r["ERROR"] = parsed["OUTPUT"], parsed["ERROR"]
168
+ json.dump(records, open(f"{task}/answer_mymodel.json", "w"), indent=4)
169
+ ```
170
+
171
+ **3. Score.**
172
+
173
+ ```bash
174
+ python counting_circles/eval.py \
175
+ -a counting_circles/answer_mymodel.json \
176
+ -o counting_circles/eval_mymodel.json
177
+ ```
178
+
179
+ `eval.py` compares `Output` against the ground-truth fields already present in each record and writes:
180
+
181
+ ```json
182
+ {
183
+ "Overall Accuracy": 42.5,
184
+ "Category-wise Accuracy": {
185
+ "1": 100.0, "2": 100.0, "3": 90.0, "4": 100.0, "5": 70.0,
186
+ "...": "...",
187
+ "16": 10.0, "17": 10.0, "18": 0.0, "19": 0.0, "20": 20.0
188
+ }
189
+ }
190
+ ```
191
+
192
+ The shape of that result is typical: near-ceiling on the smallest instances, collapsing as the count grows — which is the separation between perception and reasoning the benchmark is built to expose.
193
+
194
+ Unparseable responses (`Output` absent or `None`) count as incorrect rather than being dropped, so `Overall Accuracy` is over all 200 samples and format failures are penalised. The category keys are the difficulty axis listed in the table above.
195
+
196
+ Eight tasks — `circle_right_triangle`, `cross_and_knots`, `graph_counting`, `grid_path`, `identifying_shapes`, `inside_circles`, `maze_solving`, `sort_circles` — additionally expose `gold_to_output(i)` in `utils.py`, which renders the gold answer for sample `i` in the exact format `output_prompt.txt` asks for. This is useful for building few-shot exemplars.
197
+
198
+ ### Notes
199
+
200
+ - `eval.py` takes `--answer`/`-a` and `--output`/`-o`; the defaults refer to files that are not shipped here, so pass both explicitly.
201
+ - Several `utils.py` files contain a second, commented-out `output_from_text` inside a triple-quoted string, left over from earlier prompt formats. Only the live top-level definition is used.
202
 
203
  ## Licence
204
 
change_colour/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.19 kB). View file
 
circle_location/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.19 kB). View file
 
circle_right_triangle/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.78 kB). View file
 
circle_right_triangle/eval.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import argparse
4
+ if __name__ == "__main__":
5
+ # Parse command line arguments
6
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
7
+ parser.add_argument(
8
+ '--answer', '-a',
9
+ type=str,
10
+ default='answer_gpt4o.json',
11
+ help='Path to the answer JSON file (default: answer.json)'
12
+ )
13
+ parser.add_argument(
14
+ '--output', '-o',
15
+ type=str,
16
+ default='eval_gpt4o.json',
17
+ help='Path to the output JSON file (default: eval.json)'
18
+ )
19
+ args = parser.parse_args()
20
+ # Assuming your JSON data is stored in a file called 'results.json'
21
+ with open(args.answer, 'r') as f:
22
+ data = json.load(f)
23
+
24
+ # Initialize variables to calculate accuracies
25
+ correct_counts = 0
26
+ total_counts = 0
27
+ category_accuracies = {}
28
+
29
+ # Iterate through the JSON data
30
+
31
+ for entry in data:
32
+ grid_size = entry['rows']
33
+ num_circles = entry['circles']
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ #if grid_size not in category_accuracies:
38
+ # category_accuracies[grid_size] = {'correct': 0 , 'total': 0}
39
+
40
+ if num_circles not in category_accuracies:
41
+ category_accuracies[num_circles] = {'correct': 0, 'total': 0}
42
+
43
+ category_accuracies[num_circles]['total'] += 1
44
+ #category_accuracies['total'] += 1
45
+ # category_accuracies[(grid_size,num_circles)]['total'] += 1
46
+
47
+ if entry["ERROR"]:
48
+ continue
49
+
50
+ # Check if the output is correct
51
+ output = entry["Output"]
52
+
53
+ if output == entry["right"]:
54
+ correct_counts += 1
55
+ #category_accuracies['correct'] += 1
56
+ category_accuracies[num_circles]['correct'] += 1
57
+
58
+ # Calculate overall accuracy
59
+ overall_accuracy = correct_counts / total_counts * 100
60
+
61
+ category_accuracy_percentages = {
62
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
63
+ }
64
+
65
+ # Prepare results for saving
66
+ eval_results = {
67
+ "Overall Accuracy": overall_accuracy,
68
+ "Category-wise Accuracy": category_accuracy_percentages
69
+ }
70
+
71
+ # Save results to eval.json
72
+ with open(args.output, 'w') as eval_file:
73
+ json.dump(eval_results, eval_file, indent=4)
74
+
75
+ print("Evaluation results saved to eval.json.")
76
+
77
+
78
+ """for entry in data:
79
+ grid_size = entry['rows']
80
+ num_circles = entry['circles']
81
+ total_counts += 1
82
+
83
+ # Calculate per-category accuracy
84
+ if grid_size not in category_accuracies:
85
+ category_accuracies[grid_size] = {'correct': 0 , 'total': 0}
86
+
87
+ if num_circles not in category_accuracies[grid_size]:
88
+ category_accuracies[grid_size][num_circles] = {'correct': 0, 'total': 0}
89
+
90
+ category_accuracies[grid_size][num_circles]['total'] += 1
91
+ category_accuracies[grid_size]['total'] += 1
92
+ # category_accuracies[(grid_size,num_circles)]['total'] += 1
93
+
94
+ if entry["ERROR"]:
95
+ continue
96
+
97
+ # Check if the output is correct
98
+ output = entry["Output"]
99
+
100
+ if output == entry["right"]:
101
+ correct_counts += 1
102
+ category_accuracies[grid_size]['correct'] += 1
103
+ category_accuracies[grid_size][num_circles]['correct'] += 1
104
+
105
+ # Calculate overall accuracy
106
+ overall_accuracy = correct_counts / total_counts * 100
107
+
108
+ for grid_size in category_accuracies:
109
+ category_accuracies[grid_size]["Accuracy"] = category_accuracies[grid_size]['correct'] / category_accuracies[grid_size]['total'] * 100
110
+ for num_queens in category_accuracies[grid_size]:
111
+ if num_queens == 'correct' or num_queens == 'total' or num_queens == 'Accuracy':
112
+ continue
113
+ # print(category_accuracies[grid_size][num_queens])
114
+ category_accuracies[grid_size][num_queens]["Accuracy"] = category_accuracies[grid_size][num_queens]['correct'] / category_accuracies[grid_size][num_queens]['total'] * 100
115
+
116
+
117
+
118
+
119
+ # category_accuracies["Overall Accuracy"] = overall_accuracy
120
+
121
+ final_results = {}
122
+ for grid_size in category_accuracies:
123
+ # print(grid_size)
124
+ final_results[grid_size] = {}
125
+ final_results[grid_size]["Overall Accuracy"] = category_accuracies[grid_size]["Accuracy"]
126
+ final_results[grid_size]["Category-wise Accuracy"] = {}
127
+ for num_crosses in category_accuracies[grid_size]:
128
+ if num_crosses == 'correct' or num_crosses == 'total' or num_crosses == 'Accuracy':
129
+ continue
130
+ final_results[grid_size]["Category-wise Accuracy"][num_crosses] = category_accuracies[grid_size][num_crosses]["Accuracy"]
131
+
132
+ final_results["Overall Accuracy"] = overall_accuracy
133
+
134
+
135
+ # Save results to eval.json
136
+ with open(args.output, 'w') as eval_file:
137
+ json.dump(final_results, eval_file, indent=4)
138
+
139
+ print("Evaluation results saved to eval.json.")"""
circle_right_triangle/utils.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import json
3
+
4
+ def output_from_text(output_text):
5
+
6
+ try:
7
+ output_text = output_text.split('\n')
8
+ # print(output_text)
9
+ if len(output_text) < 2:
10
+ out_line = output_text[-1].strip()
11
+ else:
12
+ out_line = output_text[-2].strip()
13
+
14
+ try:
15
+ match = re.search(r'\s*(yes|no)\s*', out_line.lower(), re.IGNORECASE)
16
+ if match:
17
+ return {
18
+ "OUTPUT": (match.group(1).capitalize() == "Yes"),
19
+ "ERROR": None
20
+ }
21
+ else:
22
+ out_line = output_text[-1].strip()
23
+ match = re.search(r'\s*(yes|no)\s*', out_line, re.IGNORECASE)
24
+ if match:
25
+ return {
26
+ "OUTPUT": (match.group(1).capitalize() == "Yes"),
27
+ "ERROR": None
28
+ }
29
+ else:
30
+ return {
31
+ "OUTPUT": None,
32
+ "ERROR": "Output file should have last line as either 'yes' or 'no'"
33
+ }
34
+ except Exception as e:
35
+ return {
36
+ "OUTPUT": None,
37
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
38
+ }
39
+ except Exception as e:
40
+
41
+ return {
42
+ "OUTPUT": None,
43
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
44
+ }
45
+
46
+
47
+ import os
48
+ import json
49
+ def gold_to_output(i):
50
+ gold_output = None
51
+ try:
52
+ #get directory of this file
53
+ dir_of_file = os.path.dirname(os.path.realpath(__file__))
54
+ #open the data file
55
+ with open(dir_of_file + "\data.json") as f:
56
+ data = json.load(f)
57
+ row = data[i]
58
+ ans = row['right']
59
+ output_prompt = "YES" if ans else "NO"
60
+ except Exception as e:
61
+ return {
62
+ "OUTPUT": None,
63
+ "ERROR": str(e)
64
+ }
65
+
66
+ return {
67
+ "OUTPUT": output_prompt,
68
+ "ERROR": None
69
+ }
70
+
71
+
72
+ # # # Test the function
73
+ # with open("./answer.json", "r") as f:
74
+ # data = json.load(f)
75
+ # # print(data[1])
76
+ # for i in data:
77
+ # output_text = i["gpt_response"]
78
+
79
+ # i["Output"] = output_from_text(output_text)["OUTPUT"]
80
+ # i["ERROR"] = output_from_text(output_text)["ERROR"]
81
+
82
+ # with open("./answer.json", "w") as f:
83
+ # json.dump(data, f, indent=4)
84
+ # print("Output saved to answer.json")
colours_present/utils.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ def output_from_text(text):
4
+ #extract the number in the last line of text
5
+ try:
6
+ lines = text.strip().split("\n")
7
+ lines = list(filter(None, lines))
8
+ last_line = list(filter(None, lines[-1].split(" ")))
9
+ #last_line = [x.lower() for x in last_line]
10
+ answer = []
11
+ for x in last_line:
12
+ word = re.sub(r'[^a-zA-Z]', '', x.lower())
13
+ if word == 'no' or word == 'yes':
14
+ answer.append(word)
15
+
16
+ if answer != []:
17
+ return {
18
+ "OUTPUT": answer,
19
+ "ERROR": None
20
+ }
21
+ else:
22
+ return{
23
+ "OUTPUT": None,
24
+ "ERROR": 'Does not give yes/no answer'
25
+ }
26
+ except Exception as e:
27
+ return {
28
+ "OUTPUT": None,
29
+ "ERROR": str(e)
30
+ }
comparing_size/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.26 kB). View file
 
comparing_size/eval.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['Rows']
31
+ colours_present = entry['Gold_output']
32
+ colours_present = [s.lower() for s in colours_present]
33
+
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ if num_objects not in category_accuracies:
38
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[num_objects]['total'] += 1
41
+
42
+ try:
43
+ prediction = entry['Output']
44
+ prediction = [s.lower() for s in prediction]
45
+ except:
46
+ continue
47
+ # print(prediction , odd_one)
48
+ # Check if the prediction is correct
49
+ if colours_present == prediction:
50
+ correct_counts += 1
51
+ category_accuracies[num_objects]['correct'] += 1
52
+
53
+
54
+
55
+ # Calculate overall accuracy
56
+ overall_accuracy = correct_counts / total_counts * 100
57
+
58
+ # Calculate accuracy for each category
59
+ category_accuracy_percentages = {
60
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
61
+ }
62
+
63
+ # Prepare results for saving
64
+ eval_results = {
65
+ "Overall Accuracy": overall_accuracy,
66
+ "Category-wise Accuracy": category_accuracy_percentages
67
+ }
68
+
69
+ # Save results to eval.json
70
+ with open(args.output, 'w') as eval_file:
71
+ json.dump(eval_results, eval_file, indent=4)
72
+
73
+ print("Evaluation results saved to eval.json.")
count_coloured_circles/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.2 kB). View file
 
count_coloured_circles/eval.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['num_objects']
31
+ order = entry['red_circle']
32
+ order = int(order)
33
+
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ if num_objects not in category_accuracies:
38
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[num_objects]['total'] += 1
41
+
42
+ try:
43
+ predicted_order = entry['Output']
44
+ predicted_order = int(predicted_order)
45
+ except:
46
+ continue
47
+
48
+
49
+ # Check if the prediction is correct
50
+ if predicted_order != None and predicted_order == order:
51
+ correct_counts += 1
52
+ category_accuracies[num_objects]['correct'] += 1
53
+
54
+
55
+
56
+ # Calculate overall accuracy
57
+ overall_accuracy = correct_counts / total_counts * 100
58
+
59
+ # Calculate accuracy for each category
60
+ category_accuracy_percentages = {
61
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
62
+ }
63
+
64
+ # Prepare results for saving
65
+ eval_results = {
66
+ "Overall Accuracy": overall_accuracy,
67
+ "Category-wise Accuracy": category_accuracy_percentages
68
+ }
69
+
70
+ # Save results to eval.json
71
+ with open(args.output, 'w') as eval_file:
72
+ json.dump(eval_results, eval_file, indent=4)
73
+
74
+ print("Evaluation results saved to " + args.output)
counting_circles/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.19 kB). View file
 
counting_circles/eval.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer_gpt4o.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval_gpt4o.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['num_objects']
31
+
32
+
33
+ total_counts += 1
34
+
35
+ # Calculate per-category accuracy
36
+ if num_objects not in category_accuracies:
37
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
38
+
39
+ category_accuracies[num_objects]['total'] += 1
40
+
41
+ try:
42
+ predicted_count = entry['Output']
43
+ except:
44
+ continue
45
+
46
+ # Check if the prediction is correct
47
+ if predicted_count != None and int(num_objects) == int(predicted_count):
48
+ correct_counts += 1
49
+ category_accuracies[num_objects]['correct'] += 1
50
+
51
+
52
+
53
+ # Calculate overall accuracy
54
+ overall_accuracy = correct_counts / total_counts * 100
55
+
56
+ # Calculate accuracy for each category
57
+ category_accuracy_percentages = {
58
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
59
+ }
60
+
61
+ # Prepare results for saving
62
+ eval_results = {
63
+ "Overall Accuracy": overall_accuracy,
64
+ "Category-wise Accuracy": category_accuracy_percentages
65
+ }
66
+
67
+ # Save results to eval.json
68
+ with open(args.output, 'w') as eval_file:
69
+ json.dump(eval_results, eval_file, indent=4)
70
+
71
+ print("Evaluation results saved to eval.json.")
counting_circles/utils.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+
4
+ def output_from_text(text):
5
+ #extract the number in the last line of text
6
+ try:
7
+ lines = text.strip().split("\n")
8
+ lines = list(filter(None, lines))
9
+ pattern = r'^[^a-zA-Z0-9\s]+$'
10
+ lines = [s for s in lines if not re.fullmatch(pattern, s)]
11
+ answer = -1
12
+ answer = int(re.findall(r"\b\d+\b", lines[-1])[0])
13
+ if answer != -1:
14
+ return {
15
+ "OUTPUT": answer,
16
+ "ERROR": None
17
+ }
18
+ else:
19
+ return{
20
+ "OUTPUT": None,
21
+ "ERROR": 'Does not give correct format'
22
+ }
23
+ except Exception as e:
24
+ return {
25
+ "OUTPUT": None,
26
+ "ERROR": str(e)
27
+ }
counting_locations/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.49 kB). View file
 
counting_shapes/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.5 kB). View file
 
cross_and_knots/eval.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import argparse
4
+ if __name__ == "__main__":
5
+ # Parse command line arguments
6
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
7
+ parser.add_argument(
8
+ '--answer', '-a',
9
+ type=str,
10
+ default='answer_gpt4o.json',
11
+ help='Path to the answer JSON file (default: answer.json)'
12
+ )
13
+ parser.add_argument(
14
+ '--output', '-o',
15
+ type=str,
16
+ default='eval_gpt4o.json',
17
+ help='Path to the output JSON file (default: eval.json)'
18
+ )
19
+ args = parser.parse_args()
20
+ # Assuming your JSON data is stored in a file called 'results.json'
21
+ with open(args.answer, 'r') as f:
22
+ data = json.load(f)
23
+
24
+ # Initialize variables to calculate accuracies
25
+ correct_counts = 0
26
+ total_counts = 0
27
+ category_accuracies = {}
28
+
29
+ # Iterate through the JSON data
30
+
31
+ for entry in data:
32
+ grid_size = entry['n']
33
+ num_circles = entry['crosses']
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ #if grid_size not in category_accuracies:
38
+ # category_accuracies[grid_size] = {'correct': 0 , 'total': 0}
39
+
40
+ if num_circles not in category_accuracies:
41
+ category_accuracies[num_circles] = {'correct': 0, 'total': 0}
42
+
43
+ category_accuracies[num_circles]['total'] += 1
44
+ #category_accuracies['total'] += 1
45
+ # category_accuracies[(grid_size,num_circles)]['total'] += 1
46
+
47
+ if entry["ERROR"]:
48
+ continue
49
+
50
+ # Check if the output is correct
51
+ output = entry["Output"]
52
+
53
+ if output is None:
54
+ if len(entry["gold_output"]) == 0:
55
+ correct_counts += 1
56
+ category_accuracies[num_circles]['correct'] += 1
57
+ else:
58
+ if output in entry["gold_output"]:
59
+ correct_counts += 1
60
+ category_accuracies[num_circles]['correct'] += 1
61
+
62
+ # Calculate overall accuracy
63
+ overall_accuracy = correct_counts / total_counts * 100
64
+
65
+ category_accuracy_percentages = {
66
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
67
+ }
68
+
69
+ # Prepare results for saving
70
+ eval_results = {
71
+ "Overall Accuracy": overall_accuracy,
72
+ "Category-wise Accuracy": category_accuracy_percentages
73
+ }
74
+
75
+ # Save results to eval.json
76
+ with open(args.output, 'w') as eval_file:
77
+ json.dump(eval_results, eval_file, indent=4)
78
+
79
+ print("Evaluation results saved to eval.json.")
cross_and_knots/utils.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import json
3
+ import os
4
+
5
+ def output_from_text(output_text):
6
+ try:
7
+ output_text = output_text.split('\n')
8
+ # print(output_text)
9
+ out_line = output_text[-1].strip()
10
+ #print(out_line)
11
+ if out_line == "None":
12
+ return {
13
+ "OUTPUT": None,
14
+ "ERROR": None
15
+ }
16
+ else:
17
+ try:
18
+ match = re.search(r'\((-?\d+)\s*,\s*(-?\d+)\)', out_line)
19
+
20
+ if match:
21
+ # Extract x and y values as integers
22
+ #print(match.group(1))
23
+ #print(match.group(2))
24
+ x, y = map(int, match.groups())
25
+ # print(x, y)
26
+ return {
27
+ "OUTPUT": (x, y),
28
+ "ERROR": None
29
+ }
30
+ else:
31
+ out_line = output_text[-1].strip()
32
+ match = re.search(r'\[(-?\d+),\s*(-?\d+)\]', out_line)
33
+
34
+ if match:
35
+ # Extract x and y values as integers
36
+ x, y = map(int, match.groups())
37
+ # print(x, y)
38
+ return {
39
+ "OUTPUT": (x, y),
40
+ "ERROR": None
41
+ }
42
+ else:
43
+ return {
44
+ "OUTPUT": None,
45
+ "ERROR": "Output file should have a single tuple of integers"
46
+ }
47
+ except Exception as e:
48
+ return {
49
+ "OUTPUT": None,
50
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
51
+ }
52
+ except Exception as e:
53
+ return {
54
+ "OUTPUT": None,
55
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
56
+ }
57
+
58
+
59
+
60
+ def gold_to_output(i):
61
+ gold_output = None
62
+ try:
63
+ #get directory of this file
64
+ dir_of_file = os.path.dirname(os.path.realpath(__file__))
65
+ #open the data file
66
+ with open(dir_of_file + "\data.json") as f:
67
+ data = json.load(f)
68
+ row = data[i]
69
+ gold_output = row['gold_output']
70
+ x = gold_output[-1][0]
71
+ y = gold_output[-1][1]
72
+ output_prompt = f"({x}, {y})"
73
+
74
+ except Exception as e:
75
+ return {
76
+ "OUTPUT": None,
77
+ "ERROR": str(e)
78
+ }
79
+
80
+ return {
81
+ "OUTPUT": output_prompt,
82
+ "ERROR": None
83
+ }
84
+
85
+
86
+ # # Test the function
87
+ # with open("./answer_few_shot.json", "r") as f:
88
+ # data = json.load(f)
89
+ # # print(data[1])
90
+ # for i in data:
91
+ # output_text = i["gpt_response"]
92
+ # i["Output"] = output_from_text(output_text)["OUTPUT"]
93
+ # i["ERROR"] = output_from_text(output_text)["ERROR"]
94
+ # #remove OUTPUT key
95
+ # # i.pop("OUTPUT")
96
+
97
+ # with open("./answer_few_shot.json", "w") as f:
98
+ # json.dump(data, f, indent=4)
99
+ # print("Output saved to answer.json")
graph_counting/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.22 kB). View file
 
grid_path/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.48 kB). View file
 
identifying_shapes/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.24 kB). View file
 
identifying_shapes/eval.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['Rows']
31
+ colours_present = entry['Gold_output']
32
+ colours_present = [s.lower() for s in colours_present]
33
+
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ if num_objects not in category_accuracies:
38
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[num_objects]['total'] += 1
41
+
42
+ try:
43
+ prediction = entry['Output']
44
+ prediction = [s.lower() for s in prediction]
45
+ except:
46
+ continue
47
+ # print(prediction , odd_one)
48
+ # Check if the prediction is correct
49
+ if colours_present == prediction:
50
+ correct_counts += 1
51
+ category_accuracies[num_objects]['correct'] += 1
52
+
53
+
54
+
55
+ # Calculate overall accuracy
56
+ overall_accuracy = correct_counts / total_counts * 100
57
+
58
+ # Calculate accuracy for each category
59
+ category_accuracy_percentages = {
60
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
61
+ }
62
+
63
+ # Prepare results for saving
64
+ eval_results = {
65
+ "Overall Accuracy": overall_accuracy,
66
+ "Category-wise Accuracy": category_accuracy_percentages
67
+ }
68
+
69
+ # Save results to eval.json
70
+ with open(args.output, 'w') as eval_file:
71
+ json.dump(eval_results, eval_file, indent=4)
72
+
73
+ print("Evaluation results saved to eval.json.")
identifying_shapes/utils.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import re
4
+
5
+ def output_from_text(output_text):
6
+ try:
7
+
8
+ lines = output_text.strip().split("\n")
9
+ lines = list(filter(None, lines))
10
+ last_line = list(filter(None, lines[-1].split(" ")))
11
+
12
+ answer = []
13
+ for x in last_line:
14
+ word = re.sub(r'[^a-zA-Z]', '', x.lower())
15
+ if word != 'answer':
16
+ answer.append(word)
17
+ if answer != []:
18
+ return {
19
+ "OUTPUT": answer,
20
+ "ERROR": None
21
+ }
22
+ else:
23
+ return{
24
+ "OUTPUT": None,
25
+ "ERROR": 'Does not give answer in correct format'
26
+ }
27
+ except Exception as e:
28
+ return {
29
+ "OUTPUT": None,
30
+ "ERROR": str(e)
31
+ }
32
+
33
+ def gold_to_output(i):
34
+ gold_output = None
35
+ try:
36
+ #get directory of this file
37
+ dir_of_file = os.path.dirname(os.path.realpath(__file__))
38
+ #open the data file
39
+ with open(dir_of_file + "\data.json") as f:
40
+ data = json.load(f)
41
+ row = data[i]
42
+ gold_output = row['num_objects']
43
+ output_prompt = "COUNT:" + str(gold_output)
44
+ except Exception as e:
45
+ return {
46
+ "OUTPUT": None,
47
+ "ERROR": str(e)
48
+ }
49
+
50
+ return {
51
+ "OUTPUT": output_prompt,
52
+ "ERROR": None
53
+ }
layered_colours/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.39 kB). View file
 
layered_colours/eval.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['num_layers']
31
+ order = entry['colors']
32
+ order = [s.lower() for s in order]
33
+ #order = order[::-1]
34
+
35
+ total_counts += 1
36
+
37
+ # Calculate per-category accuracy
38
+ if num_objects not in category_accuracies:
39
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
40
+
41
+ category_accuracies[num_objects]['total'] += 1
42
+
43
+ try:
44
+ predicted_order = entry['Output']
45
+ predicted_order = [s.lower() for s in predicted_order]
46
+ except:
47
+ continue
48
+
49
+
50
+ # Check if the prediction is correct
51
+ if predicted_order == order:
52
+ correct_counts += 1
53
+ category_accuracies[num_objects]['correct'] += 1
54
+
55
+
56
+
57
+ # Calculate overall accuracy
58
+ overall_accuracy = correct_counts / total_counts * 100
59
+
60
+ # Calculate accuracy for each category
61
+ category_accuracy_percentages = {
62
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
63
+ }
64
+
65
+ # Prepare results for saving
66
+ eval_results = {
67
+ "Overall Accuracy": overall_accuracy,
68
+ "Category-wise Accuracy": category_accuracy_percentages
69
+ }
70
+
71
+ # Save results to eval.json
72
+ with open(args.output, 'w') as eval_file:
73
+ json.dump(eval_results, eval_file, indent=4)
74
+
75
+ print("Evaluation results saved to eval.json.")
layered_colours/utils.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ # def output_from_text(output_text):
4
+ # try:
5
+ # try:
6
+ # lline = output_text.split("\n")[-1].strip()
7
+ # shape = lline.split(":")[-1].strip()
8
+ # word1 = lline.split(":")[0].strip().lower()
9
+ # if word1 != "answer":
10
+ # raise Exception("Invalid output")
11
+ # return {"OUTPUT": shape.lower(), "ERROR": None}
12
+ # except:
13
+ # try:
14
+ # lline = output_text.split("\n")[-2]
15
+ # shape = lline.split(":")[-1].strip()
16
+ # if shape.lower() not in ["circle", "rectangle", "triangle"]:
17
+ # raise Exception("Invalid output")
18
+ # return {"OUTPUT": shape.lower(), "ERROR": None}
19
+ # except:
20
+ # return {"OUTPUT": None, "ERROR": "Invalid output"}
21
+
22
+ # except Exception as e:
23
+ # return {"OUTPUT": None, "ERROR": str(e)}
24
+
25
+
26
+ def output_from_text(output_text):
27
+
28
+ try:
29
+ lines = output_text.strip().split("\n")
30
+ lines = list(filter(None, lines))
31
+ last_line = list(filter(None, lines[-1].split(" ")))
32
+ colours = ['black', 'gray', 'brown', 'maroon', 'red', 'coral', 'tan', 'orange', 'ivory', 'goldenrod', 'yellow', 'green', 'olive', 'turquoise', 'skyblue', 'blue', 'lavender', 'purple', 'pink', 'fuchsia']
33
+
34
+ #last_line = [x.lower() for x in last_line]
35
+ answer = []
36
+ for x in last_line:
37
+ word = re.sub(r'[^a-zA-Z]', '', x.lower())
38
+ if word in colours:
39
+ answer.append(word.lower())
40
+
41
+ return {
42
+ "OUTPUT": answer,
43
+ "ERROR": None
44
+ }
45
+
46
+ except Exception as e:
47
+
48
+ return {
49
+ "OUTPUT": None,
50
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
51
+ }
layered_shapes/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.08 kB). View file
 
layered_shapes/utils.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # def output_from_text(output_text):
2
+ # try:
3
+ # try:
4
+ # lline = output_text.split("\n")[-1].strip()
5
+ # shape = lline.split(":")[-1].strip()
6
+ # word1 = lline.split(":")[0].strip().lower()
7
+ # if word1 != "answer":
8
+ # raise Exception("Invalid output")
9
+ # return {"OUTPUT": shape.lower(), "ERROR": None}
10
+ # except:
11
+ # try:
12
+ # lline = output_text.split("\n")[-2]
13
+ # shape = lline.split(":")[-1].strip()
14
+ # if shape.lower() not in ["circle", "rectangle", "triangle"]:
15
+ # raise Exception("Invalid output")
16
+ # return {"OUTPUT": shape.lower(), "ERROR": None}
17
+ # except:
18
+ # return {"OUTPUT": None, "ERROR": "Invalid output"}
19
+
20
+ # except Exception as e:
21
+ # return {"OUTPUT": None, "ERROR": str(e)}
22
+
23
+
24
+ def output_from_text(output_text):
25
+
26
+ try:
27
+ output_text = output_text.split(':')
28
+ # print(output_text)
29
+ # if len(output_text) < 2:
30
+ out_line = output_text[-1].strip()
31
+ # else:
32
+ # out_line = output_text[-2].strip()
33
+
34
+ try:
35
+ path = [word.strip() for word in out_line.split(",")]
36
+
37
+ # if len(path) >= 2:
38
+ return {
39
+ "OUTPUT": path,
40
+ "ERROR": None
41
+ }
42
+
43
+ except Exception as e:
44
+ return {
45
+ "OUTPUT": None,
46
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
47
+ }
48
+ except Exception as e:
49
+
50
+ return {
51
+ "OUTPUT": None,
52
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
53
+ }
list_colours/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.72 kB). View file
 
list_shapes/eval.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['num_objects']
31
+ order = entry['list_shapes']
32
+ order = [s.lower() for s in order]
33
+
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ if num_objects not in category_accuracies:
38
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[num_objects]['total'] += 1
41
+
42
+ try:
43
+ predicted_order = entry['Output']
44
+ predicted_order = [s.lower() for s in predicted_order]
45
+ """for i in range(len(predicted_order)):
46
+ if predicted_order[i] == "rectangle" or predicted_order[i] == "diamond":
47
+ predicted_order[i] = "square"""
48
+ except:
49
+ continue
50
+
51
+
52
+ # Check if the prediction is correct
53
+ if predicted_order == order:
54
+ correct_counts += 1
55
+ category_accuracies[num_objects]['correct'] += 1
56
+
57
+
58
+
59
+ # Calculate overall accuracy
60
+ overall_accuracy = correct_counts / total_counts * 100
61
+
62
+ # Calculate accuracy for each category
63
+ category_accuracy_percentages = {
64
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
65
+ }
66
+
67
+ # Prepare results for saving
68
+ eval_results = {
69
+ "Overall Accuracy": overall_accuracy,
70
+ "Category-wise Accuracy": category_accuracy_percentages
71
+ }
72
+
73
+ # Save results to eval.json
74
+ with open(args.output, 'w') as eval_file:
75
+ json.dump(eval_results, eval_file, indent=4)
76
+
77
+ print("Evaluation results saved to eval.json.")
list_shapes/utils.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import matplotlib.colors as mcolors
3
+
4
+
5
+ def output_from_text(text):
6
+ #extract the number in the last line of text
7
+ try:
8
+ lines = text.strip().split("\n")
9
+ lines = list(filter(None, lines))
10
+ last_line = list(filter(None, lines[-1].split(" ")))
11
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon', 'square']
12
+ #colours = sorted(mcolors.CSS4_COLORS, key=lambda c: tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(c))))
13
+ #last_line = [x.lower() for x in last_line]
14
+ answer = set()
15
+ for x in last_line:
16
+ word = re.sub(r'[^a-zA-Z]', '', x.lower())
17
+ if word in shapes:
18
+ answer.add(word.lower())
19
+
20
+ if answer:
21
+ return {
22
+ "OUTPUT": sorted(list(answer)),
23
+ "ERROR": None
24
+ }
25
+ else:
26
+ return{
27
+ "OUTPUT": None,
28
+ "ERROR": 'Does not give correct format'
29
+ }
30
+ except Exception as e:
31
+ return {
32
+ "OUTPUT": None,
33
+ "ERROR": str(e)
34
+ }
locate_circles_colour/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.71 kB). View file
 
locate_circles_colour/eval.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import argparse
4
+ if __name__ == "__main__":
5
+ # Parse command line arguments
6
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
7
+ parser.add_argument(
8
+ '--answer', '-a',
9
+ type=str,
10
+ default='answer_gpt4o.json',
11
+ help='Path to the answer JSON file (default: answer.json)'
12
+ )
13
+ parser.add_argument(
14
+ '--output', '-o',
15
+ type=str,
16
+ default='eval_gpt4o.json',
17
+ help='Path to the output JSON file (default: eval.json)'
18
+ )
19
+ args = parser.parse_args()
20
+ # Assuming your JSON data is stored in a file called 'results.json'
21
+ with open(args.answer, 'r') as f:
22
+ data = json.load(f)
23
+
24
+ # Initialize variables to calculate accuracies
25
+ correct_counts = 0
26
+ total_counts = 0
27
+ category_accuracies = {}
28
+
29
+ # Iterate through the JSON data
30
+ for entry in data:
31
+ grid_size = entry['rows']
32
+ n_circles = entry['n_circles']
33
+ total_counts += 1
34
+
35
+ # Calculate per-category accuracy
36
+
37
+ if n_circles not in category_accuracies:
38
+ category_accuracies[n_circles] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[n_circles]['total'] += 1
41
+ # category_accuracies[(grid_size,n_circles)]['total'] += 1
42
+
43
+ if entry["ERROR"]:
44
+ continue
45
+
46
+ # Check if the output is correct
47
+ output = entry["Output"]
48
+ gold_output = entry["gold_output"]
49
+
50
+ #check if elements in output are in gold_output
51
+ if sorted(output) == sorted(gold_output) :
52
+ correct_counts += 1
53
+ category_accuracies[n_circles]['correct'] += 1
54
+ # category_accuracies[(grid_size,n_circles)]['correct'] += 1
55
+ # Calculate overall accuracy
56
+ overall_accuracy = correct_counts / total_counts * 100
57
+
58
+ category_accuracy_percentages = {
59
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
60
+ }
61
+
62
+ # Prepare results for saving
63
+ eval_results = {
64
+ "Overall Accuracy": overall_accuracy,
65
+ "Category-wise Accuracy": category_accuracy_percentages
66
+ }
67
+
68
+ # Save results to eval.json
69
+ with open(args.output, 'w') as eval_file:
70
+ json.dump(eval_results, eval_file, indent=4)
71
+
72
+ print("Evaluation results saved to eval.json.")
locate_circles_colour/utils.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def output_from_text(output_text):
2
+ try:
3
+ try:
4
+ # print(1)
5
+ lline = output_text.split("\n")[-1].strip()
6
+ # print(lline)
7
+ lline = lline.split(":")[-1].strip()
8
+ # print(lline)
9
+ coordinates = lline.split(" ")
10
+ # print(coordinates)
11
+ #the list of coordinates now has in form (r,c) where r is the row and c is the column
12
+ # i want to extract r and c and store them in a list
13
+ coord_list = []
14
+ for i in coordinates:
15
+ i = i.strip("()")
16
+ i = i.split(",")
17
+ coord_list.append((int(i[0]), int(i[1]))
18
+ )
19
+ # if coord_list == ["```"]:
20
+ # raise Exception("Invalid output")
21
+ return {"OUTPUT": coord_list, "ERROR": None}
22
+ except:
23
+ try:
24
+ lline = output_text.split("\n")[-2]
25
+ coordinates = lline.split(" ")
26
+ #the list of coordinates now has in form (r,c) where r is the row and c is the column
27
+ # i want to extract r and c and store them in a list
28
+ coord_list = []
29
+ for i in coordinates:
30
+ i = i.strip("()")
31
+ i = i.split(",")
32
+ coord_list.append((int(i[0]), int(i[1]))
33
+ )
34
+ return {"OUTPUT": coord_list, "ERROR": None}
35
+ except:
36
+ return {"OUTPUT": None, "ERROR": "Invalid output"}
37
+
38
+ except Exception as e:
39
+ return {"OUTPUT": None, "ERROR": str(e)}
40
+
41
+
42
+ # import json
43
+ # with open("./answer.json", "r") as f:
44
+ # data = json.load(f)
45
+ # # print(data[1])
46
+ # for i in data:
47
+ # output_text = i["gpt_response"]
48
+ # i["Output"] = output_from_text(output_text)["OUTPUT"]
49
+ # i["ERROR"] = output_from_text(output_text)["ERROR"]
50
+ # #remove OUTPUT key
51
+ # # i.pop("OUTPUT")
52
+
53
+ # with open("./answer.json", "w") as f:
54
+ # json.dump(data, f, indent=4)
55
+ # print("Output saved to answer.json")
locate_circles_shape/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.71 kB). View file
 
locate_circles_shape/eval.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import argparse
4
+ if __name__ == "__main__":
5
+ # Parse command line arguments
6
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
7
+ parser.add_argument(
8
+ '--answer', '-a',
9
+ type=str,
10
+ default='answer_gpt4o.json',
11
+ help='Path to the answer JSON file (default: answer.json)'
12
+ )
13
+ parser.add_argument(
14
+ '--output', '-o',
15
+ type=str,
16
+ default='eval_gpt4o.json',
17
+ help='Path to the output JSON file (default: eval.json)'
18
+ )
19
+ args = parser.parse_args()
20
+ # Assuming your JSON data is stored in a file called 'results.json'
21
+ with open(args.answer, 'r') as f:
22
+ data = json.load(f)
23
+
24
+ # Initialize variables to calculate accuracies
25
+ correct_counts = 0
26
+ total_counts = 0
27
+ category_accuracies = {}
28
+
29
+ # Iterate through the JSON data
30
+ for entry in data:
31
+ grid_size = entry['rows']
32
+ n_circles = entry['n_circles']
33
+ total_counts += 1
34
+
35
+ # Calculate per-category accuracy
36
+
37
+ if n_circles not in category_accuracies:
38
+ category_accuracies[n_circles] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[n_circles]['total'] += 1
41
+ # category_accuracies[(grid_size,n_circles)]['total'] += 1
42
+
43
+ if entry["ERROR"]:
44
+ continue
45
+
46
+ # Check if the output is correct
47
+ output = entry["Output"]
48
+ gold_output = entry["gold_output"]
49
+
50
+ #check if elements in output are in gold_output
51
+ if sorted(output) == sorted(gold_output) :
52
+ correct_counts += 1
53
+ category_accuracies[n_circles]['correct'] += 1
54
+ # category_accuracies[(grid_size,n_circles)]['correct'] += 1
55
+ # Calculate overall accuracy
56
+ overall_accuracy = correct_counts / total_counts * 100
57
+
58
+ category_accuracy_percentages = {
59
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
60
+ }
61
+
62
+ # Prepare results for saving
63
+ eval_results = {
64
+ "Overall Accuracy": overall_accuracy,
65
+ "Category-wise Accuracy": category_accuracy_percentages
66
+ }
67
+
68
+ # Save results to eval.json
69
+ with open(args.output, 'w') as eval_file:
70
+ json.dump(eval_results, eval_file, indent=4)
71
+
72
+ print("Evaluation results saved to eval.json.")
locate_circles_shape/utils.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def output_from_text(output_text):
2
+ try:
3
+ try:
4
+ # print(1)
5
+ lline = output_text.split("\n")[-1].strip()
6
+ # print(lline)
7
+ lline = lline.split(":")[-1].strip()
8
+ # print(lline)
9
+ coordinates = lline.split(" ")
10
+ # print(coordinates)
11
+ #the list of coordinates now has in form (r,c) where r is the row and c is the column
12
+ # i want to extract r and c and store them in a list
13
+ coord_list = []
14
+ for i in coordinates:
15
+ i = i.strip("()")
16
+ i = i.split(",")
17
+ coord_list.append((int(i[0]), int(i[1]))
18
+ )
19
+ # if coord_list == ["```"]:
20
+ # raise Exception("Invalid output")
21
+ return {"OUTPUT": coord_list, "ERROR": None}
22
+ except:
23
+ try:
24
+ lline = output_text.split("\n")[-2]
25
+ coordinates = lline.split(" ")
26
+ #the list of coordinates now has in form (r,c) where r is the row and c is the column
27
+ # i want to extract r and c and store them in a list
28
+ coord_list = []
29
+ for i in coordinates:
30
+ i = i.strip("()")
31
+ i = i.split(",")
32
+ coord_list.append((int(i[0]), int(i[1]))
33
+ )
34
+ return {"OUTPUT": coord_list, "ERROR": None}
35
+ except:
36
+ return {"OUTPUT": None, "ERROR": "Invalid output"}
37
+
38
+ except Exception as e:
39
+ return {"OUTPUT": None, "ERROR": str(e)}
40
+
41
+
42
+ # import json
43
+ # with open("./answer.json", "r") as f:
44
+ # data = json.load(f)
45
+ # # print(data[1])
46
+ # for i in data:
47
+ # output_text = i["gpt_response"]
48
+ # i["Output"] = output_from_text(output_text)["OUTPUT"]
49
+ # i["ERROR"] = output_from_text(output_text)["ERROR"]
50
+ # #remove OUTPUT key
51
+ # # i.pop("OUTPUT")
52
+
53
+ # with open("./answer.json", "w") as f:
54
+ # json.dump(data, f, indent=4)
55
+ # print("Output saved to answer.json")
match_outline/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.19 kB). View file
 
match_outline/eval.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['Rows']
31
+ order = entry['Gold_output']
32
+ order = int(order)
33
+
34
+ total_counts += 1
35
+
36
+ # Calculate per-category accuracy
37
+ if num_objects not in category_accuracies:
38
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
39
+
40
+ category_accuracies[num_objects]['total'] += 1
41
+
42
+ try:
43
+ predicted_order = entry['Output']
44
+ predicted_order = int(predicted_order)
45
+ except:
46
+ continue
47
+
48
+
49
+ # Check if the prediction is correct
50
+ if predicted_order == order:
51
+ correct_counts += 1
52
+ category_accuracies[num_objects]['correct'] += 1
53
+
54
+
55
+
56
+ # Calculate overall accuracy
57
+ overall_accuracy = correct_counts / total_counts * 100
58
+
59
+ # Calculate accuracy for each category
60
+ category_accuracy_percentages = {
61
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
62
+ }
63
+
64
+ # Prepare results for saving
65
+ eval_results = {
66
+ "Overall Accuracy": overall_accuracy,
67
+ "Category-wise Accuracy": category_accuracy_percentages
68
+ }
69
+
70
+ # Save results to eval.json
71
+ with open(args.output, 'w') as eval_file:
72
+ json.dump(eval_results, eval_file, indent=4)
73
+
74
+ print("Evaluation results saved to eval.json.")
match_outline/utils.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+
4
+ def output_from_text(text):
5
+ #extract the number in the last line of text
6
+ try:
7
+ lines = text.strip().split("\n")
8
+ lines = list(filter(None, lines))
9
+ pattern = r'^[^a-zA-Z0-9\s]+$'
10
+ lines = [s for s in lines if not re.fullmatch(pattern, s)]
11
+ answer = -1
12
+ answer = int(re.findall(r"\b\d+\b", lines[-1])[0])
13
+
14
+ if answer != -1:
15
+ return {
16
+ "OUTPUT": answer,
17
+ "ERROR": None
18
+ }
19
+ else:
20
+ return{
21
+ "OUTPUT": None,
22
+ "ERROR": 'Does not give correct format'
23
+ }
24
+ except Exception as e:
25
+ return {
26
+ "OUTPUT": None,
27
+ "ERROR": str(e)
28
+ }
match_shadow/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.19 kB). View file
 
maze_solving/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.39 kB). View file
 
maze_solving/eval.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer_gpt4o.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval_gpt4o.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_rows = entry['Rows']
31
+ num_columns = entry['Columns']
32
+
33
+ total_counts += 1
34
+
35
+ # Calculate per-category accuracy
36
+ # category_key = f"{num_rows}"
37
+ category_key = len(entry['path'])-2
38
+ if category_key not in category_accuracies:
39
+ category_accuracies[category_key] = {'correct': 0, 'total': 0}
40
+
41
+ category_accuracies[category_key]['total'] += 1
42
+
43
+ try:
44
+ predicted_output = entry['Output']
45
+ except:
46
+ continue
47
+
48
+ if predicted_output == entry['path']:
49
+ correct_counts += 1
50
+ category_accuracies[category_key]['correct'] += 1
51
+
52
+ # Calculate overall accuracy
53
+ overall_accuracy = correct_counts / total_counts * 100
54
+
55
+ # Calculate accuracy for each category
56
+ category_accuracy_percentages = {
57
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
58
+ }
59
+
60
+ # Prepare results for saving
61
+ eval_results = {
62
+ "Overall Accuracy": overall_accuracy,
63
+ "Category-wise Accuracy": category_accuracy_percentages
64
+ }
65
+
66
+ # Save results to eval.json
67
+ with open(args.output, 'w') as eval_file:
68
+ json.dump(eval_results, eval_file, indent=4)
69
+
70
+ print(f"Evaluation results saved to {args.output}.")
mirror_image/__pycache__/utils.cpython-314.pyc ADDED
Binary file (1.2 kB). View file
 
mirror_image/eval.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import argparse
3
+ if __name__ == "__main__":
4
+ # Parse command line arguments
5
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
6
+ parser.add_argument(
7
+ '--answer', '-a',
8
+ type=str,
9
+ default='answer.json',
10
+ help='Path to the answer JSON file (default: answer.json)'
11
+ )
12
+ parser.add_argument(
13
+ '--output', '-o',
14
+ type=str,
15
+ default='eval.json',
16
+ help='Path to the output JSON file (default: eval.json)'
17
+ )
18
+ args = parser.parse_args()
19
+ # Assuming your JSON data is stored in a file called 'results.json'
20
+ with open(args.answer, 'r') as f:
21
+ data = json.load(f)
22
+
23
+ # Initialize variables to calculate accuracies
24
+ correct_counts = 0
25
+ total_counts = 0
26
+ category_accuracies = {}
27
+
28
+ # Iterate through the JSON data
29
+ for entry in data:
30
+ num_objects = entry['num_objects']
31
+ water_image = entry['mirror_image']
32
+
33
+ total_counts += 1
34
+
35
+ # Calculate per-category accuracy
36
+ if num_objects not in category_accuracies:
37
+ category_accuracies[num_objects] = {'correct': 0, 'total': 0}
38
+
39
+ category_accuracies[num_objects]['total'] += 1
40
+
41
+ try:
42
+ prediction = entry['Output']
43
+ except:
44
+ continue
45
+ # print(prediction , odd_one)
46
+ # Check if the prediction is correct
47
+ if prediction != None and int(water_image) == int(prediction):
48
+ correct_counts += 1
49
+ category_accuracies[num_objects]['correct'] += 1
50
+
51
+
52
+
53
+ # Calculate overall accuracy
54
+ overall_accuracy = correct_counts / total_counts * 100
55
+
56
+ # Calculate accuracy for each category
57
+ category_accuracy_percentages = {
58
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
59
+ }
60
+
61
+ # Prepare results for saving
62
+ eval_results = {
63
+ "Overall Accuracy": overall_accuracy,
64
+ "Category-wise Accuracy": category_accuracy_percentages
65
+ }
66
+
67
+ # Save results to eval.json
68
+ with open(args.output, 'w') as eval_file:
69
+ json.dump(eval_results, eval_file, indent=4)
70
+
71
+ print("Evaluation results saved to eval.json.")
sort_circles/__pycache__/utils.cpython-314.pyc ADDED
Binary file (2.09 kB). View file
 
sort_lines/__pycache__/utils.cpython-314.pyc ADDED
Binary file (991 Bytes). View file
 
sort_lines/eval.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import argparse
4
+ if __name__ == "__main__":
5
+ # Parse command line arguments
6
+ parser = argparse.ArgumentParser(description="Evaluation script for comparing_size task")
7
+ parser.add_argument(
8
+ '--answer', '-a',
9
+ type=str,
10
+ default='answer_gpt4o.json',
11
+ help='Path to the answer JSON file (default: answer.json)'
12
+ )
13
+ parser.add_argument(
14
+ '--output', '-o',
15
+ type=str,
16
+ default='eval_gpt4o.json',
17
+ help='Path to the output JSON file (default: eval.json)'
18
+ )
19
+ args = parser.parse_args()
20
+ # Assuming your JSON data is stored in a file called 'results.json'
21
+ with open(args.answer, 'r') as f:
22
+ data = json.load(f)
23
+
24
+ # Initialize variables to calculate accuracies
25
+ correct_counts = 0
26
+ total_counts = 0
27
+ category_accuracies = {}
28
+
29
+ # Iterate through the JSON data
30
+ for entry in data:
31
+ num_rows = entry['Lines']
32
+ total_counts += 1
33
+
34
+ # Calculate per-category accuracy
35
+ if num_rows not in category_accuracies:
36
+ category_accuracies[num_rows] = {'correct': 0, 'total': 0}
37
+
38
+ category_accuracies[num_rows]['total'] += 1
39
+
40
+ try:
41
+ predicted_output = entry['Output']
42
+ except:
43
+ continue
44
+
45
+ if predicted_output == entry['Gold_output']:
46
+ correct_counts += 1
47
+ category_accuracies[num_rows]['correct'] += 1
48
+
49
+ # Calculate overall accuracy
50
+ overall_accuracy = correct_counts / total_counts * 100
51
+
52
+ # Calculate accuracy for each category
53
+ category_accuracy_percentages = {
54
+ k: (v['correct'] / v['total'] * 100) for k, v in category_accuracies.items()
55
+ }
56
+
57
+ # Prepare results for saving
58
+ eval_results = {
59
+ "Overall Accuracy": overall_accuracy,
60
+ "Category-wise Accuracy": category_accuracy_percentages
61
+ }
62
+
63
+ # Save results to eval.json
64
+ with open(args.output, 'w') as eval_file:
65
+ json.dump(eval_results, eval_file, indent=4)
66
+
67
+ print(f"Evaluation results saved to {args.output}.")
sort_lines/utils.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def output_from_text(text):
2
+ """
3
+ Parse the text to extract the number of objects and the path.
4
+ Splits the text by commas and removes leading and trailing whitespace from each element.
5
+ """
6
+ try:
7
+ lines = text.strip().split("\n")
8
+ path = [int(item.strip()) for item in lines[-1].split(" ")]
9
+ return {
10
+ "OUTPUT": path,
11
+ "ERROR": None
12
+ }
13
+ except Exception as e:
14
+ return {
15
+ "OUTPUT": None,
16
+ "ERROR": str(e)
17
+ }
18
+
vanishing_objects/utils.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+
4
+ def output_from_text(text):
5
+ #extract the number in the last line of text
6
+ try:
7
+ lines = text.strip().split("\n")
8
+ lines = list(filter(None, lines))
9
+ pattern = r'^[^a-zA-Z0-9\s]+$'
10
+ lines = [s for s in lines if not re.fullmatch(pattern, s)]
11
+ diff = -1
12
+ diff = int(re.findall(r"\b\d+\b", lines[-1])[0])
13
+
14
+ if diff != -1:
15
+ return {
16
+ "OUTPUT": diff,
17
+ "ERROR": None
18
+ }
19
+ else:
20
+ return{
21
+ "OUTPUT": None,
22
+ "ERROR": 'Does not give correct format'
23
+ }
24
+ except Exception as e:
25
+ return {
26
+ "OUTPUT": None,
27
+ "ERROR": str(e)
28
+ }
29
+
30
+ """import json
31
+ import os
32
+
33
+ def output_from_text(output_text):
34
+ try:
35
+
36
+ output_text = output_text.split('\n')
37
+ # print(output_text)
38
+ out_words = output_text[-1].split(' ')
39
+ if len(out_words) != 1:
40
+ return {
41
+ "OUTPUT": None,
42
+ "ERROR": "Output file should have only 1 word"
43
+ }
44
+ else:
45
+ count = out_words[0].split(':')
46
+ if (count[0] == 'COUNT'):
47
+ return {
48
+ "OUTPUT": {
49
+ "vanished": int(count[1])
50
+ },
51
+ "ERROR": None
52
+ }
53
+ else:
54
+ return {
55
+ "OUTPUT": None,
56
+ "ERROR": "Output format is not correct"
57
+ }
58
+ except Exception as e:
59
+ return {
60
+ "OUTPUT": None,
61
+ "ERROR": f"Unexpected error while parsing {str(e)}\n"
62
+ }
63
+
64
+ def gold_to_output(i):
65
+ gold_output = None
66
+ try:
67
+ #get directory of this file
68
+ dir_of_file = os.path.dirname(os.path.realpath(__file__))
69
+ #open the data file
70
+ with open(dir_of_file + "\data.json") as f:
71
+ data = json.load(f)
72
+ row = data[i]
73
+ circles = row['circles']
74
+ triangles = row['triangles']
75
+ squares = row['squares']
76
+ vanished = row['vanished']
77
+ output_prompt = f"CIRCLES:{circles} TRIANGLES:{triangles} SQUARES:{squares} VANISHED:{vanished}"
78
+
79
+ except Exception as e:
80
+ return {
81
+ "OUTPUT": None,
82
+ "ERROR": str(e)
83
+ }
84
+
85
+ return {
86
+ "OUTPUT": output_prompt,
87
+ "ERROR": None
88
+ }"""