Downloads · 30 days
127
31% of all-time downloads
anmol-unitmole/grammar-correction-flan-t5-base
grammar-correction-flan-t5-base is a machine learning model from anmol-unitmole. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
Fine-tuned FLAN-T5-base encoder-decoder model for English grammatical error correction (GEC), trained and selected through controlled experiments on BEA-2019 W&I+LOCNESS, JFLEG-based evaluation data, controlled synthe…
Downloads · 30 days
127
31% of all-time downloads
All-time downloads
413
Public
Parameters
248M
991 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors990 MB · 99%
From the Hugging Face model README
Fine-tuned FLAN-T5-base encoder-decoder model for English grammatical error correction (GEC), trained and selected through controlled experiments on BEA-2019 W&I+LOCNESS, JFLEG-based evaluation data, controlled synthetic error pairs, and leakage-safe identity examples.
The selected checkpoint is the Base Conservative 30% Identity model. It was chosen because it retained essentially the same ERRANT F0.5 as the strongest Base baseline while improving precision and materially reducing unnecessary edits on clean text.
Selected deployment model:
03c-base-conservative-30pct
Base architecture:google/flan-t5-base
Parameters: 247,577,856
Primary task: English grammar error correction / text-to-text generation
The selected model was evaluated using a held-out grammar-correction set plus an independent clean-text over-correction benchmark.
| Metric | Selected Model | What it measures |
|---|---|---|
| ERRANT F0.5 | 0.4527 | Precision-weighted grammatical error correction quality |
| Precision | 0.5053 | Fraction of proposed edits that are supported by the reference |
| Recall | 0.3195 | Fraction of reference edits recovered |
| GLEU | 0.7835 | Reference-based grammatical correction quality |
| Semantic similarity | 0.9384 | Meaning preservation between source and corrected text |
| Sentence accuracy | 0.0983 | Exact whole-sentence reference match |
| Clean over-correction rate | 25.73% | Clean sentences changed unnecessarily |
| Number preservation | 99.72% | Preservation of numbers and quantities |
| Named-entity preservation | 93.57% | Preservation of detected named entities |
| Technical-term preservation | 99.63% | Preservation of technical terminology |
| Average batched latency | 75.85 ms/item | Batched evaluation throughput per item |
| P95 batched latency | 152.94 ms/item | 95th-percentile batched evaluation latency |
| Evaluation component | Count |
|---|---|
| Combined evaluation records | 2,487 |
| Correction-bearing sentences | 1,088 |
| Clean sentences in metric partition | 1,399 |
| Dedicated leakage-safe clean benchmark | 988 |
The clean metric partition includes the dedicated 988-example clean benchmark plus identity/correct examples already present in the main held-out test data.
Multiple controlled fine-tuning experiments were run rather than assuming that a larger model or more aggressive balancing would automatically perform better.
| Model | ERRANT F0.5 | Precision | Recall | GLEU | Semantic Similarity | Clean Over-Correction |
|---|---|---|---|---|---|---|
| Small — 10% identity | 0.3961 | 0.4714 | 0.2416 | 0.7510 | 0.9620 | 29.16% |
| Small — 20% identity | 0.3939 | 0.4736 | 0.2354 | 0.7521 | 0.9606 | 26.38% |
| Small — 30% identity | 0.3926 | 0.4851 | 0.2228 | 0.7516 | 0.9645 | 23.30% |
| Base — 10% identity | 0.4530 | 0.4989 | 0.3311 | 0.7830 | 0.9359 | 29.38% |
| Base — 30% identity (selected) | 0.4527 | 0.5053 | 0.3195 | 0.7835 | 0.9384 | 25.73% |
Compared with Base 10%, the selected Base 30% model:
The cost was a modest recall reduction from 0.3311 to 0.3195.
This made Base 30% the stronger quality-versus-conservatism trade-off for the final portfolio model.
Increasing the proportion of identity/correct examples consistently reduced unnecessary edits in the Small-model ablation:
| Identity Ratio | ERRANT F0.5 | Clean Over-Correction |
|---|---|---|
| 10% | 0.3961 | 29.16% |
| 20% | 0.3939 | 26.38% |
| 30% | 0.3926 | 23.30% |
The Base experiment showed the same direction:
| Base Variant | ERRANT F0.5 | Precision | Clean Over-Correction |
|---|---|---|---|
| Base 10% | 0.4530 | 0.4989 | 29.38% |
| Base 30% | 0.4527 | 0.5053 | 25.73% |
This demonstrated that identity pressure improved conservatism without materially sacrificing the primary F0.5 score.
These are project-defined aspirational gates, not claims of external production certification.
| Gate | Target | Selected Model | Status |
|---|---|---|---|
| Semantic similarity | ≥ 0.90 | 0.9384 | ✅ Pass |
| Clean over-correction | ≤ 8% | 25.73% | ⚠️ Not met |
| Number preservation | ≥ 99.5% | 99.72% | ✅ Pass |
| Named-entity preservation | ≥ 98% | 93.57% | ⚠️ Not met |
| Technical-term preservation | ≥ 98% | 99.63% | ✅ Pass |
The model is therefore presented as a measured portfolio/research model, not as a production-certified grammar checker.
| Split / Property | Value |
|---|---|
| Final Base-30 training rows | 38,825 |
| Validation rows | 3,259 |
| Main held-out test rows | 1,499 |
| Dedicated clean benchmark | 988 |
| Identity/correct rows in Base-30 train | 11,348 |
| Identity ratio | ~30% |
| Primary training error categories | 61 |
The project uses:
The final audit reported zero source overlap between the training data and validation, test, and clean-test source sets.
The selected model was fine-tuned locally on an NVIDIA RTX 5090.
| Setting | Value |
|---|---|
| Base model | google/flan-t5-base |
| Epoch budget | 4 |
| Selected checkpoint | checkpoint-3000 |
| Learning rate | 1e-4 |
| Per-device train batch size | 8 |
| Gradient accumulation | 4 |
| Effective batch size | 32 |
| Gradient checkpointing | Enabled |
| BF16 | Enabled |
| TF32 | Enabled |
| Max input length | 384 |
| Balanced sampling | Disabled for selected run |
| Training dataset | 30% identity conservative set |
| Best validation loss | 1.00873 |
| Training duration | ~44.8 minutes |
Training and inference use the same instruction-style prompt:
Task:
Correct the grammar, spelling, punctuation, and wording of the text while preserving the original meaning.
Rules:
- Preserve the original meaning.
- Do not add unsupported information.
- Do not remove important details.
- Keep named entities, numbers, technical terms, and product names unchanged unless clearly incorrect.
- Return only the corrected text.
Input:
{source_text}
Corrected Text:
Consistent prompting prevents a training/inference format mismatch.
import torch
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
MODEL_ID = "anmol-unitmole/grammar-correction-flan-t5-base"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device)
model.eval()
text = "She go to the office every day and complete her reports."
prompt = f"""Task:
Correct the grammar, spelling, punctuation, and wording of the text while preserving the original meaning.
Rules:
- Preserve the original meaning.
- Do not add unsupported information.
- Do not remove important details.
- Keep named entities, numbers, technical terms, and product names unchanged unless clearly incorrect.
- Return only the corrected text.
Input:
{text}
Corrected Text:"""
inputs = tokenizer(
prompt,
return_tensors="pt",
truncation=True,
max_length=384,
).to(device)
with torch.inference_mode():
generated = model.generate(
**inputs,
max_new_tokens=192,
num_beams=4,
early_stopping=True,
)
correction = tokenizer.decode(generated[0], skip_special_tokens=True)
print(correction)
The selected PyTorch model was exported to ONNX and dynamically INT8-quantized as an engineering experiment.
| Runtime artifact | Total size |
|---|---|
| FP32 ONNX components | 2.334 GB |
| INT8 ONNX components | 1.075 GB |
| INT8 / FP32 size ratio | 46.05% |
| Approx. aggregate size reduction | 53.95% |
| Runtime | Exact Output Match | Average Latency |
|---|---|---|
| PyTorch path | Reference | 419.49 ms |
| INT8 ONNX path | 50% | 3343.95 ms |
The parity test used a different single-example validation path from the batched evaluation latency shown earlier, so those latency figures should not be directly compared across tables.
Deployment decision: the INT8 ONNX experiment is retained as optimization evidence, but it is not claimed as the validated production/browser runtime because output parity and measured runtime were not strong enough.
Measured strengths include:
Suitable for:
Do not use the model as the sole authority for:
Training and evaluation were executed locally using:
The broader project contains reusable workflows for:
Generated corrections can be incomplete, incorrect, overly aggressive, or meaning-changing.
Do not paste private, confidential, proprietary, customer, employee, or personally identifiable text into a public demonstration.
For important writing, review the original and corrected text before accepting changes.
This fine-tuned model is based on google/flan-t5-base, which is released under the Apache License 2.0. Users should also respect the licenses and usage terms of the datasets and other third-party resources used in the broader training/evaluation workflow.