Spaces:
Runtime error
Runtime error
Update app.py
Browse filesChange search for next word from greedy to beam.
app.py
CHANGED
@@ -171,7 +171,14 @@ gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
|
171 |
|
172 |
def generate(starting_text):
|
173 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
response=""
|
176 |
#response = gpt2_tensors
|
177 |
for i, x in enumerate(gpt2_tensors):
|
|
|
171 |
|
172 |
def generate(starting_text):
|
173 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
174 |
+
|
175 |
+
# When no specific parameter is specified, the model performs a greedy search to find the next word, which entails selecting the word from all of the
|
176 |
+
# alternatives that has the highest probability of being correct. This process is deterministic in nature, which means that resultant text is the same
|
177 |
+
# as before if we use the same parameters.
|
178 |
+
|
179 |
+
# The num_beams parameter does a beam search: it returns the sequences that have the highest probability, and then, when it comes time to
|
180 |
+
# choose, it picks the one that has the highest probability.
|
181 |
+
gpt2_tensors = mdl.generate(tkn_ids, max_length=100, no_repeat_ngram_size=True, num_beams=3)
|
182 |
response=""
|
183 |
#response = gpt2_tensors
|
184 |
for i, x in enumerate(gpt2_tensors):
|