Spaces:
Runtime error
Runtime error
Commit
·
b306dde
1
Parent(s):
fa7ee8f
Update generator.py
Browse files- generator.py +12 -8
generator.py
CHANGED
|
@@ -46,19 +46,23 @@ hfmodel, hftokenizer, tok, model = load_model()
|
|
| 46 |
nlp = pipeline("e2e-qg")
|
| 47 |
def run_model(input_string, **generator_args):
|
| 48 |
generator_args = {
|
| 49 |
-
"
|
| 50 |
"num_beams": 4,
|
| 51 |
-
|
| 52 |
"no_repeat_ngram_size": 2,
|
| 53 |
"early_stopping": False,
|
| 54 |
}
|
| 55 |
# tokenizer = att.from_pretrained("ThomasSimonini/t5-end2end-question-generation")
|
| 56 |
-
output = nlp(input_string)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
return output
|
| 63 |
|
| 64 |
|
|
|
|
| 46 |
nlp = pipeline("e2e-qg")
|
| 47 |
def run_model(input_string, **generator_args):
|
| 48 |
generator_args = {
|
| 49 |
+
"max_model_length": 256,
|
| 50 |
"num_beams": 4,
|
| 51 |
+
"length_penalty": 1.5,
|
| 52 |
"no_repeat_ngram_size": 2,
|
| 53 |
"early_stopping": False,
|
| 54 |
}
|
| 55 |
# tokenizer = att.from_pretrained("ThomasSimonini/t5-end2end-question-generation")
|
| 56 |
+
# output = nlp(input_string)
|
| 57 |
+
|
| 58 |
+
input_string = "generate questions: " + input_string + " </s>"
|
| 59 |
+
|
| 60 |
+
inputs = hftokenizer.encode(input_string, return_tensors="pt")
|
| 61 |
+
|
| 62 |
+
res = model.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], **generate_kwargs)
|
| 63 |
+
output = hftokenizer.decode(res[0], skip_special_tokens=True)
|
| 64 |
+
output = [item.split("<sep>") for item in output]
|
| 65 |
+
output = [o.strip() for o in output[:-1]]
|
| 66 |
return output
|
| 67 |
|
| 68 |
|