Views
No views yet
T5-base model.t5-base model:<extra_id_97> – followed by the question type
short answer, multiple choice question, or true or false question<extra_id_98> – followed by the difficulty
easy, medium, or hard<extra_id_99> – followed by [optional answer] context
optional answer – for targeted question generation, or you can leave it as blankcontext – the main passage/content from which questions are generated1def format_prompt(qtype, difficulty, context, answer=""):
2 """
3 Format input prompt for question generation
4 """
5 answer_part = f"[{answer}]" if answer else ""
6 return f"<extra_id_97>{qtype} <extra_id_98>{difficulty} <extra_id_99>{answer_part} {context}"
71from transformers import T5Tokenizer, T5ForConditionalGeneration
2
3# Load model from Hugging Face Hub
4model_name = "Avinash250325/T5BaseQuestionGeneration"
5tokenizer = T5Tokenizer.from_pretrained(model_name)
6model = T5ForConditionalGeneration.from_pretrained(model_name)
7
8# Format input prompt
9def format_prompt(qtype, difficulty, context, answer=""):
10 answer_part = f"[{answer}]" if answer else ""
11 return f"<extra_id_97>{qtype} <extra_id_98>{difficulty} <extra_id_99>{answer_part} {context}"
12
13# You can put any text here to create a question based on this context
14context = "The sun is the center of our solar system."
15
16qtype = "short answer" # qtype: ("short answer", "multiple choice question", "true or false question")
17difficulty = "easy" # difficulty: ("easy", "medium", "hard")
18prompt = format_prompt("short answer", "easy", context)
19
20# Tokenize and generate
21inputs = tokenizer(prompt, return_tensors="pt")
22outputs = model.generate(**inputs, max_length=150)
23
24# Decode output
25print(tokenizer.decode(outputs[0], skip_special_tokens=True))
26