A Frequency-Quantized HyperLogLog Autocorrection algorithm that also is dyslexia-friendly.
Project description
FQ-HLL
An improved Frequency-Quantized HyperLogLog (FQ-HLL) Autocorrection Library
For theoretical value, there is nothing in my algorithm that uses any information about the English language or the QWERTY keyboard, to do any of the corrections. It is a NON-ML algorithm too.
Usage
The library defaults to searching within its own folder before searching in your local directory. Visit my GitHub Repo for more details, but there are two text files offered as base dictionaries: 20k_shun4midx.txt and database.txt, with around 20000 and 400 words respectively. The below code would only visit the local directory. If no dictionary is specified, 20k_shun4midx.txt would be used instead.
What is returned is in the form of a dictionary, mapping each query to either a single string for autocorrect or a list of three strings for top3.
# ======== SAMPLE USAGE ======== #
from fq_hll import Autocorrector
if __name__ == "__main__":
ac = Autocorrector()
# File
ans1 = ac.autocorrect("test_files/typo_file.txt", "test_files/class_suggestions.txt")
print(ans1.suggestions)
print(ans1.scores)
ans2 = ac.top3("test_files/typo_file.txt", "test_files/class_suggestions.txt")
# Optionally, you can not want it to output it into a file, then:
# Individual strings
ans3 = ac.autocorrect("hillo")
ans4 = ac.top3("hillo")
# Arrays
ans5 = ac.autocorrect(["tsetign", "hillo", "goobye", "haedhpoesn"])
ans6 = ac.top3(["tsetign", "hillo", "goobye", "haedhpoesn"])
# You can even have a custom dictionary!
dictionary = ["apple", "banana", "grape", "orange"]
custom_ac = Autocorrector(dictionary)
ans7 = custom_ac.autocorrect(["applle", "banana", "banan", "orenge", "grap", "pineapple"])
ans8 = custom_ac.top3(["applle", "banana", "banan", "orenge", "grap", "pineapple"])
print(ans7.suggestions)
print(ans8.suggestions)
As a side note, compare.py and compare3.py, as files that are quite useful for comparing between intended outputs and actual outputs, can be used via
from fq_hll import compare
compare_files(suggestions, typos, answers)
or if we are doing Top 3 words selected per row,
from fq_hll import compare3
compare3_files(suggestions, typos, answers)
Results
More detail can be found in my GitHub Repo.
TL;DR it is way more accurate than traditional non-ML, non-language-specific algorithms such as BK-Tree and SymSpell and it also quite fast.
Remark on Keyboards
As a side note, I made the QWERTY keyboard (including AZERTY, QWERTZ, Colemak, Dvorak, or any other custom keyboard layout) as toggleable parameters to influence my FQ-HLL, since I am coding with Ducky to create an FQ-HLL Android keyboard. In this case, runtime slowed down by only 1 second for the 20k_shun4midx.txt file, but achieving accuracy of 64~65% and 80~81%, for the autocorrection and top 3 results respectively. However, the main takeaway of this repository is how strong FQ-HLL is without the knowledge of a keyboard layout, which is why I make it something that can be turned off, and most results woud be dedicated to that.
Notice, these keyboards are accessible in Python for example via:
ac = Autocorrection(keyboard="qwerty")
or
ac = Autocorrection(keyboard=["custom_row1", "custom_row2", etc])
Notes
- HLL naturally doesn't have Local Differential Privacy (LDP) yet, but has natural obfuscation.
- This library does not collect personal data. However, still use it at your own discretion.
Dyslexia
Personally, I've always had an interest in autocorrect because I'm dyslexic and often unintentionally scramble or reverse letters when I read. Here are my thoughts about this algorithm based on my dyslexia.
- Reasoning would be more detailed in the
algo_description/description.pdffile in my GitHub Repo, but I find this algorithm's autocorrection suggestions are sometimes more intuitive (e.g. "sklof" -> "folks") to my dyslexia than other Levenshtein distance-based autocorrection models. - As a side note, as a dyslexic person, I naturally process words similar to how the FQ-HLL algorithm processes words, and that was my intuition in terms of how to create this algorithm in the first place.
Project details
Release history Release notifications | RSS feed
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 fq_hll-1.2.9.tar.gz.
File metadata
- Download URL: fq_hll-1.2.9.tar.gz
- Upload date:
- Size: 87.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbbe12c279dc2898060183c80613af619e6612584ff5ab3844be6b7834db45ac
|
|
| MD5 |
07f486a3af5720d5b390ff197b682492
|
|
| BLAKE2b-256 |
d1906dbe11195feb47aac522aada852cd7b47b1316a1659a5b7c96fb0ba30241
|
File details
Details for the file fq_hll-1.2.9-py3-none-any.whl.
File metadata
- Download URL: fq_hll-1.2.9-py3-none-any.whl
- Upload date:
- Size: 91.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
040949556826f8510feba568598fab026a4d6c0e4e6a4f13b96f0685f2206735
|
|
| MD5 |
96eb2a64512ab4f42bfbe0499e17e92c
|
|
| BLAKE2b-256 |
8254a9e32f28be9ebc42f8333cc6970e8912fb2c77042d62ad0f69d978696cd8
|