Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- grammar-correction
|
| 7 |
+
- gec
|
| 8 |
+
- flan-t5
|
| 9 |
+
- seq2seq
|
| 10 |
+
pipeline_tag: text2text-generation
|
| 11 |
+
widget:
|
| 12 |
+
- text: "grammar: She go to school yesterday."
|
| 13 |
+
example_title: "Verb Tense Correction"
|
| 14 |
+
- text: "grammar: He don't likes playing football."
|
| 15 |
+
example_title: "Subject-Verb Agreement"
|
| 16 |
+
- text: "grammar: I has a meeting tomorrow."
|
| 17 |
+
example_title: "Auxiliary Verb"
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# AI Grammar Correction — Fine-tuned FLAN-T5
|
| 21 |
+
|
| 22 |
+
## Model Description
|
| 23 |
+
This is a sequence-to-sequence transformer model fine-tuned for **Grammatical Error Correction (GEC)** based on [`google/flan-t5-base`](https://huggingface.co/google/flan-t5-base).
|
| 24 |
+
|
| 25 |
+
It automatically detects and corrects grammatical, syntactical, and stylistic errors in English sentences, returning fluent, natural corrections.
|
| 26 |
+
|
| 27 |
+
## Task Details
|
| 28 |
+
- **Task**: Grammatical Error Correction (GEC)
|
| 29 |
+
- **Base Architecture**: `google/flan-t5-base`
|
| 30 |
+
- **Input Prefix**: `"grammar: <input_text>"`
|
| 31 |
+
- **Max Sequence Length**: 128 tokens
|
| 32 |
+
|
| 33 |
+
## Dataset Specifications
|
| 34 |
+
Fine-tuned on a curated dataset of **100,000 sentence pairs**:
|
| 35 |
+
- **Train Set**: 80,000 pairs (80%)
|
| 36 |
+
- **Validation Set**: 10,000 pairs (10%)
|
| 37 |
+
- **Test Set**: 10,000 pairs (10%)
|
| 38 |
+
|
| 39 |
+
## Evaluation Results (10,000 Unseen Test Examples)
|
| 40 |
+
|
| 41 |
+
| Metric | Test Score |
|
| 42 |
+
| :--- | :--- |
|
| 43 |
+
| **BLEU** | `0.6869` |
|
| 44 |
+
| **GLEU** | `0.8311` |
|
| 45 |
+
| **ROUGE-1** | `0.8819` |
|
| 46 |
+
| **ROUGE-2** | `0.7698` |
|
| 47 |
+
| **ROUGE-L** | `0.8748` |
|
| 48 |
+
| **Exact Match Accuracy** | `0.0886` |
|
| 49 |
+
| **Word Accuracy** | `0.5018` |
|
| 50 |
+
|
| 51 |
+
## How to Use
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import torch
|
| 55 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 56 |
+
|
| 57 |
+
MODEL_ID = "anuvid/ai-grammar-correction-model"
|
| 58 |
+
|
| 59 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 60 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
|
| 61 |
+
|
| 62 |
+
text = "She go to school yesterday."
|
| 63 |
+
inputs = tokenizer(f"grammar: {text}", return_tensors="pt")
|
| 64 |
+
|
| 65 |
+
outputs = model.generate(**inputs, max_length=128, num_beams=4, early_stopping=True)
|
| 66 |
+
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 67 |
+
|
| 68 |
+
print("Original :", text)
|
| 69 |
+
print("Corrected:", corrected_text)
|
| 70 |
+
# Output: "She went to school yesterday."
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
## Example Corrections
|
| 74 |
+
|
| 75 |
+
| Original Input | Model Output |
|
| 76 |
+
| :--- | :--- |
|
| 77 |
+
| `She go to school yesterday.` | `She went to school yesterday.` |
|
| 78 |
+
| `He don't likes playing football.` | `He doesn't like playing football.` |
|
| 79 |
+
| `I has a meeting tomorrow.` | `I have a meeting tomorrow.` |
|
| 80 |
+
| `They was going to the market.` | `They were going to the market.` |
|
| 81 |
+
| `This are a very good book.` | `This is a very good book.` |
|