BigSalmon commited on
Commit
1f2cac2
·
1 Parent(s): bc518af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -72,9 +72,40 @@ Translated into the Style of Abraham Lincoln: corn fields ( permeate illinois /
72
 
73
  informal english:"""
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  with st.form(key='my_form'):
76
  prompt = st.text_area(label='Enter sentence', value=g)
77
  submit_button = st.form_submit_button(label='Submit')
 
78
 
79
  if submit_button:
80
  with torch.no_grad():
@@ -90,4 +121,6 @@ with st.form(key='my_form'):
90
  text.append(best_indices[0].item())
91
  best_probabilities = probabilities[best_indices].tolist()
92
  words = []
93
- st.write(best_words)
 
 
 
72
 
73
  informal english:"""
74
 
75
+
76
+ def BestProbs(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(200)
85
+ best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
86
+ for i in best_words[0:10]:
87
+ print("_______")
88
+ st.write(f"${i} $\n")
89
+ m = (prompt + f"{i}")
90
+ BestProbs2(m)
91
+
92
+ def BestProbs2(prompt):
93
+ prompt = prompt.strip()
94
+ text = tokenizer.encode(prompt)
95
+ myinput, past_key_values = torch.tensor([text]), None
96
+ myinput = myinput
97
+ logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
98
+ logits = logits[0,-1]
99
+ probabilities = torch.nn.functional.softmax(logits)
100
+ best_logits, best_indices = logits.topk(10)
101
+ best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
102
+ for i in best_words[0:10]:
103
+ st.write(i)
104
+
105
  with st.form(key='my_form'):
106
  prompt = st.text_area(label='Enter sentence', value=g)
107
  submit_button = st.form_submit_button(label='Submit')
108
+ submit_button2 = st.form_submit_button(label='Fast Forward')
109
 
110
  if submit_button:
111
  with torch.no_grad():
 
121
  text.append(best_indices[0].item())
122
  best_probabilities = probabilities[best_indices].tolist()
123
  words = []
124
+ st.write(best_words)
125
+ if submit_button2:
126
+ BestProbs(prompt)