UNIST-Eunchan
commited on
Commit
β’
fc5a865
1
Parent(s):
d70b47c
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,18 @@
|
|
1 |
import transformers
|
2 |
import streamlit as st
|
3 |
|
4 |
-
from transformers import AutoTokenizer,
|
5 |
-
|
|
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
|
7 |
@st.cache
|
8 |
def load_model(model_name):
|
9 |
-
|
|
|
10 |
return model
|
11 |
|
12 |
-
model = load_model("
|
13 |
|
14 |
def infer(input_ids, max_length, temperature, top_k, top_p):
|
15 |
|
@@ -20,9 +23,11 @@ def infer(input_ids, max_length, temperature, top_k, top_p):
|
|
20 |
top_k=top_k,
|
21 |
top_p=top_p,
|
22 |
do_sample=True,
|
23 |
-
num_return_sequences=1
|
|
|
|
|
24 |
)
|
25 |
-
|
26 |
return output_sequences
|
27 |
default_value = "See how a modern neural network auto-completes your text π€ This site, built by the Hugging Face team, lets you write a whole document directly from your browser, and you can trigger the Transformer anywhere using the Tab key. Its like having a smart machine that completes your thoughts π Get started by typing a custom snippet, check out the repository, or try one of the examples. Have fun!"
|
28 |
|
@@ -30,11 +35,11 @@ default_value = "See how a modern neural network auto-completes your text π€ T
|
|
30 |
st.title("Write with Transformers π¦")
|
31 |
st.write("The almighty king of text generation, GPT-2 comes in four available sizes, only three of which have been publicly made available. Feared for its fake news generation capabilities, it currently stands as the most syntactically coherent model. A direct successor to the original GPT, it reinforces the already established pre-training/fine-tuning killer duo. From the paper: Language Models are Unsupervised Multitask Learners by Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei and Ilya Sutskever.")
|
32 |
|
33 |
-
sent = st.text_area("Text", default_value, height =
|
34 |
-
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=
|
35 |
temperature = st.sidebar.slider("Temperature", value = 1.0, min_value = 0.0, max_value=1.0, step=0.05)
|
36 |
top_k = st.sidebar.slider("Top-k", min_value = 0, max_value=5, value = 0)
|
37 |
-
top_p = st.sidebar.slider("Top-p", min_value = 0.0, max_value=1.0, step = 0.05, value = 0.
|
38 |
|
39 |
encoded_prompt = tokenizer.encode(sent, add_special_tokens=False, return_tensors="pt")
|
40 |
if encoded_prompt.size()[-1] == 0:
|
|
|
1 |
import transformers
|
2 |
import streamlit as st
|
3 |
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("UNIST-Eunchan/bart-dnc-booksum")
|
7 |
+
|
8 |
tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
|
9 |
@st.cache
|
10 |
def load_model(model_name):
|
11 |
+
|
12 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("UNIST-Eunchan/bart-dnc-booksum")
|
13 |
return model
|
14 |
|
15 |
+
model = load_model("UNIST-Eunchan/bart-dnc-booksum")
|
16 |
|
17 |
def infer(input_ids, max_length, temperature, top_k, top_p):
|
18 |
|
|
|
23 |
top_k=top_k,
|
24 |
top_p=top_p,
|
25 |
do_sample=True,
|
26 |
+
num_return_sequences=1,
|
27 |
+
num_beams=4,
|
28 |
+
no_repeat_ngram_size=2
|
29 |
)
|
30 |
+
|
31 |
return output_sequences
|
32 |
default_value = "See how a modern neural network auto-completes your text π€ This site, built by the Hugging Face team, lets you write a whole document directly from your browser, and you can trigger the Transformer anywhere using the Tab key. Its like having a smart machine that completes your thoughts π Get started by typing a custom snippet, check out the repository, or try one of the examples. Have fun!"
|
33 |
|
|
|
35 |
st.title("Write with Transformers π¦")
|
36 |
st.write("The almighty king of text generation, GPT-2 comes in four available sizes, only three of which have been publicly made available. Feared for its fake news generation capabilities, it currently stands as the most syntactically coherent model. A direct successor to the original GPT, it reinforces the already established pre-training/fine-tuning killer duo. From the paper: Language Models are Unsupervised Multitask Learners by Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei and Ilya Sutskever.")
|
37 |
|
38 |
+
sent = st.text_area("Text", default_value, height = 550)
|
39 |
+
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=256)
|
40 |
temperature = st.sidebar.slider("Temperature", value = 1.0, min_value = 0.0, max_value=1.0, step=0.05)
|
41 |
top_k = st.sidebar.slider("Top-k", min_value = 0, max_value=5, value = 0)
|
42 |
+
top_p = st.sidebar.slider("Top-p", min_value = 0.0, max_value=1.0, step = 0.05, value = 0.92)
|
43 |
|
44 |
encoded_prompt = tokenizer.encode(sent, add_special_tokens=False, return_tensors="pt")
|
45 |
if encoded_prompt.size()[-1] == 0:
|