This is a fully fine-tuned T5-small (60M parameters) model for automatic question generation (AQG) from educational text passages. Given a passage and a highlighted answer span, the model generates a grammatically correct, context-aware question.
This model was developed as part of an MPhil Data Science semester research project at Punjab University, Lahore, Pakistan, focusing on NLP applications in educational technology.
🏗️ Model Architecture
Base Model → google-t5/t5-small (60M parameters)
Task → Text-to-Text Generation (Seq2Seq)
Input format → "generate question: {passage with <hl> answer <hl>}"
Output format → "{generated question}"
Max input len → 512 tokens
Max output len → 64 tokens
Decoding → Beam search (num_beams=4)
📊 Training Details
Hyperparameter
Value
Base model
google-t5/t5-small
Dataset
SQuAD 1.1
Training samples
20,000
Validation samples
2,000
Epochs
3
Batch size
4
Gradient accumulation steps
2 (effective batch = 8)
Learning rate
3e-4
Weight decay
0.01
Warmup steps
500
Optimizer
AdamW
Precision
FP16 (mixed precision)
Hardware
Google Colab T4 GPU (16GB)
Framework
HuggingFace Transformers + PyTorch
Training time
~75 minutes
📈 Evaluation Results
Evaluated on 200 samples from the SQuAD 1.1 validation split:
1passage ="""
2Photosynthesis is a process used by plants to convert light energy
3into chemical energy stored in glucose. It occurs mainly in the
4chloroplasts using chlorophyll pigment to absorb sunlight.
5"""67examples =[8("plants","What organism uses photosynthesis?"),9("chloroplasts","Where does photosynthesis take place?"),10("chlorophyll","What pigment absorbs sunlight in photosynthesis?"),11]1213for answer, expected in examples:14 generated = generate_question(passage.strip(), answer)15print(f"Answer : {answer}")16print(f"Generated: {generated}")17print(f"Expected : {expected}")18print("─"*50)
Batch Generation with spaCy
python
1import spacy
2from transformers import T5ForConditionalGeneration, AutoTokenizer
34nlp = spacy.load("en_core_web_sm")5model_id ="Hamzasajjad38/t5-small-qg"6tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)7model = T5ForConditionalGeneration.from_pretrained(model_id)89defgenerate_all_questions(passage:str, num_questions:int=3):10 doc = nlp(passage)11 candidates =[e.text for e in doc.ents]12 candidates +=[c.text for c in doc.noun_chunks]1314# Deduplicate15 seen, unique =set(),[]16for c in candidates:17if c.lower()notin seen and1<len(c.split())<=5:18 seen.add(c.lower())19 unique.append(c)2021 results =[]22for answer in unique[:num_questions]:23 q = generate_question(passage, answer)24 results.append({"question": q,"answer": answer})2526return results
2728passage = "The Amazon River is the largest river by discharge in the world, \
29flowing through Brazil, Peru,and Colombia."
3031for item in generate_all_questions(passage, num_questions=3):32print(f"Q: {item['question']}")33print(f"A: {item['answer']}\n")