Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
| 9 |
from transformers import AutoTokenizer, AutoModel
|
| 10 |
from transformers import GPTNeoXForCausalLM, GPTNeoXTokenizerFast
|
| 11 |
import math
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
st.title('GPT2:')
|
|
@@ -32,6 +33,11 @@ infill: sports teams are profitable for owners. ( accumulating vast sums / stock
|
|
| 32 |
|
| 33 |
original:"""
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def prefix_format(sentence):
|
| 36 |
words = sentence.split()
|
| 37 |
if "[MASK]" in sentence:
|
|
@@ -47,8 +53,6 @@ with st.form(key='my_form'):
|
|
| 47 |
submit_button = st.form_submit_button(label='Submit')
|
| 48 |
if submit_button:
|
| 49 |
with torch.no_grad():
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
loss, logits = outputs[:2]
|
| 53 |
-
perplex = math.exp(loss)
|
| 54 |
st.write(perplex)
|
|
|
|
| 9 |
from transformers import AutoTokenizer, AutoModel
|
| 10 |
from transformers import GPTNeoXForCausalLM, GPTNeoXTokenizerFast
|
| 11 |
import math
|
| 12 |
+
import numpy as np
|
| 13 |
|
| 14 |
|
| 15 |
st.title('GPT2:')
|
|
|
|
| 33 |
|
| 34 |
original:"""
|
| 35 |
|
| 36 |
+
|
| 37 |
+
def score(tokens_tensor):
|
| 38 |
+
loss=model(tokens_tensor, labels=tokens_tensor)[0]
|
| 39 |
+
return np.exp(loss.cpu().detach().numpy())
|
| 40 |
+
|
| 41 |
def prefix_format(sentence):
|
| 42 |
words = sentence.split()
|
| 43 |
if "[MASK]" in sentence:
|
|
|
|
| 53 |
submit_button = st.form_submit_button(label='Submit')
|
| 54 |
if submit_button:
|
| 55 |
with torch.no_grad():
|
| 56 |
+
tokens_tensor = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
| 57 |
+
perplex = score(tokens_tensor)
|
|
|
|
|
|
|
| 58 |
st.write(perplex)
|