Ubuntu commited on
Commit
de0b08b
1 Parent(s): 663656c
Files changed (1) hide show
  1. app.py +151 -48
app.py CHANGED
@@ -54,70 +54,172 @@ def infer(
54
  print(f"recv: {datetime.now()}")
55
 
56
  for stop_word in stop:
57
- if stop_word in generated_text:
58
  generated_text = generated_text[:generated_text.find(stop_word)]
59
-
60
- st.session_state.updated = True
61
 
62
  return generated_text
63
 
64
 
65
  def set_preset():
66
- if st.session_state.preset == "Classification":
67
 
68
- if not st.session_state.updated:
69
- st.session_state.prompt = '''Please classify the given sentence.
70
- Possible labels:
71
- 1. <label_0>
72
- 2. <label_1>
73
 
74
- Input: <sentence_0>
75
- Label: <label_0>
76
 
77
- Input: <sentence_1>
78
- Label:'''
 
 
 
 
79
  st.session_state.temperature = "0.0"
80
  st.session_state.top_p = "1.0"
81
- st.session_state.max_new_tokens = "10"
 
82
 
83
- elif st.session_state.preset == "Generation":
84
 
85
- if not st.session_state.updated:
86
- st.session_state.prompt = '''Please write a story given keywords.
 
 
 
 
 
 
87
 
88
- Input: bear, honey
89
- Story: Once upon a time,'''
 
 
 
 
 
 
 
90
  st.session_state.temperature = "0.0"
91
- st.session_state.top_p = "0.9"
92
- st.session_state.max_new_tokens = "100"
93
-
94
- else:
95
- pass
96
-
97
-
98
- def main():
 
99
 
100
- if 'preset' not in st.session_state:
101
- st.session_state.preset = "Classification"
102
 
103
- if 'prompt' not in st.session_state:
104
- st.session_state.prompt = "Please answer the following question:\n\nQuestion: In which country is Zurich located?\nAnswer:"
105
 
106
- if 'temperature' not in st.session_state:
107
- st.session_state.temperature = "0.8"
 
 
 
 
 
 
 
 
 
 
108
 
109
- if 'top_p' not in st.session_state:
 
 
 
 
 
 
 
 
 
110
  st.session_state.top_p = "1.0"
 
 
 
 
 
 
 
111
 
112
- if 'top_k' not in st.session_state:
113
- st.session_state.top_k = "40"
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- if 'max_new_tokens' not in st.session_state:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  st.session_state.max_new_tokens = "10"
 
117
 
118
- if 'updated' not in st.session_state:
119
- st.session_state.updated = False
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  st.title("GPT-JT")
123
 
@@ -131,26 +233,27 @@ def main():
131
  top_p = st.text_input('top_p', st.session_state.top_p)
132
  # num_completions = st.text_input('num_completions (only the best one will be returend)', "1")
133
  num_completions = "1"
134
- stop = st.text_input('stop, split by;', r'\n')
135
  # seed = st.text_input('seed', "42")
136
  seed = "42"
137
 
138
  with col2:
139
 
140
- # preset = st.radio(
141
- # "Recommended Templates",
142
- # ('Classification', 'Generation'),
143
- # on_change=set_preset,
144
- # key="preset",
145
- # horizontal=True
146
- # )
 
147
 
148
  prompt_area = st.empty()
149
  prompt = prompt_area.text_area(
150
  "Prompt",
151
  value=st.session_state.prompt,
152
  max_chars=4096,
153
- height=300,
154
  )
155
 
156
  generated_area = st.empty()
 
54
  print(f"recv: {datetime.now()}")
55
 
56
  for stop_word in stop:
57
+ if stop_word != '' and stop_word in generated_text:
58
  generated_text = generated_text[:generated_text.find(stop_word)]
 
 
59
 
60
  return generated_text
61
 
62
 
63
  def set_preset():
64
+ if st.session_state.preset == "Question Answering":
65
 
66
+ st.session_state.prompt = '''
67
+ Please answer the following question:
 
 
 
68
 
69
+ Question: What is the capital of Canada?
70
+ Answer: Ottawa
71
 
72
+ Question: What is the currency of Switzerland?
73
+ Answer: Swiss franc
74
+
75
+ Question: In which country is Wisconsin located?
76
+ Answer:
77
+ '''.strip()
78
  st.session_state.temperature = "0.0"
79
  st.session_state.top_p = "1.0"
80
+ st.session_state.max_new_tokens = "5"
81
+ st.session_state.stop = r'\n'
82
 
83
+ elif st.session_state.preset == "Sentiment Analysis":
84
 
85
+ st.session_state.prompt = '''
86
+ Label the tweets as either "positive", "negative", "mixed", or "neutral":
87
+
88
+ Tweet: I can say that there isn't anything I would change.
89
+ Label: positive
90
+
91
+ Tweet: I'm not sure about this.
92
+ Label: neutral
93
 
94
+ Tweet: I liked some parts but I didn't like other parts.
95
+ Label: mixed
96
+
97
+ Tweet: I think the background image could have been better.
98
+ Label: negative
99
+
100
+ Tweet I really like it.
101
+ Label:
102
+ '''.strip()
103
  st.session_state.temperature = "0.0"
104
+ st.session_state.top_p = "1.0"
105
+ st.session_state.max_new_tokens = "2"
106
+ st.session_state.stop = r'\n'
107
+
108
+ elif st.session_state.preset == "Topic Classification":
109
+
110
+ st.session_state.prompt = '''
111
+ Given a news article, classify its topic.
112
+ Possible labels: 1. World 2. Sports 3. Business 4. Sci/Tech
113
 
114
+ Article: A nearby star thought to harbor comets and asteroids now appears to be home to planets, too.
115
+ Label: Sci/Tech
116
 
117
+ Article: Soaring crude prices plus worries about the economy and the outlook for earnings are expected to hang over the stock market next week during the depth of the summer doldrums.
118
+ Label: Business
119
 
120
+ Article: Murtagh a stickler for success Northeastern field hockey coach Cheryl Murtagh doesn't want the glare of the spotlight that shines on her to detract from a team that has been the America East champion for the past three years and has been to the NCAA tournament 13 times.
121
+ Label:
122
+ '''.strip()
123
+ st.session_state.temperature = "0.0"
124
+ st.session_state.top_p = "1.0"
125
+ st.session_state.max_new_tokens = "5"
126
+ st.session_state.stop = r'\n'
127
+
128
+ elif st.session_state.preset == "Paraphrasing":
129
+
130
+ st.session_state.prompt = '''
131
+ Paraphrase the given sentence into a different sentence.
132
 
133
+ Input: Can you recommed some upscale restaurants in New York?
134
+ Output: What upscale restaurants do you recommend in New York?
135
+
136
+ Input: What are the famous places we should not miss in Paris?
137
+ Output: Recommend some of the best places to visit in Paris?
138
+
139
+ Input: Could you recommed some hotels that have cheap price in Zurich?
140
+ Output:
141
+ '''.strip()
142
+ st.session_state.temperature = "0.8"
143
  st.session_state.top_p = "1.0"
144
+ st.session_state.max_new_tokens = "20"
145
+ st.session_state.stop = r'\n'
146
+
147
+ elif st.session_state.preset == "Text Summarization":
148
+
149
+ st.session_state.prompt = '''
150
+ Given a review from Amazon's food products, the task is to generate a short summary of the given review in the input.
151
 
152
+ Input: I have bought several of the Vitality canned dog food products and have found them all to be of good quality. The product looks more like a stew than a processed meat and it smells better. My Labrador is finicky and she appreciates this product better than most.
153
+ Output: Good Quality Dog Food
154
+
155
+ Input: Product arrived labeled as Jumbo Salted Peanuts...the peanuts were actually small sized unsalted. Not sure if this was an error or if the vendor intended to represent the product as 'Jumbo'.
156
+ Output: Not as Advertised
157
+
158
+ Input: Wolfgang Puck recently changed their Chicken soup. The old stuff is excellent. The new stuff is watered down, not filling and doesn't taste as good. The image and description on this item stated that it was the old soup. The soup I received is the new stuff. Being a food item, returns are not allowed. I feel this was false advertizing and am extremely displeased.
159
+ Output:
160
+ '''.strip()
161
+ st.session_state.temperature = "0.0"
162
+ st.session_state.top_p = "1.0"
163
+ st.session_state.max_new_tokens = "10"
164
+ st.session_state.stop = r'\n'
165
+
166
+ elif st.session_state.preset == "Word Sense Disambiguation":
167
 
168
+ st.session_state.prompt = '''
169
+ Identify which sense of a word is meant in a given context.
170
+
171
+ Context: The river overflowed the bank.
172
+ Word: bank
173
+ Sense: river bank
174
+
175
+ Context: A mouse takes much more room than a trackball.
176
+ Word: mouse
177
+ Sense: computer mouse
178
+
179
+ Context: The bank will not be accepting cash on Saturdays.
180
+ Word: bank
181
+ Sense: commercial (finance) banks
182
+
183
+ Context: Bill killed the project
184
+ Word: kill
185
+ Sense:
186
+ '''.strip()
187
+ st.session_state.temperature = "0.0"
188
+ st.session_state.top_p = "1.0"
189
  st.session_state.max_new_tokens = "10"
190
+ st.session_state.stop = r'\n'
191
 
192
+ elif st.session_state.preset == "Natural Language Inference":
 
193
 
194
+ st.session_state.prompt = '''
195
+ Given a pair of sentences, choose whether the two sentences agree (entailment)/disagree (contradiction) with each other.
196
+ Possible labels: 1. entailment 2. contradiction
197
+
198
+ Sentence 1: The skier was on the edge of the ramp. Sentence 2: The skier was dressed in winter clothes.
199
+ Label: entailment
200
+
201
+ Sentence 1: The boy skated down the staircase railing. Sentence 2: The boy is a newbie skater.
202
+ Label: contradiction
203
+
204
+ Sentence 1: Two middle-aged people stand by a golf hole. Sentence 2: A couple riding in a golf cart.
205
+ Label:
206
+ '''.strip()
207
+ st.session_state.temperature = "0.0"
208
+ st.session_state.top_p = "1.0"
209
+ st.session_state.max_new_tokens = "2"
210
+ st.session_state.stop = r'\n'
211
+
212
+ else:
213
+ pass
214
+
215
+
216
+ def main():
217
+
218
+ if 'preset' not in st.session_state:
219
+ st.session_state.preset = "Sentiment Analysis"
220
+ st.session_state.top_k = "40"
221
+ st.session_state.stop = r'\n'
222
+ set_preset()
223
 
224
  st.title("GPT-JT")
225
 
 
233
  top_p = st.text_input('top_p', st.session_state.top_p)
234
  # num_completions = st.text_input('num_completions (only the best one will be returend)', "1")
235
  num_completions = "1"
236
+ stop = st.text_input('stop, split by;', st.session_state.stop)
237
  # seed = st.text_input('seed', "42")
238
  seed = "42"
239
 
240
  with col2:
241
 
242
+ preset = st.selectbox(
243
+ label="Examples",
244
+ options=('Question Answering', 'Sentiment Analysis',
245
+ "Topic Classification", "Paraphrasing", "Text Summarization",
246
+ "Word Sense Disambiguation", "Natural Language Inference"),
247
+ on_change=set_preset,
248
+ key="preset",
249
+ )
250
 
251
  prompt_area = st.empty()
252
  prompt = prompt_area.text_area(
253
  "Prompt",
254
  value=st.session_state.prompt,
255
  max_chars=4096,
256
+ height=500,
257
  )
258
 
259
  generated_area = st.empty()