fjenett commited on
Commit
2e004f5
1 Parent(s): 83c91d7

added examples

Browse files
Files changed (1) hide show
  1. app.py +129 -22
app.py CHANGED
@@ -4,20 +4,22 @@ import time
4
  from ast import literal_eval
5
  from datetime import datetime
6
 
 
7
  def to_md(text):
8
  # return text.replace("\n", "<br />")
9
  return text.replace("\n", "<br />")
10
 
 
11
  def infer(
12
- prompt,
13
- model_name,
14
- max_new_tokens=10,
15
- temperature=0.1,
16
- top_p=1.0,
17
- top_k=40,
18
- num_completions=1,
19
- seed=42,
20
- stop="\n"
21
  ):
22
  model_name_map = {
23
  "GPT-JT-6B-v1": "Together-gpt-JT-6B-v1",
@@ -29,7 +31,7 @@ def infer(
29
  top_k = int(top_k)
30
  stop = stop.split(";")
31
  seed = seed
32
-
33
  assert 1 <= max_new_tokens <= 256
34
  assert 1 <= num_completions <= 5
35
  assert 0.0 <= temperature <= 10.0
@@ -38,7 +40,7 @@ def infer(
38
 
39
  if temperature == 0.0:
40
  temperature = 0.01
41
- if prompt=="":
42
  prompt = " "
43
  my_post_dict = {
44
  "model": "Together-gpt-JT-6B-v1",
@@ -53,28 +55,133 @@ def infer(
53
  response = requests.get("https://staging.together.xyz/api/inference", params=my_post_dict).json()
54
  generated_text = response['output']['choices'][0]['text']
55
  print(f"recv: {datetime.now()}")
56
-
57
  for stop_word in stop:
58
  if stop_word != '' and stop_word in generated_text:
59
  generated_text = generated_text[:generated_text.find(stop_word)]
60
-
61
  return generated_text
62
 
63
- def main ():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  iface = gr.Interface(
65
  fn=infer,
66
  inputs=[
67
- gr.Textbox(lines=20), # prompt
68
- gr.Dropdown(["GPT-JT-6B-v1"]), # model_name
69
- gr.Slider(1, 256, value=200), # max_tokens
70
- gr.Slider(0.0, 10.0, value=0.1), # temperature
71
- gr.Slider(0.0, 1.0, value=0.9), # top_p
72
- gr.Slider(0, 1000, value=40) # top_k
73
  ],
74
- outputs=gr.Textbox(lines=7)
 
75
  )
76
 
77
  iface.launch(debug=True)
78
 
 
79
  if __name__ == '__main__':
80
- main()
 
4
  from ast import literal_eval
5
  from datetime import datetime
6
 
7
+
8
  def to_md(text):
9
  # return text.replace("\n", "<br />")
10
  return text.replace("\n", "<br />")
11
 
12
+
13
  def infer(
14
+ prompt,
15
+ model_name,
16
+ max_new_tokens=10,
17
+ temperature=0.1,
18
+ top_p=1.0,
19
+ top_k=40,
20
+ num_completions=1,
21
+ seed=42,
22
+ stop="\n"
23
  ):
24
  model_name_map = {
25
  "GPT-JT-6B-v1": "Together-gpt-JT-6B-v1",
 
31
  top_k = int(top_k)
32
  stop = stop.split(";")
33
  seed = seed
34
+
35
  assert 1 <= max_new_tokens <= 256
36
  assert 1 <= num_completions <= 5
37
  assert 0.0 <= temperature <= 10.0
 
40
 
41
  if temperature == 0.0:
42
  temperature = 0.01
43
+ if prompt == "":
44
  prompt = " "
45
  my_post_dict = {
46
  "model": "Together-gpt-JT-6B-v1",
 
55
  response = requests.get("https://staging.together.xyz/api/inference", params=my_post_dict).json()
56
  generated_text = response['output']['choices'][0]['text']
57
  print(f"recv: {datetime.now()}")
58
+
59
  for stop_word in stop:
60
  if stop_word != '' and stop_word in generated_text:
61
  generated_text = generated_text[:generated_text.find(stop_word)]
62
+
63
  return generated_text
64
 
65
+
66
+ examples = [
67
+ # Sentiment Analysis
68
+ '''Label the tweets as either "positive", "negative", "mixed", or "neutral":
69
+
70
+ Tweet: I can say that there isn't anything I would change.
71
+ Label: positive
72
+
73
+ Tweet: I'm not sure about this.
74
+ Label: neutral
75
+
76
+ Tweet: I liked some parts but I didn't like other parts.
77
+ Label: mixed
78
+
79
+ Tweet: I think the background image could have been better.
80
+ Label: negative
81
+
82
+ Tweet: I really like it.
83
+ Label: ''',
84
+ # Question Answering
85
+ '''Please answer the following question:
86
+
87
+ Question: What is the capital of Canada?
88
+ Answer: Ottawa
89
+
90
+ Question: What is the currency of Switzerland?
91
+ Answer: Swiss franc
92
+
93
+ Question: In which country is Wisconsin located?
94
+ Answer:
95
+ ''',
96
+ # Topic Classification
97
+ '''Given a news article, classify its topic.
98
+ Possible labels: 1. World 2. Sports 3. Business 4. Sci/Tech
99
+
100
+ Article: A nearby star thought to harbor comets and asteroids now appears to be home to planets, too.
101
+ Label: Sci/Tech
102
+
103
+ 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.
104
+ Label: Business
105
+
106
+ 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.
107
+ Label:
108
+ ''',
109
+ # Paraphrasing
110
+ '''Paraphrase the given sentence into a different sentence.
111
+
112
+ Input: Can you recommend some upscale restaurants in New York?
113
+ Output: What upscale restaurants do you recommend in New York?
114
+
115
+ Input: What are the famous places we should not miss in Paris?
116
+ Output: Recommend some of the best places to visit in Paris?
117
+
118
+ Input: Could you recommend some hotels that have cheap price in Zurich?
119
+ Output:
120
+ ''',
121
+ # Text Summarization
122
+ '''Given a review from Amazon's food products, the task is to generate a short summary of the given review in the input.
123
+
124
+ 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.
125
+ Output: Good Quality Dog Food
126
+
127
+ 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'.
128
+ Output: Not as Advertised
129
+
130
+ Input: My toddler loves this game to a point where he asks for it. That's a big thing for me. Secondly, no glitching unlike one of their competitors (PlayShifu). Any tech I don’t have to reach out to support for help is a good tech for me. I even enjoy some of the games and activities in this. Overall, this is a product that shows that the developers took their time and made sure people would not be asking for refund. I’ve become bias regarding this product and honestly I look forward to buying more of this company’s stuff. Please keep up the great work.
131
+ Output:
132
+ ''',
133
+ # Word Sense Disambiguation
134
+ '''Identify which sense of a word is meant in a given context.
135
+
136
+ Context: The river overflowed the bank.
137
+ Word: bank
138
+ Sense: river bank
139
+
140
+ Context: A mouse takes much more room than a trackball.
141
+ Word: mouse
142
+ Sense: computer mouse
143
+
144
+ Context: The bank will not be accepting cash on Saturdays.
145
+ Word: bank
146
+ Sense: commercial (finance) banks
147
+
148
+ Context: Bill killed the project
149
+ Word: kill
150
+ Sense:
151
+ ''',
152
+ # Natural Language Interface
153
+ '''Given a pair of sentences, choose whether the two sentences agree (entailment)/disagree (contradiction) with each other.
154
+ Possible labels: 1. entailment 2. contradiction
155
+
156
+ Sentence 1: The skier was on the edge of the ramp. Sentence 2: The skier was dressed in winter clothes.
157
+ Label: entailment
158
+
159
+ Sentence 1: The boy skated down the staircase railing. Sentence 2: The boy is a newbie skater.
160
+ Label: contradiction
161
+
162
+ Sentence 1: Two middle-aged people stand by a golf hole. Sentence 2: A couple riding in a golf cart.
163
+ Label:
164
+ '''
165
+ ]
166
+
167
+
168
+ def main():
169
  iface = gr.Interface(
170
  fn=infer,
171
  inputs=[
172
+ gr.Textbox(lines=20), # prompt
173
+ gr.Dropdown(["GPT-JT-6B-v1"]), # model_name
174
+ gr.Slider(1, 256, value=200), # max_tokens
175
+ gr.Slider(0.0, 10.0, value=0.1), # temperature
176
+ gr.Slider(0.0, 1.0, value=0.9), # top_p
177
+ gr.Slider(0, 1000, value=40) # top_k
178
  ],
179
+ outputs=gr.Textbox(lines=7),
180
+ examples=examples
181
  )
182
 
183
  iface.launch(debug=True)
184
 
185
+
186
  if __name__ == '__main__':
187
+ main()