Update generation params
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ tokenizer = T5Tokenizer.from_pretrained("rinna/japanese-gpt-1b")
|
|
7 |
model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt-1b")
|
8 |
|
9 |
|
10 |
-
def generate(text, max_length=
|
11 |
|
12 |
token_ids = tokenizer.encode(
|
13 |
text, add_special_tokens=False, return_tensors="pt")
|
@@ -19,13 +19,14 @@ def generate(text, max_length=128):
|
|
19 |
do_sample=True,
|
20 |
top_k=500,
|
21 |
top_p=0.95,
|
22 |
-
pad_token_id=tokenizer.pad_token_id,
|
23 |
-
bos_token_id=tokenizer.bos_token_id,
|
24 |
-
eos_token_id=tokenizer.eos_token_id,
|
25 |
-
bad_word_ids=[[tokenizer.unk_token_id]]
|
|
|
26 |
)
|
27 |
|
28 |
-
output = tokenizer.decode(output_ids.tolist()[0])
|
29 |
return output, translate_from_jp_to_en(output)
|
30 |
|
31 |
|
@@ -33,7 +34,7 @@ title = "JP GPT Demo"
|
|
33 |
description = "Demo for generating text in Japanase using a GPT model"
|
34 |
examples = [['日本のeスポーツ障害者がステレオタイプを撃ち落とす', 128]]
|
35 |
gr.Interface(fn=generate, inputs=[gr.inputs.Textbox(lines=4, label="Prompt"),
|
36 |
-
gr.inputs.Slider(minimum=8, maximum=
|
37 |
outputs=["text", "text"],
|
38 |
title=title, description=description,
|
39 |
# article= article,
|
|
|
7 |
model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt-1b")
|
8 |
|
9 |
|
10 |
+
def generate(text, max_length=512):
|
11 |
|
12 |
token_ids = tokenizer.encode(
|
13 |
text, add_special_tokens=False, return_tensors="pt")
|
|
|
19 |
do_sample=True,
|
20 |
top_k=500,
|
21 |
top_p=0.95,
|
22 |
+
#pad_token_id=tokenizer.pad_token_id,
|
23 |
+
#bos_token_id=tokenizer.bos_token_id,
|
24 |
+
#eos_token_id=tokenizer.eos_token_id,
|
25 |
+
#bad_word_ids=[[tokenizer.unk_token_id]]
|
26 |
+
early_stopping=False,
|
27 |
)
|
28 |
|
29 |
+
output = tokenizer.decode(output_ids.tolist()[0], skip_specual_tokens=True)
|
30 |
return output, translate_from_jp_to_en(output)
|
31 |
|
32 |
|
|
|
34 |
description = "Demo for generating text in Japanase using a GPT model"
|
35 |
examples = [['日本のeスポーツ障害者がステレオタイプを撃ち落とす', 128]]
|
36 |
gr.Interface(fn=generate, inputs=[gr.inputs.Textbox(lines=4, label="Prompt"),
|
37 |
+
gr.inputs.Slider(minimum=8, maximum=4096, step=8, default=64, label="Numbers of tokens")],
|
38 |
outputs=["text", "text"],
|
39 |
title=title, description=description,
|
40 |
# article= article,
|