Grammar error correction backend with Triton and FastAPI/ GRPC integration
Project description
If you find this project useful, please give it a ⭐ — and contributions are always welcome! 🤗
Grammared Language 🚀
✨ Adding Grammarly (and other) open source models to LanguageTool ✨
Demo 🎬
Try it live: https://grammared-language-demo.rayliu.ca/v2 🌐
⚠️ Heads up: Demo server is running on an Oracle ARM CPU server. It might be a bit slow—patience is a virtue! 🐢
Overview 📝
LanguageTool is a fantastic open-source grammar and spell-checking tool that mostly uses deterministic rules (with a sprinkle of n-grams).
One of the most common requests is to add support for smarter, self-hosted, AI/ML-based models. While not documented, LanguageTool does support remote correction servers via gRPC (see GRPCRule), configured by the remoteRulesFile option in the server.properties config file.
This project is that missing remote server! It connects LanguageTool to open-source grammatical error correction models—mainly Grammarly's GECToR and CoEdIT—because they're fast, open, and get the job done. 💪
Limitations ⚠️
- All corrections show up as "grammar" corrections (LanguageTool doesn't use the categories from remote servers)
- No paraphrasing support (LanguageTool clients use a hardcoded rewrite server URL)
Supported Models 🧠
GECToRmodels from gotutiyan/gectortext2text-generationmodels (e.g., Grammarly's CoEdIT)
Quick Start ⚡
Model Config
Config File
Check out model_config.yaml or docker/default_model_config.yaml for a template:
gector_deberta_large:
type: gector
backend: triton
serving_config:
triton_host: triton-server
triton_port: 8001
pretrained_model_name_or_path: "gotutiyan/gector-deberta-large-5k"
triton_model_name: gector_deberta_large
device: cuda # cpu, cuda, or auto
Environment Variable
Or set things up with environment variables (see demo-docker-compose.yml for real-world examples):
# See the 'environment:' section in demo-docker-compose.yml for full model config via env vars
# Example:
GRAMMARED_LANGUAGE__MODELS__GECTOR_DEBERTA_LARGE__TYPE=gector
GRAMMARED_LANGUAGE__MODELS__GECTOR_DEBERTA_LARGE__BACKEND=triton
GRAMMARED_LANGUAGE__MODELS__GECTOR_DEBERTA_LARGE__SERVING_CONFIG__TRITON_HOST=triton-server
...
For more details, see the comments in grammared_language/utils/config_parser.py.
LanguageTool Integration 🛠️
To enable remote servers with LanguageTool, you'll need a remote rule config file. Point to it with the remoteRulesFile option in your server.properties file:
How config loading works 🧩
When the service starts, it loads model configuration in this order:
- If
/model_config.yamlexists, it loads that. - If not, and environment variables starting with
GRAMMARED_LANGUAGE__are set, it loads config from those (seedemo-docker-compose.yml). - If neither is found, it falls back to
/default_model_config.yaml.
See the get_config function in grammared_language/utils/config_parser.py for the nitty-gritty.
🚢 Start everything with Docker Compose:
docker-compose up --build
This runs Triton, the API, and (optionally) LanguageTool with remote rules. Easy!
Requirements 📦
- Python 3.11+
- Docker (for containers)
- Triton Inference Server (for model serving)
- See
pyproject.tomlfor more
Usage 🏃
LanguageTool Integration
To use remote servers with LanguageTool:
-
Set up a remote rule config file (see
example_language_tool_configs/remote-rule-config.json). -
Add this to your
server.properties:remoteRulesFile=./remote-rule-config.json -
Run:
java -cp languagetool-server.jar org.languagetool.server.HTTPServer --config server.properties
With Dockerized LanguageTool 🐳
If you're using the meyay/languagetool or erikvl87/languagetool Docker images, set:
```
langtool_remoteRulesFile=<remote file config path in docker>
```
See docker-compose.yml for a full example.
Troubleshooting 🛠️
- Model loading or inference errors? Check Triton and API logs.
- LanguageTool not working? Double-check your remote rule config is correct and accessible.
License 📄
See LICENSE.md.
Vibe Coding Notice 🎨
- One key learning objective of this project is to explore the use of various vibe coding models and tools
- which is probably why you might see the code quality to be a bit patchy
- Bugs and rough edges are expected, use at your own risk
Credits & References 🙏
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grammared_language-0.1.1.tar.gz.
File metadata
- Download URL: grammared_language-0.1.1.tar.gz
- Upload date:
- Size: 45.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d613225746460599efeb97286e04feb8663722d99ba6b164ec84aa54ac9cbe9
|
|
| MD5 |
843462f5b5703187f4a1f38a3776aebf
|
|
| BLAKE2b-256 |
3244e47651b16ad33878e289dacb1867b333d9a78c1f807a7ee34b4da3027496
|
File details
Details for the file grammared_language-0.1.1-py3-none-any.whl.
File metadata
- Download URL: grammared_language-0.1.1-py3-none-any.whl
- Upload date:
- Size: 59.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6f071c0489c5d4fb3c935b61770ba8ab642e8e5037ddfc53caa7e77dff2567e
|
|
| MD5 |
93fabc5ee62d25a3abc77c34bbc503ca
|
|
| BLAKE2b-256 |
ef82056c89f19ae2357c0641dab4c74b348b6bd2c9b8fd1ca98b287632d5c75a
|