# shibing624/pycorrector

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/shibing624-pycorrector).**

6,473 stars · 1,160 forks · Python · Apache-2.0

## Links

- GitHub: https://github.com/shibing624/pycorrector
- Homepage: https://www.mulanai.com/product/corrector/
- awesome-repositories: https://awesome-repositories.com/repository/shibing624-pycorrector.md

## Topics

`csc` `error-correction` `error-detection` `kenlm` `macbert4csc` `pycorrector` `spelling-errors` `t5`

## Description

pycorrector is an open-source toolkit for detecting and correcting spelling and grammar errors in Chinese text. It combines multiple correction approaches, including rule-based methods using Kenlm n-gram language models and confusion sets, as well as deep learning correctors built on BERT, GPT, and T5 models. The toolkit also provides a command-line interface for batch processing Chinese text files with configurable detection and output options.

The project distinguishes itself by offering a range of correction strategies that can be mixed and matched. Rule-based correction uses character-level perplexity scoring from a language model to detect errors, then evaluates phonetic and shape-similar features to suggest fixes. Deep learning correctors handle more complex cases, with BERT-based models for character-level errors, GPT-based models for phonetic and grammatical mistakes, and T5 sequence-to-sequence models for length-mismatched grammar errors like missing or extra characters. The toolkit also supports pinyin-to-character conversion and bidirectional traditional-simplified Chinese character conversion.

Beyond the core correction pipeline, pycorrector provides tools for model training, evaluation, and customization. Users can fine-tune pretrained language models on their own labeled datasets to create domain-specific correctors, and measure accuracy through precision, recall, and F1 scores at both character and sentence levels. The correction behavior is configurable through custom word lists, confusion character sets, mapping tables, and detection sensitivity thresholds. The project supports loading custom Kenlm language models and pretrained correction model checkpoints from HuggingFace.

## Tags

### Artificial Intelligence & ML

- [Error Correction Toolkits](https://awesome-repositories.com/f/artificial-intelligence-ml/chinese-language-model-toolkits/error-correction-toolkits.md) — Provides a comprehensive open-source toolkit for detecting and correcting spelling and grammar errors in Chinese text.
- [Confusion Set Matchers](https://awesome-repositories.com/f/artificial-intelligence-ml/confused-word-detection/confusion-set-matchers.md) — Replaces characters or words by looking them up in hand-curated phonetic, shape-similar, or custom mapping tables.
- [Chinese Error Correction Models](https://awesome-repositories.com/f/artificial-intelligence-ml/large-language-models/chinese-language-model-repositories/bert-variants/chinese-error-correction-models.md) — Ships a fine-tuned BERT model for detecting and correcting character-level spelling errors in Chinese text.
- [N-Gram Language Models](https://awesome-repositories.com/f/artificial-intelligence-ml/natural-language-processing/word-embeddings/skip-gram-model-architectures/n-gram-language-models.md) — Scores candidate corrections by their perplexity under a Kenlm n-gram language model to rank and select the best fix.
- [Chinese Spelling Correctors](https://awesome-repositories.com/f/artificial-intelligence-ml/natural-language-processing/word-embeddings/skip-gram-model-architectures/n-gram-language-models/chinese-spelling-correctors.md) — Provides a rule-based corrector using Kenlm n-gram language models for phonetic and shape-similar character errors.
- [Phonetic Homophone Correction](https://awesome-repositories.com/f/artificial-intelligence-ml/phonetic-homophone-correction.md) — Replaces characters that sound alike but are wrong using a confusion set of homophones to fix common misspellings. ([source](https://github.com/shibing624/pycorrector/wiki/pycorrector%E6%BA%90%E7%A0%81%E8%A7%A3%E8%AF%BB-%E8%A7%84%E5%88%99%E6%96%B9%E6%B3%95))
- [Perplexity-Based Error Detectors](https://awesome-repositories.com/f/artificial-intelligence-ml/sequence-modeling/character-level-models/perplexity-based-error-detectors.md) — Detects erroneous character positions by comparing character-level perplexity scores against a tunable threshold from a language model.
- [Chinese Spelling Correctors](https://awesome-repositories.com/f/artificial-intelligence-ml/spelling-correction/chinese-spelling-correctors.md) — Corrects Chinese spelling mistakes using statistical and neural models for phonetic and shape-similar errors. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Shape-Similar Error Correctors](https://awesome-repositories.com/f/artificial-intelligence-ml/spelling-correction/shape-similar-error-correctors.md) — Replaces characters that look alike but are wrong using a confusion set of visually similar glyphs. ([source](https://github.com/shibing624/pycorrector/wiki/pycorrector%E6%BA%90%E7%A0%81%E8%A7%A3%E8%AF%BB-%E8%A7%84%E5%88%99%E6%96%B9%E6%B3%95))
- [Text Error Detection APIs](https://awesome-repositories.com/f/artificial-intelligence-ml/text-error-detection-apis.md) — Provides APIs that identify error positions and types in text without performing correction. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Chinese Error Detection APIs](https://awesome-repositories.com/f/artificial-intelligence-ml/text-error-detection-apis/chinese-error-detection-apis.md) — Implements APIs that detect erroneous characters in Chinese text and return their positions and error types. ([source](https://github.com/shibing624/pycorrector/blob/master/README_EN.md))
- [Custom Model Training](https://awesome-repositories.com/f/artificial-intelligence-ml/custom-model-training.md) — Supports fine-tuning pretrained language models on user-annotated datasets to adapt error correction to specific domains. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Error Correction Model Training](https://awesome-repositories.com/f/artificial-intelligence-ml/custom-model-training/error-correction-model-training.md) — Supports fine-tuning pretrained language models on labeled Chinese text pairs to produce custom error correctors. ([source](https://github.com/shibing624/pycorrector/blob/master/examples/macbert/README.md))
- [T5 Correction Model Predictions](https://awesome-repositories.com/f/artificial-intelligence-ml/end-to-end-training-pipelines/training-correctness-validators/t5-correction-model-predictions.md) — Provides a trained T5 model that corrects Chinese text and annotates errors in the output. ([source](https://github.com/shibing624/pycorrector/blob/master/examples/t5/README.md))
- [Pretrained Model Loading](https://awesome-repositories.com/f/artificial-intelligence-ml/natural-language-processing/language-model-pretraining/pretrained-model-loading.md) — Loads pretrained correction model checkpoints from HuggingFace for Chinese text error correction without retraining. ([source](https://github.com/shibing624/pycorrector/blob/master/examples/macbert/README.md))
- [Custom Language Model Correctors](https://awesome-repositories.com/f/artificial-intelligence-ml/spelling-correction/custom-language-model-correctors.md) — Loads a user-supplied Kenlm language model to tailor spelling correction to a specific domain. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Error Correction Model Training](https://awesome-repositories.com/f/artificial-intelligence-ml/text-model-training/error-correction-model-training.md) — Provides training scripts for BERT models on paired error-correction data to learn character-level corrections. ([source](https://github.com/shibing624/pycorrector/wiki))

### Part of an Awesome List

- [Chinese Error Correction Models](https://awesome-repositories.com/f/awesome-lists/ai/model-implementations/gpt-implementations/chinese-error-correction-models.md) — Ships GPT-based correctors (ChatGLM3, Qwen2.5) for detecting and fixing phonetic and grammatical errors in Chinese.
- [Chinese Error Correction Models](https://awesome-repositories.com/f/awesome-lists/ai/model-training-and-fine-tuning/model-fine-tuning/chinese-error-correction-models.md) — Uses a fine-tuned BERT model to predict and correct character-level errors in Chinese text input. ([source](https://github.com/shibing624/pycorrector/wiki/%E8%AE%AD%E7%BB%83BERT%E6%A8%A1%E5%9E%8B))
- [Transformer Fine-Tuning](https://awesome-repositories.com/f/awesome-lists/ai/model-training-and-fine-tuning/pretrained-checkpoint-fine-tuning/transformer-fine-tuning.md) — Fine-tunes encoder-decoder or decoder-only transformer models on paired error-correction data for sequence-level text correction.
- [Chinese Error Correction Models](https://awesome-repositories.com/f/awesome-lists/ai/sequence-to-sequence-models/chinese-error-correction-models.md) — Ships a T5 sequence-to-sequence corrector for handling length-mismatched grammar errors in Chinese text.
- [N-Gram Frequency Rankers](https://awesome-repositories.com/f/awesome-lists/ai/language-detection/n-gram-detection/n-gram-frequency-rankers.md) — Ranks candidate corrections by counting character n-gram frequencies in a corpus without requiring word segmentation.

### Content Management & Publishing

- [Deep Learning Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/deep-learning-correctors.md) — Employs end-to-end deep learning models like RNN, CRF, and transformers to automatically fix errors in Chinese text. ([source](https://github.com/shibing624/pycorrector/blob/master/docs/correction_solution.md))
- [Built-In Language Model Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/grammatical-error-corrections/built-in-language-model-correctors.md) — Corrects Chinese text errors using built-in language models for phonetic, shape-similar, and grammatical mistakes. ([source](https://github.com/shibing624/pycorrector/blob/master/README_EN.md))
- [Multi-Model Chinese Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/grammatical-error-corrections/multi-model-chinese-correctors.md) — Combines rule-based, statistical, and deep learning models to correct Chinese text errors. ([source](https://github.com/shibing624/pycorrector/wiki/TODO))
- [Rule-Based Chinese Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/rule-based-chinese-correctors.md) — Detects misspelled characters via language model perplexity and corrects them using phonetic and shape-similar features. ([source](https://github.com/shibing624/pycorrector/blob/master/docs/correction_solution.md))
- [Automated Text Corrections](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections.md) — Runs batch text correction on a file from the terminal using a language model, with options to control output detail and character detection. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Batch Text Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/batch-text-correctors.md) — Runs batch Chinese text correction on a file from the terminal with configurable output and detail level. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [Chinese Grammar Error Corrections](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/grammatical-error-corrections/chinese-grammar-error-corrections.md) — Corrects Chinese grammar errors like missing or extra characters using sequence-to-sequence models. ([source](https://cdn.jsdelivr.net/gh/shibing624/pycorrector@master/README.md))
- [GPT-Based Chinese Correctors](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/grammatical-error-corrections/gpt-based-chinese-correctors.md) — Ships a GPT-based corrector that detects and fixes phonetic, shape-similar, and grammatical errors in Chinese sentences. ([source](https://github.com/shibing624/pycorrector/blob/master/examples/gpt/README.md))
- [N-Gram Language Model Corrections](https://awesome-repositories.com/f/content-management-publishing/automated-text-corrections/grammatical-error-corrections/n-gram-language-model-corrections.md) — Scores candidate corrections with a Kenlm n-gram language model to detect and fix ungrammatical sequences. ([source](https://github.com/shibing624/pycorrector/wiki/pycorrector%E6%BA%90%E7%A0%81%E8%A7%A3%E8%AF%BB-%E8%A7%84%E5%88%99%E6%96%B9%E6%B3%95))

### Business & Productivity Software

- [Batch Text Correctors](https://awesome-repositories.com/f/business-productivity-software/task-workflow-automation/productivity-task-management/productivity-tools/command-line/command-line-typo-correction/batch-text-correctors.md) — Provides a command-line interface for batch processing Chinese text files with configurable correction options.

### Data & Databases

- [Pinyin-to-Text Converters](https://awesome-repositories.com/f/data-databases/pinyin-transliterations/pinyin-to-text-converters.md) — Converts pinyin input to the most likely Chinese character sequence using a statistical language model and n-gram frequency counts.

### Testing & Quality Assurance

- [Correction Accuracy Evaluators](https://awesome-repositories.com/f/testing-quality-assurance/model-evaluation-benchmarks/correction-accuracy-evaluators.md) — Provides evaluation tools to measure precision, recall, and F1 scores of correction models on benchmark test sets. ([source](https://github.com/shibing624/pycorrector/blob/master/examples/macbert/README.md))
