Spaces:
Runtime error
Runtime error
Commit
·
aa7bb26
1
Parent(s):
260e134
Update app.py
Browse files
app.py
CHANGED
@@ -19,37 +19,38 @@ def chatbot(input):
|
|
19 |
|
20 |
|
21 |
tokenizer = transformers.AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
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 |
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
55 |
outputs = gr.outputs.Textbox(label="Reply")
|
|
|
19 |
|
20 |
|
21 |
tokenizer = transformers.AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
22 |
+
|
23 |
+
for i in range(50):
|
24 |
+
# mtp-7b is trained to add "<|endoftext|>" at the end of generations
|
25 |
+
stop_token_ids = tokenizer.convert_tokens_to_ids(["<|endoftext|>"])
|
26 |
+
|
27 |
+
# define custom stopping criteria object
|
28 |
+
class StopOnTokens(StoppingCriteria):
|
29 |
+
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
|
30 |
+
for stop_id in stop_token_ids:
|
31 |
+
if input_ids[0][-1] == stop_id:
|
32 |
+
return True
|
33 |
+
return False
|
34 |
+
|
35 |
+
stopping_criteria = StoppingCriteriaList([StopOnTokens()])
|
36 |
+
|
37 |
+
generate_text = transformers.pipeline(
|
38 |
+
model=model, tokenizer=tokenizer,
|
39 |
+
return_full_text=True, # langchain expects the full text
|
40 |
+
task='text-generation',
|
41 |
+
device=device,
|
42 |
+
# we pass model parameters here too
|
43 |
+
stopping_criteria=stopping_criteria, # without this model will ramble
|
44 |
+
temperature=0.1, # 'randomness' of outputs, 0.0 is the min and 1.0 the max
|
45 |
+
top_p=0.15, # select from top tokens whose probability add up to 15%
|
46 |
+
top_k=0, # select from top 0 tokens (because zero, relies on top_p)
|
47 |
+
max_new_tokens=64, # mex number of tokens to generate in the output
|
48 |
+
repetition_penalty=1.1 # without this output begins repeating
|
49 |
+
)
|
50 |
+
|
51 |
+
res = generate_text(input)
|
52 |
+
output = res[0]["generated_text"]
|
53 |
+
return output
|
54 |
|
55 |
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
56 |
outputs = gr.outputs.Textbox(label="Reply")
|