MedSpellChecker
Fast and effective tool for correcting spelling errors in Russian medical texts. The tool takes the raw medical text and returns the corrected text in lemmatized form.
This project is in its final stages. If you have found a bug or would like to improve something, please create an issue or pull request.
How to install
The project is written in Python 3.9 and works on Python version 3.9 or higher.
-
From the pip repository
pip install medspellchecker
-
Or from the sources
- Install requirements
pip install -r requirements.txt
- Install the package
pip install .
- Install requirements
Note! MedSpellChecker has the editdistpy package as a dependency. To install it you will need Microsoft Visual C++ 14 (for Windows) or build-essential package (for Linux).
How to use
An example of using the `medspellchecker' is shown below.
from medspellchecker.tool.medspellchecker import MedSpellchecker
from medspellchecker.tool.distilbert_candidate_ranker import RuDistilBertCandidateRanker
candidate_ranker = RuDistilBertCandidateRanker()
spellchecker = MedSpellchecker(candidate_ranker)
fixed_text = spellchecker.fix_text(
"У больногодиагностирован инфркт и тубркулез"
)
print(fixed_text)
# -> "У больной диагностировать инфаркт и тубркулез"
- The first two lines import the main class of the package.
- Lines 3 and 4 then import one of the three available classes to rank the edit candidates.
- Line 6 creates an instance of the candidate ranking class based on the fine-tuned DistilBert model.
- Line 7 creates an instance of the class to correct spelling errors.
- On line 8, the
fix_textmethod is called, which takes the raw text and returns the corrected text. - Finally line 10 prints the corrected result, which looks like "У больной диагностировать инфаркт и тубркулез".
- In this way, the package can be used to correct spelling errors in Russian medical texts in a few lines.
Tips for using the tool
- Initiate and create MedSpellchecker class once. And then use it many times to correct Russian medical texts.
- The tool must be used before all the preprocessing steps. This way the various preprocessing steps cannot affect the result of the tool correction.
- Nevertheless, the input raw text must be cleared of all sorts of tags, technical symbols and other trash. The input text should be plain text without any structure.
- Before using the tool on the whole dataset, test how it works on a small chunk to choose the best available candidate ranker.
- If the available candidate rankers do not perform well enough, consider fine-tuning the BERT-based model on your dataset and using the candidate ranker on the fine-tuned model. The quality of the corrections should improve.
Internals
MedSpellChecker uses the SymDel algorithm to speed up the generation of correction candidates, and a fine-tuned BERT-based machine learning model to rank candidates and select the best fit.
This architecture allows each component to be developed almost independently and the correction process to be implemented flexibly.
- Spellchecker Manager - responsible for coordinating other components and implementing high-level logic.
- Preprocessor and PostProcessor - responsible for splitting the incoming text and assembling the result.
- Dictionary - contains a dictionary of correct words, which allows to check the correct word or not.
- Edit Distance Index - allows to optimize and speed up the calculation of the editing distance required to generate candicates for fixing an incorrect word.
- Error Model - responsible for generating candidates for fixing incorrect words.
- Language Model - based on the fine-tuned BERT-based model, ranks candidates for fixing and selects the most suitable word for correction.
Supported Candidate Rankers
Candidate rankers rank the candidates to replace the incorrect word and choose the most appropriate one.
The tool contains several rankers based on different BERT-based models.
However, the list of supported rankers can easily be extended with rankers based on any other approach and models.
It is sufficient to implement the AbstractCandidateRanker interface.
Available rankers out of the box:
RuRobertaCandidateRankerbased on DmitryPogrebnoy/MedRuRobertaLarge modelRuDistilBertCandidateRankerbased on DmitryPogrebnoy/MedDistilBertBaseRuCased modelRuBertTiny2CandidateRankerbased on DmitryPogrebnoy/MedRuBertTiny2 modelRuBioRobertCandidateRankerbased on alexyalunin/RuBioRoBERTa modelRuBioBertCandidateRankerbased on alexyalunin/RuBioBERT model
More information
This project is part of master's thesis. The current state is the result of the first year of work. More details about MedSpellCHecker you can find in the text of the term report .
Metadata
Release files for medspellchecker 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| medspellchecker-0.0.4.tar.gz | 1.4 MB | Without provenance | Details for medspellchecker-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| medspellchecker-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for medspellchecker-0.0.4-py3-none-any.whl |
Total release size: 2.8 MB
Release files / medspellchecker-0.0.4.tar.gz
| Download URL | medspellchecker-0.0.4.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2a73617925ba6619dab0f857af29834289bab7afb312604ff7ac0c619b44e65
|
|
BLAKE2b-256 checksum How to use checksums |
352bc5dec150e297b5cc4d95b8a92eae4c2fe5f8de46f712bea44922e7c95eb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Release files / medspellchecker-0.0.4-py3-none-any.whl
| Download URL | medspellchecker-0.0.4-py3-none-any.whl |
|---|---|
| Size | 1.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d8d9c6875a9fc56dc85f541bd5fab180efd06a4281a05e74012b8a505d15930
|
|
BLAKE2b-256 checksum How to use checksums |
6aab3bcdaf337bf8a49f54fa3dc708bfef8532778b1335bae12b82c1a44d3f8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Security for medspellchecker 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.