AI Grammar Correction — Fine-tuned FLAN-T5
Model Description
This is a sequence-to-sequence transformer model fine-tuned for Grammatical Error Correction (GEC) based on google/flan-t5-base.
It automatically detects and corrects grammatical, syntactical, and stylistic errors in English sentences, returning fluent, natural corrections.
Task Details
- Task: Grammatical Error Correction (GEC)
- Base Architecture:
google/flan-t5-base - Input Prefix:
"grammar: <input_text>" - Max Sequence Length: 128 tokens
Dataset Specifications
Fine-tuned on a curated dataset of 100,000 sentence pairs:
- Train Set: 80,000 pairs (80%)
- Validation Set: 10,000 pairs (10%)
- Test Set: 10,000 pairs (10%)
Evaluation Results (10,000 Unseen Test Examples)
| Metric | Test Score |
|---|---|
| BLEU | 0.6869 |
| GLEU | 0.8311 |
| ROUGE-1 | 0.8819 |
| ROUGE-2 | 0.7698 |
| ROUGE-L | 0.8748 |
| Exact Match Accuracy | 0.0886 |
| Word Accuracy | 0.5018 |
How to Use
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
MODEL_ID = "anuvid/ai-grammar-correction-model"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
text = "She go to school yesterday."
inputs = tokenizer(f"grammar: {text}", return_tensors="pt")
outputs = model.generate(**inputs, max_length=128, num_beams=4, early_stopping=True)
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print("Original :", text)
print("Corrected:", corrected_text)
# Output: "She went to school yesterday."
Example Corrections
| Original Input | Model Output |
|---|---|
She go to school yesterday. | She went to school yesterday. |
He don't likes playing football. | He doesn't like playing football. |
I has a meeting tomorrow. | I have a meeting tomorrow. |
They was going to the market. | They were going to the market. |
This are a very good book. | This is a very good book. |