Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,6 +73,24 @@ def run_generate(text, bad_words):
|
|
73 |
yo.append(e)
|
74 |
return yo
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
def run_generate2(text, bad_words):
|
77 |
yo = []
|
78 |
input_ids = tokenizer2.encode(text, return_tensors='pt')
|
@@ -107,6 +125,8 @@ with st.form(key='my_form'):
|
|
107 |
submit_button3 = st.form_submit_button(label='Submit Other Model')
|
108 |
submit_button4 = st.form_submit_button(label='Submit Log Probs Other Model')
|
109 |
|
|
|
|
|
110 |
if submit_button:
|
111 |
translated_text = run_generate(text, bad_words)
|
112 |
st.write(translated_text if translated_text else "No translation found")
|
@@ -137,4 +157,6 @@ with st.form(key='my_form'):
|
|
137 |
probabilities = torch.nn.functional.softmax(logits)
|
138 |
best_logits, best_indices = logits.topk(logs_outputs)
|
139 |
best_words = [tokenizer2.decode([idx.item()]) for idx in best_indices]
|
140 |
-
st.write(best_words)
|
|
|
|
|
|
73 |
yo.append(e)
|
74 |
return yo
|
75 |
|
76 |
+
def BestProbs5(prompt):
|
77 |
+
prompt = prompt.strip()
|
78 |
+
text = tokenizer.encode(prompt)
|
79 |
+
myinput, past_key_values = torch.tensor([text]), None
|
80 |
+
myinput = myinput
|
81 |
+
logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
|
82 |
+
logits = logits[0,-1]
|
83 |
+
probabilities = torch.nn.functional.softmax(logits)
|
84 |
+
best_logits, best_indices = logits.topk(number_of_outputs)
|
85 |
+
best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
|
86 |
+
for i in best_words[0:number_of_outputs]:
|
87 |
+
#print(i)
|
88 |
+
print("\n")
|
89 |
+
g = (prompt + i)
|
90 |
+
st.write(g)
|
91 |
+
l = run_generate(g, "hey")
|
92 |
+
st.write(l)
|
93 |
+
|
94 |
def run_generate2(text, bad_words):
|
95 |
yo = []
|
96 |
input_ids = tokenizer2.encode(text, return_tensors='pt')
|
|
|
125 |
submit_button3 = st.form_submit_button(label='Submit Other Model')
|
126 |
submit_button4 = st.form_submit_button(label='Submit Log Probs Other Model')
|
127 |
|
128 |
+
submit_button5 = st.form_submit_button(label='Most Prob')
|
129 |
+
|
130 |
if submit_button:
|
131 |
translated_text = run_generate(text, bad_words)
|
132 |
st.write(translated_text if translated_text else "No translation found")
|
|
|
157 |
probabilities = torch.nn.functional.softmax(logits)
|
158 |
best_logits, best_indices = logits.topk(logs_outputs)
|
159 |
best_words = [tokenizer2.decode([idx.item()]) for idx in best_indices]
|
160 |
+
st.write(best_words)
|
161 |
+
if submit_button5:
|
162 |
+
BestProbs5(prompt)
|