Detects gibberish or mischievous chat messages/string.
Project description
gibberish-chat-detector
gibberish-chat-detector is a lightweight Python package that detects gibberish or mischievous chat messages using a set of interpretable, rule-based heuristics. Machine learning approach generally won't work well given there are often special definition of what is considered gibberish in specific application. This detector give you full flexibility and transparence about what to detect. It is particularly useful for filtering low-quality user input in chat systems, collaborative platforms, or educational environments.
🔍 How It Works
The core detection logic is based on a suite of handcrafted textual features and a set of six transparent rules. If any rule triggers, the message is flagged as gibberish.
The detection is deterministic, fast, and doesn't rely on machine learning — making it interpretable and easily customizable.
📥 Input and 📤 Output
Input
The main function accepts a single string:
detect_gibberish_chat(s: str)
s— A chat message or short text (e.g.,"hellooooooo!!!!")
Output
The function returns a dictionary containing:
- A top-level
gibberishflag:1(True) or0(False) - A collection of interpretable features
Example:
{
'gibberish': 1,
'repeated_letter_ratio': 0.73,
'repeat_punct': 8,
'repeat_group_ratio': 0.0,
'max_token_length': 12,
'avg_token_length': 5.2,
'token_count': 3,
'std_token_length': 2.3,
'total_char_count': 19,
'unique_char_count': 8,
'letter_token_ratio': 0.12,
'entropy_letter': 1.44,
'entropy_character': 2.10
}
✨ Features Used
The detector computes the following per-message features:
| Feature Name | Description |
|---|---|
repeated_letter_ratio |
Ratio of repeated single characters (e.g., aaa, 111) to total alphanumeric characters |
repeat_group_ratio |
Ratio of repeated character groups (e.g., abcabcabc) |
repeat_punct |
Count of repeated non-alphanumeric symbols (e.g., !!! or ???) |
letter_token_ratio |
Ratio of alphabetic characters to all characters |
token_count |
Number of tokens (split by whitespace) |
avg_token_length |
Average length of tokens |
std_token_length |
Standard deviation of token lengths |
max_token_length |
Length of the longest token |
unique_char_count |
Count of unique non-space characters |
total_char_count |
Count of all non-space characters |
entropy_letter |
Entropy of alphabetic characters |
entropy_character |
Entropy of all characters |
✅ Example Usage
from gibberish_chat_detector import detect_gibberish_chat
text = "l;kjasdf;lkjasdf;lkj!!!!"
result = detect_gibberish_chat(text)
print(result['gibberish'])
🛠 Customizing the Rules
By default, the detector uses six interpretable rules based on the above features. For example:
(repeated_letter_ratio >= 0.5 and max_token_length >= 6)
You can customize the rules by modifying the rule section in detector.py, or refactor it to load thresholds dynamically from a config file or function argument.
📦 Installation
pip install gibberish-chat-detector
Requires Python 3.7+.
🔓 License
MIT License
👨💻 Author
Developed by Jiangang Hao
💡 Contributing
Got ideas for new features or more precise rules? Contributions are welcome — open a PR or issue!
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 gibberish_chat_detector-0.1.0.tar.gz.
File metadata
- Download URL: gibberish_chat_detector-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d08ebf2f6a841f081cae9ef6403ba2eeb619f1d4ae5ce9fe7a4a964a68d34431
|
|
| MD5 |
0037d2458e8f3dffc5200ad3036c26d2
|
|
| BLAKE2b-256 |
2a92818e0638c7c0401990ada37e7c2f610864a4ee9dcae758624cdbd955e2b6
|
File details
Details for the file gibberish_chat_detector-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gibberish_chat_detector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd7d6e9cdd36f95bcd35eee2ee67d42e0082e2cd0a1969d0c553dad074b792a1
|
|
| MD5 |
2bca18347b2336ef762fb038621a7cd2
|
|
| BLAKE2b-256 |
c0b8f3e0048445d073787b0c2724ed76c19f440eda8e07adb28c63667653295a
|