Spaces:
Running
Running
File size: 1,402 Bytes
d3530f3 f962b30 d3530f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
"""This module contains all tasks specific to question generation model
@Author: Karthick T. Sharma
"""
from .base import Model
from src.utils.text_process import postprocess_question
class QuestionGenerator(Model):
"""Generate question from context and answer."""
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(QuestionGenerator, cls).__new__(cls)
cls._instance._init_model()
return cls._instance
def _init_model(self):
"""Initialize question generator once."""
super().__init__(model_name='iarfmoose/t5-base-question-generator')
# def __init__(self):
# """Initialize question generator."""
# super().__init__(model_name='iarfmoose/t5-base-question-generator')
# super().__init__(model_name='t5-question',
# path_id='1_0dPLdv8WNtSYQdKEWxFc03IR-szs0kB')
def generate(self, context, answer):
"""Generate abstrative summary of given context.
Args:
context (str): input corpus.
ans (str): ans for question that needs to be generated.
Returns:
str: generated question.
"""
return postprocess_question(self().inference(
num_beams=5, no_repeat_ngram_size=2, model_max_length=72,
token_max_length=382, context=context, answer=answer))
|