Spaces:
Runtime error
Runtime error
Duplicate from togethercomputer/GPT-JT
Browse filesCo-authored-by: Jue Wang <juewang@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +280 -0
- requirements.txt +0 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: GPT-JT
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: pink
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.10.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
duplicated_from: togethercomputer/GPT-JT
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
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 |
+
@st.cache
|
12 |
+
def infer(
|
13 |
+
prompt,
|
14 |
+
model_name,
|
15 |
+
max_new_tokens=10,
|
16 |
+
temperature=0.1,
|
17 |
+
top_p=1.0,
|
18 |
+
top_k=40,
|
19 |
+
num_completions=1,
|
20 |
+
seed=42,
|
21 |
+
stop="\n"
|
22 |
+
):
|
23 |
+
model_name_map = {
|
24 |
+
"GPT-JT-6B-v1": "Together-gpt-JT-6B-v1",
|
25 |
+
}
|
26 |
+
max_new_tokens = int(max_new_tokens)
|
27 |
+
num_completions = int(num_completions)
|
28 |
+
temperature = float(temperature)
|
29 |
+
top_p = float(top_p)
|
30 |
+
top_k = int(top_k)
|
31 |
+
stop = stop.split(";")
|
32 |
+
seed = seed
|
33 |
+
|
34 |
+
assert 1 <= max_new_tokens <= 256
|
35 |
+
assert 1 <= num_completions <= 5
|
36 |
+
assert 0.0 <= temperature <= 10.0
|
37 |
+
assert 0.0 <= top_p <= 1.0
|
38 |
+
assert 1 <= top_k <= 1000
|
39 |
+
|
40 |
+
if temperature == 0.0:
|
41 |
+
temperature = 0.01
|
42 |
+
if prompt=="":
|
43 |
+
prompt = " "
|
44 |
+
my_post_dict = {
|
45 |
+
"model": "Together-gpt-JT-6B-v1",
|
46 |
+
"prompt": prompt,
|
47 |
+
"top_p": top_p,
|
48 |
+
"top_k": top_k,
|
49 |
+
"temperature": temperature,
|
50 |
+
"max_tokens": max_new_tokens,
|
51 |
+
"stop": stop,
|
52 |
+
}
|
53 |
+
print(f"send: {datetime.now()}")
|
54 |
+
response = requests.get("https://staging.together.xyz/api/inference", params=my_post_dict).json()
|
55 |
+
generated_text = response['output']['choices'][0]['text']
|
56 |
+
print(f"recv: {datetime.now()}")
|
57 |
+
|
58 |
+
for stop_word in stop:
|
59 |
+
if stop_word != '' and stop_word in generated_text:
|
60 |
+
generated_text = generated_text[:generated_text.find(stop_word)]
|
61 |
+
|
62 |
+
return generated_text
|
63 |
+
|
64 |
+
|
65 |
+
def set_preset():
|
66 |
+
if st.session_state.preset == "Question Answering":
|
67 |
+
|
68 |
+
st.session_state.prompt = '''
|
69 |
+
Please answer the following question:
|
70 |
+
|
71 |
+
Question: What is the capital of Canada?
|
72 |
+
Answer: Ottawa
|
73 |
+
|
74 |
+
Question: What is the currency of Switzerland?
|
75 |
+
Answer: Swiss franc
|
76 |
+
|
77 |
+
Question: In which country is Wisconsin located?
|
78 |
+
Answer:
|
79 |
+
'''.strip()
|
80 |
+
st.session_state.temperature = "0.0"
|
81 |
+
st.session_state.top_p = "1.0"
|
82 |
+
st.session_state.max_new_tokens = "5"
|
83 |
+
st.session_state.stop = r'\n'
|
84 |
+
|
85 |
+
elif st.session_state.preset == "Sentiment Analysis":
|
86 |
+
|
87 |
+
st.session_state.prompt = '''
|
88 |
+
Label the tweets as either "positive", "negative", "mixed", or "neutral":
|
89 |
+
|
90 |
+
Tweet: I can say that there isn't anything I would change.
|
91 |
+
Label: positive
|
92 |
+
|
93 |
+
Tweet: I'm not sure about this.
|
94 |
+
Label: neutral
|
95 |
+
|
96 |
+
Tweet: I liked some parts but I didn't like other parts.
|
97 |
+
Label: mixed
|
98 |
+
|
99 |
+
Tweet: I think the background image could have been better.
|
100 |
+
Label: negative
|
101 |
+
|
102 |
+
Tweet: I really like it.
|
103 |
+
Label:
|
104 |
+
'''.strip()
|
105 |
+
st.session_state.temperature = "0.0"
|
106 |
+
st.session_state.top_p = "1.0"
|
107 |
+
st.session_state.max_new_tokens = "2"
|
108 |
+
st.session_state.stop = r'\n'
|
109 |
+
|
110 |
+
elif st.session_state.preset == "Topic Classification":
|
111 |
+
|
112 |
+
st.session_state.prompt = '''
|
113 |
+
Given a news article, classify its topic.
|
114 |
+
Possible labels: 1. World 2. Sports 3. Business 4. Sci/Tech
|
115 |
+
|
116 |
+
Article: A nearby star thought to harbor comets and asteroids now appears to be home to planets, too.
|
117 |
+
Label: Sci/Tech
|
118 |
+
|
119 |
+
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.
|
120 |
+
Label: Business
|
121 |
+
|
122 |
+
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.
|
123 |
+
Label:
|
124 |
+
'''.strip()
|
125 |
+
st.session_state.temperature = "0.0"
|
126 |
+
st.session_state.top_p = "1.0"
|
127 |
+
st.session_state.max_new_tokens = "5"
|
128 |
+
st.session_state.stop = r'\n'
|
129 |
+
|
130 |
+
elif st.session_state.preset == "Paraphrasing":
|
131 |
+
|
132 |
+
st.session_state.prompt = '''
|
133 |
+
Paraphrase the given sentence into a different sentence.
|
134 |
+
|
135 |
+
Input: Can you recommend some upscale restaurants in New York?
|
136 |
+
Output: What upscale restaurants do you recommend in New York?
|
137 |
+
|
138 |
+
Input: What are the famous places we should not miss in Paris?
|
139 |
+
Output: Recommend some of the best places to visit in Paris?
|
140 |
+
|
141 |
+
Input: Could you recommend some hotels that have cheap price in Zurich?
|
142 |
+
Output:
|
143 |
+
'''.strip()
|
144 |
+
st.session_state.temperature = "0.8"
|
145 |
+
st.session_state.top_p = "1.0"
|
146 |
+
st.session_state.max_new_tokens = "20"
|
147 |
+
st.session_state.stop = r'\n'
|
148 |
+
|
149 |
+
elif st.session_state.preset == "Text Summarization":
|
150 |
+
|
151 |
+
st.session_state.prompt = '''
|
152 |
+
Given a review from Amazon's food products, the task is to generate a short summary of the given review in the input.
|
153 |
+
|
154 |
+
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.
|
155 |
+
Output: Good Quality Dog Food
|
156 |
+
|
157 |
+
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'.
|
158 |
+
Output: Not as Advertised
|
159 |
+
|
160 |
+
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.
|
161 |
+
Output:
|
162 |
+
'''.strip()
|
163 |
+
st.session_state.temperature = "0.0"
|
164 |
+
st.session_state.top_p = "1.0"
|
165 |
+
st.session_state.max_new_tokens = "10"
|
166 |
+
st.session_state.stop = r'\n'
|
167 |
+
|
168 |
+
elif st.session_state.preset == "Word Sense Disambiguation":
|
169 |
+
|
170 |
+
st.session_state.prompt = '''
|
171 |
+
Identify which sense of a word is meant in a given context.
|
172 |
+
|
173 |
+
Context: The river overflowed the bank.
|
174 |
+
Word: bank
|
175 |
+
Sense: river bank
|
176 |
+
|
177 |
+
Context: A mouse takes much more room than a trackball.
|
178 |
+
Word: mouse
|
179 |
+
Sense: computer mouse
|
180 |
+
|
181 |
+
Context: The bank will not be accepting cash on Saturdays.
|
182 |
+
Word: bank
|
183 |
+
Sense: commercial (finance) banks
|
184 |
+
|
185 |
+
Context: Bill killed the project
|
186 |
+
Word: kill
|
187 |
+
Sense:
|
188 |
+
'''.strip()
|
189 |
+
st.session_state.temperature = "0.0"
|
190 |
+
st.session_state.top_p = "1.0"
|
191 |
+
st.session_state.max_new_tokens = "10"
|
192 |
+
st.session_state.stop = r'\n'
|
193 |
+
|
194 |
+
elif st.session_state.preset == "Natural Language Inference":
|
195 |
+
|
196 |
+
st.session_state.prompt = '''
|
197 |
+
Given a pair of sentences, choose whether the two sentences agree (entailment)/disagree (contradiction) with each other.
|
198 |
+
Possible labels: 1. entailment 2. contradiction
|
199 |
+
|
200 |
+
Sentence 1: The skier was on the edge of the ramp. Sentence 2: The skier was dressed in winter clothes.
|
201 |
+
Label: entailment
|
202 |
+
|
203 |
+
Sentence 1: The boy skated down the staircase railing. Sentence 2: The boy is a newbie skater.
|
204 |
+
Label: contradiction
|
205 |
+
|
206 |
+
Sentence 1: Two middle-aged people stand by a golf hole. Sentence 2: A couple riding in a golf cart.
|
207 |
+
Label:
|
208 |
+
'''.strip()
|
209 |
+
st.session_state.temperature = "0.0"
|
210 |
+
st.session_state.top_p = "1.0"
|
211 |
+
st.session_state.max_new_tokens = "2"
|
212 |
+
st.session_state.stop = r'\n'
|
213 |
+
|
214 |
+
else:
|
215 |
+
pass
|
216 |
+
|
217 |
+
|
218 |
+
def main():
|
219 |
+
|
220 |
+
if 'preset' not in st.session_state:
|
221 |
+
st.session_state.preset = "Sentiment Analysis"
|
222 |
+
st.session_state.top_k = "40"
|
223 |
+
st.session_state.stop = r'\n'
|
224 |
+
set_preset()
|
225 |
+
|
226 |
+
st.title("GPT-JT")
|
227 |
+
|
228 |
+
col1, col2 = st.columns([1, 2])
|
229 |
+
|
230 |
+
with col1:
|
231 |
+
model_name = st.selectbox("Model", ["GPT-JT-6B-v1"])
|
232 |
+
|
233 |
+
with col2:
|
234 |
+
preset = st.selectbox(
|
235 |
+
label="Examples",
|
236 |
+
options=('Question Answering', 'Sentiment Analysis',
|
237 |
+
"Topic Classification", "Paraphrasing", "Text Summarization",
|
238 |
+
"Word Sense Disambiguation", "Natural Language Inference"),
|
239 |
+
on_change=set_preset,
|
240 |
+
key="preset",
|
241 |
+
)
|
242 |
+
|
243 |
+
col3, col4 = st.columns([1, 5])
|
244 |
+
|
245 |
+
with col3:
|
246 |
+
max_new_tokens = st.text_input('Max new tokens', st.session_state.max_new_tokens)
|
247 |
+
temperature = st.text_input('temperature', st.session_state.temperature)
|
248 |
+
top_k = st.text_input('top_k', st.session_state.top_k)
|
249 |
+
top_p = st.text_input('top_p', st.session_state.top_p)
|
250 |
+
# num_completions = st.text_input('num_completions (only the best one will be returend)', "1")
|
251 |
+
num_completions = "1"
|
252 |
+
stop = st.text_input('stop, split by;', st.session_state.stop)
|
253 |
+
# seed = st.text_input('seed', "42")
|
254 |
+
seed = "42"
|
255 |
+
|
256 |
+
with col4:
|
257 |
+
|
258 |
+
prompt_area = st.empty()
|
259 |
+
prompt = prompt_area.text_area(
|
260 |
+
"Prompt",
|
261 |
+
value=st.session_state.prompt,
|
262 |
+
max_chars=4096,
|
263 |
+
height=500,
|
264 |
+
)
|
265 |
+
|
266 |
+
generated_area = st.empty()
|
267 |
+
generated_area.markdown("(Generate here)")
|
268 |
+
|
269 |
+
button_submit = st.button("Submit")
|
270 |
+
|
271 |
+
if button_submit:
|
272 |
+
generated_area.markdown("<b>" + to_md(prompt) + "</b>", unsafe_allow_html=True)
|
273 |
+
report_text = infer(
|
274 |
+
prompt, model_name=model_name, max_new_tokens=max_new_tokens, temperature=temperature, top_p=top_p, top_k=top_k,
|
275 |
+
num_completions=num_completions, seed=seed, stop=literal_eval("'''"+stop+"'''"),
|
276 |
+
)
|
277 |
+
generated_area.markdown("<b>" + to_md(prompt) + "</b><mark style='background-color: #cbeacd'>" + to_md(report_text)+"</mark>", unsafe_allow_html=True)
|
278 |
+
|
279 |
+
if __name__ == '__main__':
|
280 |
+
main()
|
requirements.txt
ADDED
File without changes
|