Fine-tuning Google’s T5 for Grammatical Error Correction (GEC) in sentences.
This project provides a FastAPI-based service for Grammar Error Correction (GEC) using fine-tuned T5 models. We applied three different fine-tuning approaches (LoRA, QLoRA, and Full fine-tuning) and evaluate each method’s effectiveness in terms of performance, efficiency, and time and resource requirements.- Tech Stack
- Dataset
- File Structure
- Reports & Documentation
- Evaluation Metrics
- Getting Started
- Usage
- Future Work
- Contributors
- Acknowledgements
- Programming Language: Python
- Deep Learning Framework: PyTorch
- Data Processing and Handling: Numpy, Pandas
- Model: Hugging Face Transformers
- Optimization: Optimum, ONNX Runtime
- Backend: FastAPI, Uvicorn
- Frontend: HTML, CSS, JS
We used a Custom HF Dataset of 200k sentence pairs which is a compilation of the following 2 datasets:
https://www.kaggle.com/datasets/satishgunjal/grammar-correction
https://bekushal.medium.com/cleaned-lang8-dataset-for-grammar-error-detection-79aaa31150aa
├─ app/ # files for deployment and web app
├─ digit_recognition_nn/ # NN implementation code
├─ fine_tuning/ # fine-tuning and evaluation code
└─ shakespeare_textgen/ # LSTM implementation code
├─ media/ # images used in readme, report, blog
├─ biweekly_blog.md
├─ report.md
├─ README.md
The evaluation in detail has been documented in the Comparison report
View the Comparison Report analysing the performance of Full Fine-Tuning, LoRA, and QLoRA across parameters like efficiency, memory usage, and accuracy.
We also maintained a detailed Project Blog to document workflow, progress, results and decisions made over the course of the project.
We evaluated the 3 models using the following metrics:
- GLEU Score
- Precision
- F1
- Recall
We also used WandB experiment tracking to track losses, CPU/GPU usage, etc. The detailed graph and evaluation inferences can be found in the Comparison Report.
To install necessary libraries, run:
pip install transformers optimum[onnxruntime] torch fastapi uvicorn Clone the repository
git clone https://github.com/sarayusapa/t5_Grammarator.gitNavigate to the following directory:
cd t5_Grammarator/app/You can run either the Full Fine-Tuned model or the Adapter-based models (LoRA / QLoRA), depending on your preference.
Run convertmodel.py as it is.
Step 1: In convertmodel.py, set:
USE_ADAPTER = TrueStep 2: In the same file, set:
ADAPTER_PATH = "sarayusapa/T5_Large_GEC_LoRA" #LoRAor
ADAPTER_PATH = sarayusapa/T5_Large_GEC_LoRA #QLoRAStep 3: Run convertmodel.py to save the model in ONNX format.
In the same directory ("t5_Grammarator/app"), run the command:
uvicorn t5app:app --reloadAfter this, the server will be available to open and use.
- Use Full FT model if you want the most accurate results.
- Use Adapters (LoRA/QLoRA) if you want lightweight and memory-efficient inference.
- Reinforcement Learning based fine-tuning for GEC+reasoning
- Probing methods to identify how attention heads imbibe grammar rules
- Finding ways to maximize quantization and maintaining accuracy
