srush HF staff commited on
Commit
e0f8e8c
1 Parent(s): 9c56b3e

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +45 -0
  2. pal.pmpt.tpl +148 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf).
2
+
3
+ import minichain
4
+
5
+ # PAL Prompt
6
+
7
+ class PalPrompt(minichain.TemplatePrompt):
8
+ template_file = "pal.pmpt.tpl"
9
+
10
+ # Prompt to run and print python code.
11
+
12
+ class PyPrompt(minichain.Prompt):
13
+ def prompt(self, inp):
14
+ return inp + "\nprint(solution())"
15
+
16
+ def parse(self, response, inp):
17
+ return int(response)
18
+
19
+ # Chain the prompts.
20
+
21
+ with minichain.start_chain("pal") as backend:
22
+ question = "Melanie is a door-to-door saleswoman. She sold a third of her ' \
23
+ 'vacuum cleaners at the green house, 2 more to the red house, and half of ' \
24
+ 'what was left at the orange house. If Melanie has 5 vacuum cleaners left, ' \
25
+ 'how many did she start with?'"
26
+ prompt = PalPrompt(backend.OpenAI()).chain(PyPrompt(backend.Python()))
27
+ result = prompt({"question": question})
28
+ print(result)
29
+
30
+ # View prompt examples.
31
+
32
+ # + tags=["hide_inp"]
33
+ PalPrompt().show(
34
+ {"question": "Joe has 10 cars and Bobby has 12. How many do they have together?"},
35
+ "def solution():\n\treturn 10 + 12",
36
+ )
37
+ # -
38
+
39
+ # + tags=["hide_inp"]
40
+ PyPrompt().show("def solution():\n\treturn 10 + 12", "22")
41
+ # -
42
+
43
+ # View the log.
44
+
45
+ minichain.show_log("pal.log")
pal.pmpt.tpl ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?
2
+
3
+ # solution in Python:
4
+
5
+
6
+ def solution():
7
+ """Olivia has $23. She bought five bagels for $3 each. How much money does she have left?"""
8
+ money_initial = 23
9
+ bagels = 5
10
+ bagel_cost = 3
11
+ money_spent = bagels * bagel_cost
12
+ money_left = money_initial - money_spent
13
+ result = money_left
14
+ return result
15
+
16
+
17
+
18
+
19
+
20
+ Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?
21
+
22
+ # solution in Python:
23
+
24
+
25
+ def solution():
26
+ """Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?"""
27
+ golf_balls_initial = 58
28
+ golf_balls_lost_tuesday = 23
29
+ golf_balls_lost_wednesday = 2
30
+ golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday
31
+ result = golf_balls_left
32
+ return result
33
+
34
+
35
+
36
+
37
+
38
+ Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?
39
+
40
+ # solution in Python:
41
+
42
+
43
+ def solution():
44
+ """There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?"""
45
+ computers_initial = 9
46
+ computers_per_day = 5
47
+ num_days = 4 # 4 days between monday and thursday
48
+ computers_added = computers_per_day * num_days
49
+ computers_total = computers_initial + computers_added
50
+ result = computers_total
51
+ return result
52
+
53
+
54
+
55
+
56
+
57
+ Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?
58
+
59
+ # solution in Python:
60
+
61
+
62
+ def solution():
63
+ """Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?"""
64
+ toys_initial = 5
65
+ mom_toys = 2
66
+ dad_toys = 2
67
+ total_received = mom_toys + dad_toys
68
+ total_toys = toys_initial + total_received
69
+ result = total_toys
70
+ return result
71
+
72
+
73
+
74
+
75
+
76
+ Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?
77
+
78
+ # solution in Python:
79
+
80
+
81
+ def solution():
82
+ """Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?"""
83
+ jason_lollipops_initial = 20
84
+ jason_lollipops_after = 12
85
+ denny_lollipops = jason_lollipops_initial - jason_lollipops_after
86
+ result = denny_lollipops
87
+ return result
88
+
89
+
90
+
91
+
92
+
93
+ Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?
94
+
95
+ # solution in Python:
96
+
97
+
98
+ def solution():
99
+ """Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?"""
100
+ leah_chocolates = 32
101
+ sister_chocolates = 42
102
+ total_chocolates = leah_chocolates + sister_chocolates
103
+ chocolates_eaten = 35
104
+ chocolates_left = total_chocolates - chocolates_eaten
105
+ result = chocolates_left
106
+ return result
107
+
108
+
109
+
110
+
111
+
112
+ Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?
113
+
114
+ # solution in Python:
115
+
116
+
117
+ def solution():
118
+ """If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?"""
119
+ cars_initial = 3
120
+ cars_arrived = 2
121
+ total_cars = cars_initial + cars_arrived
122
+ result = total_cars
123
+ return result
124
+
125
+
126
+
127
+
128
+
129
+ Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?
130
+
131
+ # solution in Python:
132
+
133
+
134
+ def solution():
135
+ """There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?"""
136
+ trees_initial = 15
137
+ trees_after = 21
138
+ trees_added = trees_after - trees_initial
139
+ result = trees_added
140
+ return result
141
+
142
+
143
+
144
+
145
+
146
+ Q: {{question}}
147
+
148
+ # solution in Python:
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ git+https://github.com/srush/minichain
3
+ manifest-ml