Spaces:
Runtime error
Runtime error
kevin-yang
commited on
Commit
ยท
4f76eaa
1
Parent(s):
5d01a65
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel, PreTrainedTokenizerFast
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
model = GPT2LMHeadModel.from_pretrained("jason9693/soongsil-univ-gpt-v1")
|
| 8 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained("jason9693/soongsil-univ-gpt-v1")
|
| 9 |
+
|
| 10 |
+
category_map = {
|
| 11 |
+
"์ญ์ค๋ ์ํ": "<unused5>",
|
| 12 |
+
"๋ชจ๋์ ์ฐ์ ": "<unused3>",
|
| 13 |
+
"๋ํ์ ์ก๋ด๋ฐฉ": "<unused4>"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
st.markdown("""# University Community KoGPT2 : ์ญ์ค๋ ์๋ธ๋ฆฌํ์๋ด
|
| 17 |
+
|
| 18 |
+
[](https://colab.research.google.com/drive/1p6DIxsesi3eJNPwFwvMw0MeM5LkSGoPW?usp=sharing) [](https://github.com/jason9693/UCK-GPT2/issues) 
|
| 19 |
+
|
| 20 |
+
## ๋ํ ์ปค๋ฎค๋ํฐ ๊ฒ์๊ธ ์์ฑ๊ธฐ
|
| 21 |
+
|
| 22 |
+
SKT-AI์์ ๊ณต๊ฐํ [KoGPT2](https://github.com/SKT-AI/KoGPT2) ๋ชจ๋ธ์ ํ์ธํ๋ํ์ฌ ๋ํ ์ปค๋ฎค๋ํฐ ๊ฒ์๊ธ์ ์์ฑํ๋ ๋ชจ๋ธ์
๋๋ค. ์ด ์๋ธ๋ฆฌํ์, ์บ ํผ์คํฝ ๋ฐ์ดํฐ 22๋ง๊ฐ๋ฅผ ์ด์ฉํด์ ํ์ต์ ์งํํ์ผ๋ฉฐ, ํ์ต์๋ ๋๋ต **3์ผ**์ ๋ ์์๋์์ต๋๋ค.
|
| 23 |
+
|
| 24 |
+
* [GPT ๋
ผ๋ฌธ ๋ฆฌ๋ทฐ ๋งํฌ](https://www.notion.so/Improve-Language-Understanding-by-Generative-Pre-Training-GPT-afb4b5ef6e984961ac022b700c152b6b)
|
| 25 |
+
|
| 26 |
+
## ์์ฐํ๊ธฐ
|
| 27 |
+
""")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
seed = st.text_input("Seed", "์กฐ๋ง์ ๊ธฐ๋
๊ด")
|
| 31 |
+
category = st.selectbox("Category", list(category_map.keys()))
|
| 32 |
+
go = st.button("Generate")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
st.markdown("## ์์ฑ ๊ฒฐ๊ณผ")
|
| 36 |
+
if go:
|
| 37 |
+
input_context = category_map[category] + seed
|
| 38 |
+
input_ids = tokenizer(input_context, return_tensors="pt")
|
| 39 |
+
outputs = model.generate(
|
| 40 |
+
input_ids=input_ids["input_ids"],
|
| 41 |
+
max_length=250,
|
| 42 |
+
num_return_sequences=1,
|
| 43 |
+
no_repeat_ngram_size=3,
|
| 44 |
+
repetition_penalty=2.0,
|
| 45 |
+
do_sample=True,
|
| 46 |
+
use_cache=True,
|
| 47 |
+
eos_token_id=tokenizer.eos_token_id
|
| 48 |
+
)
|
| 49 |
+
st.write(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].replace("<unused2>", "\n"))
|