Gibberish Detector - Advanced Text Classification Model

Model on Hugging Face License: MIT Accuracy

State-of-the-art gibberish detection model that accurately identifies nonsensical text, spam, and incoherent input in English. Built with DistilBERT and AutoNLP, this model achieves 97.36% accuracy in multi-class text classification, making it the ideal solution for content moderation, chatbot input validation, and text quality assurance.

🎯 Quick Start

from transformers import pipeline

# Initialize the gibberish detector
detector = pipeline("text-classification", model="madhurjindal/autonlp-Gibberish-Detector-492513457")

# Detect gibberish in text
result = detector("I love Machine Learning!")
print(result)
# Output: [{'label': 'clean', 'score': 0.99}]

πŸ”₯ Key Features

  • 🎯 97.36% Accuracy: Industry-leading performance in gibberish detection
  • ⚑ Fast Inference: Optimized DistilBERT architecture for real-time applications
  • 🏷️ Multi-Class Detection: Distinguishes between Noise, Word Salad, Mild Gibberish, and Clean text
  • πŸ”§ Easy Integration: Simple API with transformers pipeline
  • 🌐 Production Ready: Tested on diverse real-world datasets
  • πŸ’š Eco-Friendly: Low carbon footprint (5.53g CO2 emissions)

Problem Description

The ability to process and understand user input is crucial for various applications, such as chatbots or downstream tasks. However, a common challenge faced in such systems is the presence of gibberish or nonsensical input. To address this problem, we present a project focused on developing a gibberish detector for the English language. The primary goal of this project is to classify user input as either gibberish or non-gibberish, enabling more accurate and meaningful interactions with the system. We also aim to enhance the overall performance and user experience of chatbots and other systems that rely on user input.

What is Gibberish?

Gibberish refers to nonsensical or meaningless language or text that lacks coherence or any discernible meaning. It can be characterized by a combination of random words, nonsensical phrases, grammatical errors, or syntactical abnormalities that prevent the communication from conveying a clear and understandable message. Gibberish can vary in intensity, ranging from simple noise with no meaningful words to sentences that may appear superficially correct but lack coherence or logical structure when examined closely. Detecting and identifying gibberish is essential in various contexts, such as natural language processing, chatbot systems, spam filtering, and language-based security measures, to ensure effective communication and accurate processing of user inputs.

Label Description

Thus, we break down the problem into 4 categories:

  1. Noise: Gibberish at the zero level where even the different constituents of the input phrase (words) do not hold any meaning independently.
    For example: dfdfer fgerfow2e0d qsqskdsd djksdnfkff swq.

  2. Word Salad: Gibberish at level 1 where words make sense independently, but when looked at the bigger picture (the phrase) any meaning is not depicted.
    For example: 22 madhur old punjab pickle chennai

  3. Mild gibberish: Gibberish at level 2 where there is a part of the sentence that has grammatical errors, word sense errors, or any syntactical abnormalities, which leads the sentence to miss out on a coherent meaning.
    For example: Madhur study in a teacher

  4. Clean: This category represents a set of words that form a complete and meaningful sentence on its own.
    For example: I love this website

Tip: To facilitate gibberish detection, you can combine the labels based on the desired level of detection. For instance, if you need to detect gibberish at level 1, you can group Noise and Word Salad together as "Gibberish," while considering Mild gibberish and Clean separately as "NotGibberish." This approach allows for flexibility in detecting and categorizing different levels of gibberish based on specific requirements.

Model Trained Using AutoNLP

  • Problem type: Multi-class Classification
  • Model ID: 492513457
  • CO2 Emissions (in grams): 5.527544460835904

Validation Metrics

  • Loss: 0.07609463483095169
  • Accuracy: 0.9735624586913417
  • Macro F1: 0.9736173135739408
  • Micro F1: 0.9735624586913417
  • Weighted F1: 0.9736173135739408
  • Macro Precision: 0.9737771415197378
  • Micro Precision: 0.9735624586913417
  • Weighted Precision: 0.9737771415197378
  • Macro Recall: 0.9735624586913417
  • Micro Recall: 0.9735624586913417
  • Weighted Recall: 0.9735624586913417

πŸš€ Use Cases

1. Chatbot Input Validation

Prevent chatbots from processing nonsensical queries:

def validate_user_input(text):
    result = detector(text)[0]
    if result['label'] in ['noise', 'word_salad']:
        return "Please provide a valid question."
    return process_query(text)

2. Content Moderation

Filter spam and gibberish from user-generated content:

def moderate_content(post):
    classification = detector(post)[0]
    if classification['label'] != 'clean':
        return f"Post rejected: {classification['label']} detected"
    return "Post approved"

3. Data Quality Assurance

Clean datasets by removing low-quality text:

def filter_quality_text(texts):
    quality_texts = []
    for text in texts:
        if detector(text)[0]['label'] == 'clean':
            quality_texts.append(text)
    return quality_texts

πŸ› οΈ Installation & Usage

Basic Usage

from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

# Load model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("madhurjindal/autonlp-Gibberish-Detector-492513457")
tokenizer = AutoTokenizer.from_pretrained("madhurjindal/autonlp-Gibberish-Detector-492513457")

# Classify text
def detect_gibberish(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
    with torch.no_grad():
        outputs = model(**inputs)
    
    probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
    predicted_label_id = probabilities.argmax().item()
    
    return model.config.id2label[predicted_label_id]

# Example
print(detect_gibberish("Hello world!"))  # Output: clean
print(detect_gibberish("asdkfj asdf"))   # Output: noise

API Usage

curl -X POST -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{"inputs": "Is this text gibberish?"}' \
     https://api-inference.huggingface.co/models/madhurjindal/autonlp-Gibberish-Detector-492513457

Batch Processing

texts = [
    "Perfect sentence structure",
    "random kdjs dskjf",
    "apple banana car house"
]

results = detector(texts)
for text, result in zip(texts, results):
    print(f"'{text}' -> {result['label']} ({result['score']:.2f})")

πŸ” How It Works

This gibberish detector uses a fine-tuned DistilBERT model trained on a carefully curated dataset of various gibberish types. The model learns to identify patterns in:

  1. Character-level patterns: Detecting random character sequences
  2. Word-level coherence: Identifying meaningful word combinations
  3. Sentence-level structure: Recognizing grammatical patterns
  4. Semantic consistency: Understanding logical meaning flow

πŸ“ˆ Comparison with Other Solutions

Feature Our Model Traditional Regex Rule-Based Systems
Accuracy 97.36% ~60-70% ~70-80%
Context Understanding βœ… ❌ Limited
Multilevel Detection βœ… ❌ Limited
Speed Fast Very Fast Medium
Maintenance Low High High

🌟 Why Choose This Model?

  1. Highest Accuracy: Outperforms traditional rule-based approaches
  2. Contextual Understanding: Uses transformer architecture for deep comprehension
  3. Easy Integration: Works with standard transformers library
  4. Battle-Tested: Used in production by multiple organizations
  5. Active Maintenance: Regular updates and community support

🀝 Contributing

We welcome contributions! Please feel free to:

  • Report issues
  • Suggest improvements
  • Share your use cases
  • Contribute to documentation

πŸ“š Citations

If you use this model in your research, please cite:

@misc{gibberish-detector-2021,
  author = {Madhur Jindal},
  title = {Gibberish Detector: High-Accuracy Text Classification Model},
  year = {2021},
  publisher = {Hugging Face},
  url = {https://huggingface.co/madhurjindal/autonlp-Gibberish-Detector-492513457}
}

πŸ“ž Support

πŸ“œ License

This model is licensed under the MIT License. See LICENSE for details.


Made with ❀️ by Madhur Jindal
Downloads last month
192,034
Safetensors
Model size
67M params
Tensor type
F32
Β·
Inference Providers NEW

Model tree for madhurjindal/autonlp-Gibberish-Detector-492513457

Quantized
(30)
this model
Quantizations
3 models

Spaces using madhurjindal/autonlp-Gibberish-Detector-492513457 8

Evaluation results