Skip to main content

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 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.


📦 Installation

pip install gibberish-chat-detector

Requires Python 3.7+.


📥 Input and 📤 Output

Input

The main function accepts a single string:

gibberish_detector(s: str)
  • s — A chat message or short text (e.g., "hellooooooo!!!!")

Output

The function returns a dictionary containing:

  • A top-level gibberish flag: 1 (True) or 0 (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
}

✅ Example Usage

from gibberish_detector import gibberish_detector

text = "l;kjasdf;lkjasdf;lkj!!!!"
result = gibberish_detector(text)

print(result['gibberish'])

✨ 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

🛠 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.


🔓 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gibberish_chat_detector-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gibberish_chat_detector-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file gibberish_chat_detector-0.1.1.tar.gz.

File metadata

  • Download URL: gibberish_chat_detector-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for gibberish_chat_detector-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8426b13d2ad847043242b42560dd361c8eeeb4445185770faffe5e09d5457786
MD5 3ec95467c0e0b2b6043e3efa223f5b74
BLAKE2b-256 0f2bf0ce0cb337df690d2827fe006fb81943ca5344241aa010d8f53277d1f43e

See more details on using hashes here.

File details

Details for the file gibberish_chat_detector-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gibberish_chat_detector-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da7ea7f4a3ae1db7fb6dab26a305f941f645e3029ffb5897478e37c18e9f2e75
MD5 8029dd0ab910565f027aad2f913cd272
BLAKE2b-256 3c7fdaa0a0edd60448b54ac9ea17fc67781b154ea4d1b1ae4c05f7874572b45d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page