Upload folder using huggingface_hub
Browse files- README.md +171 -0
- config.json +40 -0
- model.safetensors +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- text-classification
|
| 4 |
+
- gibberish
|
| 5 |
+
- detector
|
| 6 |
+
- spam
|
| 7 |
+
- distilbert
|
| 8 |
+
- nlp
|
| 9 |
+
- text-filter
|
| 10 |
+
- akto
|
| 11 |
+
language: en
|
| 12 |
+
widget:
|
| 13 |
+
- text: I love Machine Learning!
|
| 14 |
+
license: mit
|
| 15 |
+
library_name: transformers
|
| 16 |
+
base_model: distilbert-base-uncased
|
| 17 |
+
model-index:
|
| 18 |
+
- name: gibberish-detector
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: text-classification
|
| 22 |
+
name: Gibberish Detection
|
| 23 |
+
metrics:
|
| 24 |
+
- type: accuracy
|
| 25 |
+
value: 0.9736
|
| 26 |
+
name: Accuracy
|
| 27 |
+
- type: f1
|
| 28 |
+
value: 0.9736
|
| 29 |
+
name: F1 Score
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Gibberish Detector - Text Classification Model
|
| 33 |
+
|
| 34 |
+
**High-performance gibberish detection model** for identifying nonsensical text, spam, and incoherent input. Built with DistilBERT, achieving **97.36% accuracy** in multi-class text classification.
|
| 35 |
+
|
| 36 |
+
This model is designed for production use with Akto's security frameworks and LLM protection systems.
|
| 37 |
+
|
| 38 |
+
## 🎯 Quick Start
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from transformers import pipeline
|
| 42 |
+
|
| 43 |
+
# Initialize the gibberish detector
|
| 44 |
+
detector = pipeline("text-classification", model="TangoBeeAkto/gibberish-detector")
|
| 45 |
+
|
| 46 |
+
# Detect gibberish in text
|
| 47 |
+
result = detector("I love Machine Learning!")
|
| 48 |
+
print(result)
|
| 49 |
+
# Output: [{'label': 'clean', 'score': 0.99}]
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## 🔥 Key Features
|
| 53 |
+
|
| 54 |
+
- **🎯 97.36% Accuracy**: High-performance gibberish detection
|
| 55 |
+
- **⚡ Fast Inference**: Optimized DistilBERT architecture
|
| 56 |
+
- **🏷️ Multi-Class Detection**: Noise, Word Salad, Mild Gibberish, and Clean text
|
| 57 |
+
- **🔧 Easy Integration**: Standard transformers pipeline
|
| 58 |
+
- **🌐 Production Ready**: Tested and validated for security applications
|
| 59 |
+
- **💚 Efficient**: Low computational footprint
|
| 60 |
+
|
| 61 |
+
## Problem Description
|
| 62 |
+
|
| 63 |
+
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. This project focuses on developing a gibberish detector for the English language.
|
| 64 |
+
|
| 65 |
+
The primary goal is to classify user input as either **gibberish** or **non-gibberish**, enabling more accurate and meaningful interactions with the system.
|
| 66 |
+
|
| 67 |
+
## Label Categories
|
| 68 |
+
|
| 69 |
+
The model classifies text into 4 categories:
|
| 70 |
+
|
| 71 |
+
1. **Clean (0)**: Proper, meaningful sentences
|
| 72 |
+
- Example: `I love this website`
|
| 73 |
+
|
| 74 |
+
2. **Mild Gibberish (1)**: Sentences with grammatical or syntactical errors
|
| 75 |
+
- Example: `I study in a teacher`
|
| 76 |
+
|
| 77 |
+
3. **Noise (2)**: Random character sequences with no meaningful words
|
| 78 |
+
- Example: `dfdfer fgerfow2e0d qsqskdsd`
|
| 79 |
+
|
| 80 |
+
4. **Word Salad (3)**: Valid words without coherent meaning
|
| 81 |
+
- Example: `apple banana car house randomly`
|
| 82 |
+
|
| 83 |
+
## 🚀 Use Cases
|
| 84 |
+
|
| 85 |
+
### Input Validation for Security Systems
|
| 86 |
+
```python
|
| 87 |
+
def validate_user_input(text):
|
| 88 |
+
result = detector(text)[0]
|
| 89 |
+
if result['label'] in ['noise', 'word_salad']:
|
| 90 |
+
return "Invalid input detected. Please provide meaningful text."
|
| 91 |
+
return process_query(text)
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Content Moderation
|
| 95 |
+
```python
|
| 96 |
+
def moderate_content(post):
|
| 97 |
+
classification = detector(post)[0]
|
| 98 |
+
if classification['label'] != 'clean':
|
| 99 |
+
return f"Content flagged: {classification['label']}"
|
| 100 |
+
return "Content approved"
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### LLM Prompt Filtering
|
| 104 |
+
```python
|
| 105 |
+
def filter_prompt(prompt):
|
| 106 |
+
result = detector(prompt)[0]
|
| 107 |
+
if result['label'] in ['noise', 'word_salad'] and result['score'] > 0.8:
|
| 108 |
+
return "Potentially malicious or gibberish prompt detected"
|
| 109 |
+
return "Prompt is valid"
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
## 🛠️ Installation & Usage
|
| 113 |
+
|
| 114 |
+
```python
|
| 115 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 116 |
+
import torch
|
| 117 |
+
|
| 118 |
+
# Load model and tokenizer
|
| 119 |
+
model = AutoModelForSequenceClassification.from_pretrained("TangoBeeAkto/gibberish-detector")
|
| 120 |
+
tokenizer = AutoTokenizer.from_pretrained("TangoBeeAkto/gibberish-detector")
|
| 121 |
+
|
| 122 |
+
def detect_gibberish(text):
|
| 123 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 124 |
+
with torch.no_grad():
|
| 125 |
+
outputs = model(**inputs)
|
| 126 |
+
|
| 127 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 128 |
+
predicted_label_id = probabilities.argmax().item()
|
| 129 |
+
|
| 130 |
+
return model.config.id2label[predicted_label_id]
|
| 131 |
+
|
| 132 |
+
# Example usage
|
| 133 |
+
print(detect_gibberish("Hello world!")) # Output: clean
|
| 134 |
+
print(detect_gibberish("asdkfj asdf")) # Output: noise
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
## Model Details
|
| 138 |
+
|
| 139 |
+
- **Architecture**: DistilBERT for Sequence Classification
|
| 140 |
+
- **Base Model**: distilbert-base-uncased
|
| 141 |
+
- **Max Length**: 64 tokens
|
| 142 |
+
- **Vocab Size**: 30,522
|
| 143 |
+
- **Parameters**: ~67M
|
| 144 |
+
|
| 145 |
+
## Performance Metrics
|
| 146 |
+
|
| 147 |
+
- **Accuracy**: 97.36%
|
| 148 |
+
- **F1 Score**: 97.36%
|
| 149 |
+
- **Precision**: 97.38%
|
| 150 |
+
- **Recall**: 97.36%
|
| 151 |
+
|
| 152 |
+
## ONNX Support
|
| 153 |
+
|
| 154 |
+
This model supports ONNX optimization for faster inference in production environments. Use with optimized runtimes for best performance.
|
| 155 |
+
|
| 156 |
+
## Integration with Akto Security Framework
|
| 157 |
+
|
| 158 |
+
This model is optimized for use with Akto's LLM security and protection systems. It provides real-time gibberish detection for:
|
| 159 |
+
|
| 160 |
+
- Prompt injection detection
|
| 161 |
+
- Input validation
|
| 162 |
+
- Content filtering
|
| 163 |
+
- Security monitoring
|
| 164 |
+
|
| 165 |
+
## License
|
| 166 |
+
|
| 167 |
+
This model is licensed under the MIT License.
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
**Developed by Akto for enterprise security applications**
|
config.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "TangoBeeAkto/gibberish-detector",
|
| 3 |
+
"_num_labels": 4,
|
| 4 |
+
"activation": "gelu",
|
| 5 |
+
"architectures": [
|
| 6 |
+
"DistilBertForSequenceClassification"
|
| 7 |
+
],
|
| 8 |
+
"attention_dropout": 0.1,
|
| 9 |
+
"dim": 768,
|
| 10 |
+
"dropout": 0.1,
|
| 11 |
+
"hidden_dim": 3072,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "clean",
|
| 14 |
+
"1": "mild gibberish",
|
| 15 |
+
"2": "noise",
|
| 16 |
+
"3": "word salad"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"label2id": {
|
| 20 |
+
"clean": 0,
|
| 21 |
+
"mild gibberish": 1,
|
| 22 |
+
"noise": 2,
|
| 23 |
+
"word salad": 3
|
| 24 |
+
},
|
| 25 |
+
"max_length": 64,
|
| 26 |
+
"max_position_embeddings": 512,
|
| 27 |
+
"model_type": "distilbert",
|
| 28 |
+
"n_heads": 12,
|
| 29 |
+
"n_layers": 6,
|
| 30 |
+
"pad_token_id": 0,
|
| 31 |
+
"padding": "max_length",
|
| 32 |
+
"problem_type": "single_label_classification",
|
| 33 |
+
"qa_dropout": 0.1,
|
| 34 |
+
"seq_classif_dropout": 0.2,
|
| 35 |
+
"sinusoidal_pos_embds": false,
|
| 36 |
+
"tie_weights_": true,
|
| 37 |
+
"torch_dtype": "float32",
|
| 38 |
+
"transformers_version": "4.15.0",
|
| 39 |
+
"vocab_size": 30522
|
| 40 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:278bd923924e82f8021d73c771840e98c5d2a1f032a6cba5d09dab1583cd2e82
|
| 3 |
+
size 267838720
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "AutoNLP", "tokenizer_class": "DistilBertTokenizer"}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|