CoolFace
Apppublic

NicoleMathias/grammer-error-correction

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

Multilingual Grammar Error Detection & Correction

A powerful web application for detecting and correcting grammar errors in multiple languages using state-of-the-art AI models.

๐ŸŒ Supported Languages

  • โ€”English - Error detection + Grammar correction
  • โ€”Czech - Error detection only
  • โ€”German - Error detection only
  • โ€”Italian - Error detection only
  • โ€”Swedish - Error detection only

โœจ Features

  • โ€”๐Ÿ” Grammar Error Detection: Identifies grammar errors with confidence scores
  • โ€”โœ๏ธ Grammar Correction: Corrects errors (English only)
  • โ€”๐ŸŒ Multilingual Support: 5 languages with specialized models
  • โ€”๐ŸŽจ Modern UI: Clean, responsive web interface
  • โ€”๐Ÿ”ง REST API: Full API for integration
  • โ€”๐Ÿ“Š Detailed Analysis: Error statistics and confidence scores

๐Ÿš€ Quick Start

Local Development

bash
# Clone the repository
git clone <your-repo-url>
cd automatic_grammar_error_correction

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

# Open http://localhost:7860

Hugging Face Spaces Deployment

See README_HF_SPACES.md for detailed deployment instructions.

๐Ÿ”ง API Endpoints

EndpointMethodDescription
/GETWeb interface
/api/healthGETHealth check
/api/languagesGETAvailable languages
/api/detectPOSTError detection
/api/correctPOSTGrammar correction
/api/analyzePOSTCombined analysis

Example API Usage

bash
# Error Detection
curl -X POST http://localhost:7860/api/detect \
  -H "Content-Type: application/json" \
  -d '{"text": "I goes to the store", "language_code": "en"}'

# Grammar Correction
curl -X POST http://localhost:7860/api/correct \
  -H "Content-Type: application/json" \
  -d '{"text": "I goes to the store", "language_code": "en"}'

๐Ÿ“Š Model Information

  • โ€”T5 Model: Grammar correction (English only)
  • โ€”BERT Models: Error detection for each language
  • โ€”English: FCE dataset
  • โ€”Czech: GECCC dataset
  • โ€”German: Falko-Merlin dataset
  • โ€”Italian: Merlin dataset
  • โ€”Swedish: SWELL dataset

๐ŸŽฏ Language Capabilities

LanguageError DetectionGrammar CorrectionModel
Englishโœ… Yesโœ… YesFCE
Czechโœ… YesโŒ NoGECCC
Germanโœ… YesโŒ NoFalko-Merlin
Italianโœ… YesโŒ NoMerlin
Swedishโœ… YesโŒ NoSWELL

๐Ÿ› ๏ธ Technology Stack

  • โ€”Backend: Flask (Python)
  • โ€”AI Models: Transformers (BERT, T5)
  • โ€”Frontend: HTML, CSS, JavaScript
  • โ€”Deployment: Docker, Hugging Face Spaces
  • โ€”Dependencies: PyTorch, Transformers, NumPy

๐Ÿ“ Project Structure

automatic_grammar_error_correction/
โ”œโ”€โ”€ app.py                 # Main Flask application
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ multilingual.html  # Web interface
โ”œโ”€โ”€ models/                # BERT models for each language
โ”œโ”€โ”€ t5_jfleg/             # T5 model for correction
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ Dockerfile            # Docker configuration
โ””โ”€โ”€ README_HF_SPACES.md   # Deployment guide

๐Ÿ” Usage Examples

Web Interface

  1. 1.Select your language from the dropdown
  2. 2.Enter text to analyze
  3. 3.Choose an action:
  4. 4.Detect Errors: Find grammar errors
  5. 5.Correct Grammar: Fix errors (English only)
  6. 6.Full Analysis: Both detection and correction

API Response Examples

Error Detection:

json
{
  "accuracy": 0.806,
  "avg_confidence": 0.921,
  "dataset": "FCE",
  "tokens": [
    {"token": "I", "tag": "c", "confidence": 0.95},
    {"token": "goes", "tag": "i", "confidence": 0.86}
  ]
}

Grammar Correction:

json
{
  "success": true,
  "corrected_text": "I go to the store",
  "original_text": "I goes to the store"
}

๐Ÿšจ Troubleshooting

Common Issues

  1. 1.Model Loading: First run may take time to download models
  2. 2.Memory: Models require significant RAM (~2GB)
  3. 3.Port Conflicts: App uses port 7860 by default

Health Check

bash
curl http://localhost:7860/api/health

๐Ÿ“ˆ Performance

  • โ€”Error Detection: ~80-85% accuracy across languages
  • โ€”Grammar Correction: ~90% accuracy for English
  • โ€”Response Time: 1-3 seconds per request
  • โ€”Model Size: ~2GB total

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.Test thoroughly
  5. 5.Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿ™ Acknowledgments

  • โ€”Hugging Face for the Transformers library
  • โ€”The research teams behind the fine-tuned models
  • โ€”The open-source community for various tools and libraries

Ready for deployment! ๐Ÿš€

For deployment instructions, see README_HF_SPACES.md.