-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerate_visual_language_with_gpt.py
More file actions
209 lines (161 loc) · 42.4 KB
/
generate_visual_language_with_gpt.py
File metadata and controls
209 lines (161 loc) · 42.4 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import os
from openai import OpenAI
from dotenv import load_dotenv
import time
# Load environment variables from .env file
load_dotenv(override=True)
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
def generate_response(prompt, model):
while True:
try:
completion = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
return completion.choices[0].message.content
except Exception as e:
print(f"Error {e} occurred while generating response. Retrying in 2 seconds...")
time.sleep(2)
def generate_prompt(mwp,formula=None):
prompt_base = (f'''
You are an expert at converting math story problem into a structured 'visual language'. Your task is to write a visual language expression based on the given math word problem.
**Background information**
You shoud use the following fixed format for each problem:
<operation>(
container1[entity_name: <entity name>, entity_type: <entity type>, entity_quantity: <number of this entity in this container>, container_name: <container name>, container_type: <container type>, attr_name: <attribute name>, attr_type: <attribute type>],
container2[entity_name: <entity name>, entity_type: <entity type>, entity_quantity: <number of this entity in this container>, container_name: <container name>, container_type: <container type>, attr_name: <attribute name>, attr_type: <attribute type>],
result_container[entity_name: <entity name>, entity_type: <entity type>, entity_quantity: <number of this entity in this container>, container_name: <container name>, container_type: <container type>, attr_name: <attribute name>, attr_type: <attribute type>]
)
operation can be ``addition'', ``subtraction'', ``multiplication'', ``division'', ``surplus'', ``area'', ``comparison'', or ``unittrans''.
Each entity has the attributes: entity_name, entity_type, entity_quantity, container_name, container_type, attr_name, attr_type. Name and type are different, for example, a girl named Lucy may be represented by entity_name: Lucy, entity_type: girl. The attributes container_name, container_type, attr_name and attr_type are optional and may vary according to different interpretations, only use them if you think they are necessary to clarify the entity.
In the math word problem description ``Jake picked up three apples in the morning...'' the container1 could be specified as entity_name: apple, entity_type: apple, entity_quantity: 3, container_name: Jake, container_type: boy, attr_name: morning, attr_type: morning.
**Examples**
We first provide you several example, please understand the logic clearly:
1. Question: Marin has nine apples and Donald has two apples. How many apples do Marin and Donald have together?
Visual language: addition(container1[entity_name: apple, entity_type: apple, entity_quantity:9 , container_name: Marin, container_type: girl, attr_name: , attr_type: ],container2[entity_name: apple, entity_type: apple, entity_quantity: 2, container_name: Donald, container_type: boy, attr_name: , attr_type: ], result_container[entity_name:apple,entity_type:apple,entity_quantity:11 , container_name:Marin and Donald, container_type:, attr_name:, attr_type:])
Note: Here addition describe the computation relationship between container1 and container2. We choose the entity as the thing corresponding to quantity, so the quantity is describing that entity. "entity_type" represent entity's visual representation name while "entity_name" is its apparent name. Like a boy has name Bob, so "entity_name" is Bob, "entity_type" is boy because we visualize he as a boy. container_name and container_type represent an attribute that you think is necessary in this question and we will make this attribute as the container of this entity to show a ownership relation, only add it if you think it do not cause confusion. If all entity share same container, please only give "container_name" and "container_type" value to result_container and leave other container blank. Only give value to attr_type, attr_name if you found "container_name" and "container_type" is not enough so we provide one more attribute to identify this entity. The result_container describe the result of this computation, their entity_name usually is the same as container1 and container2, their entity_quantity is the computation result, their container_name and container_type describe the container of the final result.
2. Question: If Carl has a total of 89 stamps and Kevin has 57, how many more stamps does Carl have more than Kevin?
Visual language: subtraction(container1[entity_name: stamp, entity_type: stamp, entity_quantity: 89, container_name: Carl, container_type: boy, attr_name:, attr_type:], container2[entity_name: stamp, entity_type: stamp, entity_quantity: 57, container_name: Kevin, container_type: boy, attr_name:, attr_type:],result_container[entity_name:stamp,entity_type:stamp,entity_quantity:32 , container_name:Carl have more, container_type: more, attr_name:, attr_type:])
Note: Here subtraction is another relationship. The result_container has container_name: Carl have more, and container_type is more.
3. Question: There are 10 books on a shelf. 3 of them are history books, 5 of them are geography books and the rest are math books. How many math books are there on the shelf?
Visual language: subtraction(subtraction(container1[entity_name: total books, entity_type: book, entity_quantity: 10, container_name: shelf, container_type: shelf, attr_name:, attr_type:], container2[entity_name: history books, entity_type: book, entity_quantity: 3, container_name: history books, container_type: history, attr_name:, attr_type:], result_container[entity_name: minus history books, entity_type: book, entity_quantity: 7, container_name: , container_type:, attr_name:, attr_type:]), container2[entity_name: geography books, entity_type: book, entity_quantity: 5, container_name: geography books, container_type: geography, attr_name:, attr_type:], result_container[entity_name:math books, entity_type: book, entity_quantity: 2,container_name:math books, container_type:math, attr_name:,attr_type:])
Note: here is an example of continuous subtraction, we should try to use less relationship like here we only use multiple subtractions instead of using subtraction and addition, notice each single computation has one result_container.
4. Question: For the fifth grade play, the chairs have been put into 27 rows with 16 chairs in each row. How many chairs have been put out for the play?
Visual language: multiplication(container1[entity_name: chair, entity_type: chair, entity_quantity: 16, container_name: row, container_type: row, attr_name:, attr_type:], container2[entity_name: multiplier, entity_type: multiplier, entity_quantity: 27, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name:chair,entity_type:chair,entity_quantity:432 , container_name:, container_type:, attr_name:, attr_type:])
Note: Here multiplication is another relationship. And row/column is necessary in visual representation so we put it in container_name and container_type
5. Question: Lexie's younger brother helped pick up all the paper clips in Lexie's room. He was able to collect 21 paper clips. If he wants to distribute the paper clips in 3 boxes, how many paper clips will each box contain?
Visual language: division(container1[entity_name: paper clip, entity_type: paper-clip, entity_quantity: 21, container_name:, container_type:, attr_name:, attr_type:], container2[entity_name: box, entity_type: box, entity_quantity: 3, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: paper clip per box, entity_type: paper clip per box, entity_quantity: 7, container_name:, container_type:, attr_name:, attr_type:])
Note: here the divider is the box, so the result_container has container paper clips per box. If the question is about fixing the number of paper clip per box and asking how many boxes, then the result_container should have container as box.
6. Question: There were 36 dogs and 29 cats in a pet center. After 20 of the dogs were adopted by people, the pet center collected another 12 cats. How many pets were there in the pet center in the end?
Visual language: addition(subtraction(addition(container1[entity_name: dog, entity_type: dog, entity_quantity: 36, container_name:, container_type:, attr_name:, attr_type:],container2[entity_name: cat, entity_type: cat, entity_quantity: 29, container_name:, container_type:, attr_name:, attr_type:],
result_container[entity_name:animal,entity_type:animal,entity_quantity:65,container_name:,container_type:,attr_name:,attr_type:]),container2[entity_name: dog, entity_type: dog, entity_quantity: 20, container_name: adopt, container_type: adopt, attr_name:, attr_type:],result_container[entity_name:animal,entity_type:animal,entity_quantity:45,container_name:,container_type:,attr_name:,attr_type:]),container2[entity_name: cat, entity_type: cat, entity_quantity: 12, container_name: collect, container_type: collect, attr_name:, attr_type:],result_container[entity_name:animal,entity_type:animal,entity_quantity:57,container_name:pet center,container_type:pet-center,attr_name:,attr_type:])
Note: This example show we can nesting relationship to express multiple relationships. We write computation in time series order, and as pet center represent the total results, we only put it as the container of the last result_container.
7. Question: Mrs. Santiago has 58 red roses. Mrs. Garrett has 24. What's the difference of the number of Mrs. Santiago's red roses and Mrs. Garrett's red roses?
Visual language: subtraction(container1[entity_name: red rose, entity_type: red-rose, entity_quantity: 58, container_name:Mrs. Santiago, container_type:woman, attr_name:, attr_type:],container2[entity_name: red rose, entity_type: red-rose, entity_quantity: 24, container_name:Mrs. Garrett, container_type:woman, attr_name:, attr_type:],result_container[entity_name: red rose, entity_type: red-rose, entity_quantity: 34, container_name:difference, container_type:difference, attr_name:, attr_type:])
Note: For those difference problem, we still use subtraction relationship to express it.
8. Question: An airline has 41 pieces of luggage to put away. If each luggage compartment will hold 5 pieces of luggage, how many will be in the compartment that isn't full?
Visual language: surplus(container1[entity_name: luggage, entity_type: luggage, entity_quantity: 41, container_name:airline, container_type:airline, attr_name:, attr_type:],container2[entity_name: luggage, entity_type: luggage, entity_quantity: 5, container_name:compartment, container_type:compartment, attr_name:, attr_type:],result_container[entity_name: luggage,entity_type: luggage, entity_quantity: 1,container_name: compartment,container_type: compartment,attr_name:,attr_type:])
Note: Here surplus is another relationship, we compute the surplus of container1 divided by container2.
9. Question: If you have 1 ten dollar bill, 1 quarter and 1 nickel, how much money do you have?
Visual language: addition(addition(unittrans(container1[entity_name: ten dollar bill, entity_type: ten-dollar-bill, entity_quantity: 1, container_name:, container_type:, attr_name:, attr_type:],container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 10, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type: dollar, entity_quantity:10, container_name:, container_type:,attr_name:,attr_type:]),unittrans(container1[entity_name: quarter, entity_type: quarter, entity_quantity: 1, container_name:, container_type:, attr_name:, attr_type:],container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.25, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type:dollar,entity_quantity:0.25,container_name:,container_type:,attr_name:,attr_type:]),result_container[entity_name: dollar, entity_type:dollar,entity_quantity:10.25,container_name:,container_type:,attr_name:,attr_type:]),unittrans(container1[entity_name: nickel, entity_type: nickel, entity_quantity: 1, container_name:, container_type:, attr_name:, attr_type:],container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.05, container_name:, container_type:, attr_name:, attr_type:],result_container[entity_name: dollar, entity_type:dollar,entity_quantity:0.05,container_name:,container_type:,attr_name:,attr_type:]),result_container[entity_name: dollar, entity_type:dollar,entity_quantity:10.30,container_name:you,container_type:human,attr_name:,attr_type:])
Note: Here unittrans means unit transformation, it is another relationship between entity and its unittrans_value. Like in this example, a ten-dollar-bill have value of 10 dollars, so the name of container2 is dollar, the type is unittrans_value, and quantity is 10.
9. Question: Rug A is 8 feet by 4 feet, and Rug B is 5 feet by 7 feet. Which rug should Mrs. Hilt buy if she wants the rug with the biggest area?
Visual language: comparison(area(container1[entity_name: feet, entity_type: measure, entity_quantity: 8, container_name:length, container_type:length, attr_name:, attr_type:],container2[entity_name:feet, entity_type: measure, entity_quantity: 4, container_name:width, container_type:width, attr_name:, attr_type:], result_container[entity_name:area,entity_type:area,entity_quantity:32 , container_name:Rug A, container_type:rug, attr_name:, attr_type:]),area(container1[entity_name: feet, entity_type: measure, entity_quantity: 5, container_name:length, container_type:length, attr_name:, attr_type:],container2[entity_name:feet, entity_type: measure, entity_quantity: 7, container_name:width, container_type:width, attr_name:, attr_type:],result_container[entity_name:area,entity_type:area,entity_quantity:35 , container_name:Rug B, container_type:rug, attr_name:, attr_type:]),result_container[entity_name:Rug B,entity_type:rug,entity_quantity: , container_name:, container_type:, attr_name:, attr_type:])
Note: Here comparison and area are two new relationships. "comparison" comparing the quantity of two entity, the two entity can be the result of other computation like in this example, the name of result_container indicate the comparison result.
"area" is computing the area value by its two input entities, the container1 represent length while container2 represents width as indicated by container, name is unit. The container_name and container_type of result_container indicate the item this area belong to.
10. Question: Ellen has six more balls than Marin. Marin has nine balls. How many balls does Ellen have?
Visual language: addition(container1[entity_name: ball, entity_type: ball, entity_quantity: 9, container_name: Marin, container_type: girl, attr_name:, attr_type:], container2[entity_name: ball, entity_type: ball, entity_quantity: 6, container_name:, container_type:, attr_name:, attr_type:],result_container[entity_name:ball,entity_type:ball,entity_quantity:15,container_name:Ellen,container_type:boy,attr_name:,attr_type:])
Note: In this case, the added results are the balls Ellen has, so we do not add Ellen in the container of container2 because it will cause the confusion that Ellen own 6 balls.
11. Question: Isha's pencil is 22 inches long. If she sharpens two inches off on Monday and two inches on Tuesday, how long will her pencil be then?
Visual language: subtraction(subtraction(container1[entity_name: inch, entity_type: measure, entity_quantity: 22, container_name: pencil, container_type: pencil, attr_name:, attr_type:], container2[entity_name: inch, entity_type: measure, entity_quantity: 2, container_name: Monday, container_type: calendar, attr_name:, attr_type:],result_container[entity_name:inch,entity_type:measure,entity_quantity:20,container_name:pencil,container_type:pencil,attr_name:,attr_type:]), container2[entity_name: inch, entity_type: measure, entity_quantity: 2, container_name: Tuesday, container_type: calendar, attr_name:, attr_type:],result_container[entity_name:inch,entity_type:measure,entity_quantity:18,container_name:pencil,container_type:pencil,attr_name:,attr_type:])
Note: In this case, if the attr is a name of a day of the week(Monday,Sunday, yesterday, tomorrow...) or a year or a month, we can use calendar as type to visualize it. Similar if its a time, we can use clock as type. And for inch or other length, we can use measure as type. The last result_container should use the overall container of this item, like pencil here.
12. Question: The Hawks scored three touchdowns worth 7 points each. How many points do they have?
Visual language: multiplication(container1[entity_name: point, entity_type: point, entity_quantity: 7, container_name: touchdown, container_type: touchdown, attr_name:, attr_type:], container2[entity_name: multiplier, entity_type: multiplier, entity_quantity: 3, container_name:, container_type:, attr_name:, attr_type:],result_container[entity_name:point,entity_type:point,entity_quantity:21,container_name:Hawks,container_type:hawks,attr_name:,attr_type:])
Note: Here the entity_name is point instead of touchdown because the quantity 7 is corresponding to point not touchdown, and we put touchdown in container as it owns these points. You can imagine multiplication as we repeat one box multiple times, here the box is touchdown and points are item inside each box. And finally Hawks is the container of the result_container as it owns all the box.
13. Question: A game spinner has 5 equal parts. Two parts are blue and three parts are purple. Which color would you most likely spin?
Visual_language: comparison(container1[entity_name: blue part, entity_type: blue-part, entity_quantity: 2, container_name: , container_type: , attr_name:, attr_type:], container2[entity_name: purple part, entity_type: purple-part, entity_quantity: 3, container_name: , container_type: , attr_name:, attr_type:],result_container[entity_name:purple part,entity_type:purple-part,entity_quantity:,container_name:,container_type:,attr_name:,attr_type:])
Note: If the item is some color part, you can refer it as color-part, like red-part.
14. Question: There are 10 books on a shelf. 3 of them are history books, 5 of them are geography books and the rest are math books. How many math books are there on the shelf?
Visual language: subtraction(subtraction(container1[entity_name: total books, entity_type: book, entity_quantity: 10, container_name: shelf, container_type: shelf, attr_name:, attr_type:], container2[entity_name: history books, entity_type: book, entity_quantity: 3, container_name: history books, container_type: history-book, attr_name:, attr_type:], result_container[entity_name: minus history books, entity_type: book, entity_quantity: 7, container_name: , container_type:, attr_name:, attr_type:]), container2[entity_name: geography books, entity_type: book, entity_quantity: 5, container_name: geography books, container_type: geography-book, attr_name:, attr_type:], result_container[entity_name:math books, entity_type: book, entity_quantity: 2,container_name:math books, container_type:math-book, attr_name:,attr_type:])
Note: When there are continuous subtractions, please always use subtraction relationship. In general try to use fewer kinds of relationship to represent the question. And here, the entity_name and entity_type should distinguish history book and geography book.
15. Question: Mrs. Hilt has two pennies, two dimes, and two nickels. Jacob has four pennies, one nickel, and one dime. Who has more money?
Visual language: comparison(addition(addition(unittrans(container1[entity_name: penny, entity_type: penny, entity_quantity: 2, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.01, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.02, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ]), unittrans(container1[entity_name: dime, entity_type: dime, entity_quantity: 2, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.1, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.2, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ]), result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.22, container_name:Mrs.Hilt , container_type:woman , attr_name: , attr_type: ]), unittrans(container1[entity_name: nickel, entity_type: nickel, entity_quantity: 2, container_name:Mrs.Hilt , container_type:woman , attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.05, container_name:Mrs.Hilt , container_type:woman , attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.1, container_name:Mrs.Hilt , container_type:woman , attr_name: , attr_type: ]), result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.32, container_name: Mrs.Hilt, container_type: woman, attr_name: , attr_type: ]), addition(addition(unittrans(container1[entity_name: penny, entity_type: penny, entity_quantity: 4, container_name:Jacob , container_type:man , attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.01, container_name:Jacob , container_type:man , attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.04, container_name:Jacob , container_type:man , attr_name: , attr_type: ]), unittrans(container1[entity_name: dime, entity_type: dime, entity_quantity: 1, container_name:Jacob , container_type:man , attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.1, container_name:Jacob , container_type:man , attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.1, container_name:Jacob , container_type:man , attr_name: , attr_type: ]), result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.14, container_name:Jacob , container_type:man , attr_name: , attr_type: ]), unittrans(container1[entity_name: nickel, entity_type: nickel, entity_quantity: 1, container_name:Jacob , container_type:man , attr_name: , attr_type: ], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.05, container_name:Jacob , container_type:man , attr_name: , attr_type: ], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.05, container_name:Jacob , container_type:man , attr_name: , attr_type: ]), result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.19, container_name: Jacob, container_type: man, attr_name: , attr_type: ]), result_container[entity_name: more, entity_type: more, entity_quantity: , container_name: more, container_type: more, attr_name: , attr_type: ])
16. Question: Mrs. Hilt bought a yoyo for 24 cents and a whistle for 14 cents. How much did she spend in all for the two toys?
Visual language: addition(container1[entity_name: cent, entity_type: cent, entity_quantity: 24, container_name: yoyo, container_type: yoyo, attr_name:, attr_type:], container2[entity_name: cent, entity_type: cent, entity_quantity: 14, container_name: whistle, container_type: whistle, attr_name:, attr_type:], result_container[entity_name: cent, entity_type: cent, entity_quantity: 38, container_name: Mrs. Hilt, container_type: woman, attr_name:, attr_type:])
17. Question: Mrs. Hilt spent 25 cents on one caramel apple and 15 cents on one ice cream cone. How much more did the apple cost?
Visual language: subtraction(container1[entity_name: cent, entity_type: cent, entity_quantity: 25, container_name: caramel apple, container_type: caramel-apple, attr_name:, attr_type:], container2[entity_name: cent, entity_type: cent, entity_quantity: 15, container_name: ice cream cone, container_type: ice-cream-cone, attr_name:, attr_type:], result_container[entity_name: cent, entity_type: cent, entity_quantity: 10, container_name: Mrs. Hilt, container_type: woman, attr_name:, attr_type:])
18. Question: Roden went to a pet shop. He bought 15 gold fish and 7 blue fish. How many fish did he buy?
Visual language: addition(container1[entity_name: gold fish, entity_type: gold-fish, entity_quantity: 15, container_name: Roden, container_type: boy, attr_name:, attr_type:], container2[entity_name: blue fish, entity_type: blue-fish, entity_quantity: 7, container_name: Roden, container_type: boy, attr_name:, attr_type:], result_container[entity_name: fish, entity_type: fish, entity_quantity: 22, container_name: Roden, container_type: boy, attr_name:, attr_type:])
Note: we need to distinguish different fish here because their visual are different
19. Question: Tessa has 4 apples. Anita gave her 5 more. She needs 10 apples to make a pie. Does she have enough to make a pie?
Visual language: comparison(addition(container1[entity_name: apple, entity_type: apple, entity_quantity: 4, container_name: Tessa, container_type: girl, attr_name:, attr_type:],container2[entity_name: apple, entity_type: apple, entity_quantity: 5, container_name: Anita, container_type: girl, attr_name:, attr_type:], result_container[entity_name: apple, entity_type: apple, entity_quantity: 9, container_name: Tessa, container_type: girl, attr_name:, attr_type:]),container2[entity_name: apple, entity_type: apple, entity_quantity: 10, container_name: pie, container_type: pie, attr_name:, attr_type:])
20. Question: Mrs. Snyder made 86 heart cookies. She made 36 red cookies and the rest are pink. How many pink cookies did she make?
Visual language: subtraction(container1[entity_name: total cookies, entity_type: heart-cookie, entity_quantity: 86, container_name: Mrs. Snyder, container_type: woman, attr_name:, attr_type:], container2[entity_name: red cookies, entity_type: red-heart-cookie, entity_quantity: 36, container_name: Mrs. Snyder, container_type: woman, attr_name:, attr_type:], result_container[entity_name: minus red cookies, entity_type: pink-heart-cookie, entity_quantity: 50, container_name: Mrs. Snyder, container_type: woman, attr_name:, attr_type:])
Note: here we need to use heart-cookie because its visual is different with normal cookie
21. Question: Sarah had some trucks. She gave 13 to Jeff, and now she has 38 trucks left. How many trucks did Sarah have to start with?
Visual language: addition(container1[entity_name: trucks, entity_type: truck, entity_quantity: 13, container_name: Jeff, container_type: boy, attr_name:, attr_type:], container2[entity_name: trucks, entity_type: truck, entity_quantity: 38, container_name: left, container_type: left, attr_name:, attr_type:], result_container[entity_name: trucks, entity_type: truck, entity_quantity: 51, container_name: Sarah, container_type: girl, attr_name:, attr_type:])
Note: can emphasize 'left' for this type of question.
22. Question: Mrs. Hilt bought an ice cream cone for 99 cents. How much would 2 ice cream cones cost?
Visual language: addition(container1[entity_name: cent, entity_type: cent, entity_quantity: 99, container_name:ice cream cone, container_type:ice-cream-cone, attr_name:, attr_type:],container2[entity_name: cent, entity_type: cent, entity_quantity: 99, container_name:ice cream cone, container_type:ice-cream-cone, attr_name:, attr_type:],result_container[entity_name: cent, entity_type: cent, entity_quantity: 198, container_name:Mrs. Hilt, container_type:woman, attr_name:, attr_type:])
23. Question: Mrs. Hilt bought 6 hot dogs. Each hot dog cost 50 cents. How much money did she pay for all of the hot dogs?
Visual language: multiplication(container1[entity_name: cent, entity_type: cent, entity_quantity: 50, container_name:hot dog, container_type: hot-dog, attr_name:, attr_type:], container2[entity_name: multiplier, entity_type: multiplier, entity_quantity: 6, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: cent, entity_type: cent, entity_quantity: 300, container_name: Mrs. Hilt, container_type: woman, attr_name:, attr_type:])
24. Question: Mrs. Hilt bought 3 pizzas for $8 each. What was the total amount she paid for the three pizzas?
Visual language: multiplication(container1[entity_name: dollar, entity_type: dollar, entity_quantity: 8, container_name: pizza, container_type: pizza, attr_name:, attr_type:], container2[entity_name: multiplier, entity_type: multiplier, entity_quantity: 3, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: total amount, entity_type: dollar, entity_quantity: 24, container_name: Mrs. Hilt, container_type: woman, attr_name:, attr_type:])
25. Question: John's birthday is January 20th. His sister's birthday comes 14 days later. When is his sister's birthday?
Visual language: subtraction(addition(container1[entity_name: day, entity_type: calendar, entity_quantity: 20, container_name: John's birthday, container_type: boy, attr_name:, attr_type:], container2[entity_name: day, entity_type: calendar, entity_quantity: 14, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name:day, entity_type: calendar, entity_quantity: 34, container_name:sister's birthday, container_type:girl, attr_name:, attr_type:]),container2[entity_name: day, entity_type: calendar, entity_quantity: 31, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name:day, entity_type: calendar, entity_quantity: 3, container_name:sister's birthday, container_type:girl, attr_name:, attr_type:])
26. Question: A quarter equals $0.25. How many quarters equal $2.25?
Visual language: division(container1[entity_name: dollar, entity_type: dollar, entity_quantity: 2.25, container_name:, container_type:, attr_name:, attr_type:], container2[entity_name: dollar, entity_type: dollar, entity_quantity: 0.25, container_name:quarter, container_type:quarter, attr_name:, attr_type:], result_container[entity_name: quarter, entity_type: quarter, entity_quantity: 9, container_name:, container_type:, attr_name:, attr_type:])
27. Question: Karen wants to buy a pen that costs 75 cents. She has 2 quarters and 3 dimes. Does she have enough money?
Visual language: comparison(addition(unittrans(container1[entity_name: dime, entity_type: dime, entity_quantity: 3, container_name:, container_type:, attr_name:, attr_type:], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.10, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.30, container_name:, container_type:, attr_name:, attr_type:]),unittrans(container1[entity_name: quarter, entity_type: quarter, entity_quantity: 2, container_name:, container_type:, attr_name:, attr_type:], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.25, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.50, container_name:, container_type:, attr_name:, attr_type:]),result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.30, container_name:Karen, container_type:boy, attr_name:, attr_type:]),unittrans(container1[entity_name: cent, entity_type: cent, entity_quantity: 75, container_name:pen, container_type:pen, attr_name:, attr_type:], container2[entity_name: dollar, entity_type: unittrans_value, entity_quantity: 0.01, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 0.75, container_name:, container_type:, attr_name:, attr_type:]),result_container[entity_name: yes, entity_type: yes, entity_quantity: , container_name: , container_type: , attr_name:, attr_type:])
28. Question: It is Buddy's first day at a new school and he is feeling very nervous. His day begins with some bacon and egg prepared by his mother. After eating and preparing, Buddy headed out to catch the school bus from the nearest bus stop. Including Buddy, there were 39 students that got on the bus during the first stop. If 29 more students got on the bus at the second stop, how many students are riding the bus?
Visual language: addition(container1[entity_name: student, entity_type: student, entity_quantity: 39, container_name: bus stop 1, container_type: bus-stop, attr_name:, attr_type:], container2[entity_name: student, entity_type: student, entity_quantity: 29, container_name: bus stop 2, container_type: bus-stop, attr_name:, attr_type:], result_container[entity_name: total students, entity_type: student, entity_quantity: 68, container_name: bus, container_type: bus, attr_name:, attr_type:])
29. Question: During recess, Buddy went to the cafeteria where he met other students from different grades. If he met 14 second grade students, 10 fourth grade students and 16 fifth grade students, how many students did Buddy meet during recess?
Visual language: addition(addition(container1[entity_name: student, entity_type: student, entity_quantity: 14, container_name: second grade, container_type: second-grade, attr_name:, attr_type:], container2[entity_name: student, entity_type: student, entity_quantity: 10, container_name: fourth grade, container_type: fourth-grade, attr_name:, attr_type:], result_container[entity_name: total students, entity_type: student, entity_quantity: 24, container_name: , container_type:, attr_name:, attr_type:]), container2[entity_name: student, entity_type: student, entity_quantity: 16, container_name: fifth grade, container_type: fifth-grade, attr_name:, attr_type:], result_container[entity_name: more students, entity_type: student, entity_quantity: 40, container_name: Buddy met more, container_type: more, attr_name:, attr_type:])
30. Question: At the top of the Empire State Building, he saw the Madison Square Garden so he decided to go there as well. It took him 676 steps to get down the building and 315 steps from the building to Madison Square Garden. How many steps did he take to get to Madison Square?
Visual language: addition(container1[entity_name: step, entity_type: step, entity_quantity: 676, container_name: Empire State Building, container_type: building, attr_name:, attr_type:], container2[entity_name: step, entity_type: step, entity_quantity: 315, container_name: Madison Square Garden, container_type: garden, attr_name:, attr_type:], result_container[entity_name: step, entity_type: step, entity_quantity: 991, container_name: steps to Madison Square Garden, container_type: destination, attr_name:, attr_type:])
31. Question: To add support on the house's connections, he decided to tie the wood joints with rope. He needs 185 feet of rope. If he has 46 feet of rope with him and at the moment he only needed 57 feet, how many feet of rope did his friends give to him?
Visual language: subtraction(container1[entity_name: required rope, entity_type: rope, entity_quantity: 185, container_name: total need, container_type: total-need, attr_name:, attr_type:], addition(container1[entity_name: current rope, entity_type: rope, entity_quantity: 46, container_name:have , container_type: have, attr_name:, attr_type:], container2[entity_name: needed rope, entity_type: rope, entity_quantity: 57, container_name:current need , container_type:current-need , attr_name:, attr_type:], result_container[entity_name: total rope used, entity_type: rope, entity_quantity: 103, container_name: , container_type:, attr_name:, attr_type:]), result_container[entity_name: rope given by friends, entity_type: rope, entity_quantity: 82, container_name: friends, container_type: friend, attr_name:, attr_type:])
Note: please make sure the container name is representative of the current state like in this example, make it distinguishable. Also if the formula is given, make sure the visual langauge is align with the formula, do not skip steps.
32. Question: Another material that he needs is rope. If he already has 6 feet of rope and he needs additional ropes having 5 times the length of what he already have, how long should be the additional rope?
Visual language: multiplication(container1[entity_name: rope, entity_type: measure, entity_quantity: 6, container_name: already have, container_type: rope, attr_name:, attr_type:], container2[entity_name: multiplier, entity_type: multiplier, entity_quantity: 5, container_name:, container_type:, attr_name:, attr_type:], result_container[entity_name: additional rope, entity_type: measure, entity_quantity: 30, container_name: additional rope, container_type: rope, attr_name:, attr_type:])
Note: for this type of 'x times of' question, you should use multiplication operation, and the container2 should be have name and type == multiplier.
33. Question: If Lizzie's group is composed of 54 people and they have 17 more members than the other group, how many people are working together to clean the city?
Visual language: addition(subtraction(container1[entity_name: people, entity_type: people, entity_quantity: 54, container_name: Lizzie's group, container_type: group, attr_name:, attr_type:], container2[entity_name: people, entity_type: people, entity_quantity: 17, container_name: other group, container_type: group, attr_name:, attr_type:], result_container[entity_name: people, entity_type: people, entity_quantity: 37, container_name:, container_type:, attr_name:, attr_type:]), container2[entity_name: people, entity_type: people, entity_quantity: 54, container_name: Lizzie's group, container_type: group, attr_name:, attr_type:], result_container[entity_name: total people, entity_type: people, entity_quantity: 91, container_name: working together, container_type: clean city, attr_name:, attr_type:])
Note: the name and type always corresponding to the questioned item, like here we should use people not group or member, and container is the thing distinguish the belonging of items.
34. Question: Katie spent a total $350.00 on her whole stay in the island. If she spent $125.00 on food and $135.00 on hotel rooms, how much did she spend on buying other stuff?
Visual language: subtraction(container1[entity_name: dollar, entity_type: dollar, entity_quantity: 350, container_name: Katie, container_type: girl, attr_name:, attr_type:], addition(container1[entity_name: dollar, entity_type: dollar, entity_quantity: 125, container_name: food, container_type: food, attr_name:, attr_type:], container2[entity_name: dollar, entity_type: dollar, entity_quantity: 135, container_name: hotel rooms, container_type: hotel, attr_name:, attr_type:], result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 260, container_name:total spent on food and hotel, container_type:total, attr_name:, attr_type:]), result_container[entity_name: dollar, entity_type: dollar, entity_quantity: 90, container_name: spent on other stuff, container_type: other-stuff, attr_name:, attr_type:])
Note: here is another example, the name and type always point to same thing.
35. Question: After the mountain country, she went to the famous beach on the continent. There, she collected 291 seashells of different colors. If she has 76 red shells and 49 green shells, how many shells are not red or green?
Visual_language: subtraction(container1[entity_name: shell, entity_type: shell, entity_quantity: 291, container_name: total, container_type: total, attr_name:, attr_type:], addition(container1[entity_name: red shell, entity_type: red-shell, entity_quantity: 76, container_name: red shell, container_type: red-shell, attr_name:, attr_type:], container2[entity_name: green shell, entity_type: green-shell, entity_quantity: 49, container_name: green shell, container_type: green-shell, attr_name:, attr_type:], result_container[entity_name: total red and green shells, entity_type: shell, entity_quantity: 125, container_name: beach, container_type: beach, attr_name:, attr_type:]), result_container[entity_name: shells not red or green, entity_type: shell, entity_quantity: 166, container_name: beach, container_type: beach, attr_name:, attr_type:])
Note: its ok if we use the container name the same as name if the name itself is distinguishable.''')
if formula:
prompt_instruct = (f'''**Task**
Good, now try to understand the above requirement step by step. I also provide you with the formula of this question, your visual_language should adapt to this formula, for example, if the formula is multiple addition instead of multiplication, you should use multiple addition.
Once you are ready, you can do the task of converting, you can write down your thinking procedure but please make sure to give me the final visual language of the following question in this format in the end: visual_language:<the visual language result>
Question: {mwp}
Formula: {formula}''')
else:
prompt_instruct = (f'''**Task**
Good, now try to understand the above requirement step by step.
Once you are ready, you can do the task of converting, you can write down your thinking procedure but please make sure to give me the final visual language of the following question in this format in the end: visual_language:<the visual language result>
Question: {mwp}''')
prompt = prompt_base + "\n\n" + prompt_instruct
return prompt
def generate_visual_language(mwp, formula, model='o3-mini'):
visual_language = generate_response(generate_prompt(mwp,formula),model=model)
return visual_language
# main function
if __name__ == "__main__":
mwp = "Janet has nine oranges, and Sharon has seven oranges. How many oranges do Janet and Sharon have together?"
formula = "9 + 7 = 16" # optional
visual_language = generate_visual_language(mwp, formula)
# save visual_language into a txt file
current_dir = os.path.dirname(os.path.abspath(__file__))
output_dir = os.path.join(current_dir, 'output_visual_language')
os.makedirs(output_dir, exist_ok=True)
output_path = os.path.join(output_dir, 'visual_language.txt')
with open(output_path, 'w') as f:
f.write(visual_language)
print(visual_language)