paiml/shell-safety-classifier
114
Shell Safety Classifier
Classifies shell scripts into 5 safety categories using a lightweight MLP trained on the bashrs corpus.
Labels
Architecture
- Model: MLP classifier (ShellVocabulary token embeddings -> 128 -> 64 -> 5)
- Tokenizer: ShellVocabulary (250 shell-specific tokens, maxseqlen=64)
- Format: SafeTensors (model.safetensors) + JSON config + vocab
- Framework: aprender (pure Rust ML, no Python dependencies)
Training
- Corpus: bashrs v2 corpus (17,942 entries: 16,431 Bash + 804 Makefile + 707 Dockerfile)
- Split: 80/20 train/validation (14,353 / 3,589)
- Epochs: 50
- Optimizer: Adam (lr=0.01)
- Loss: CrossEntropyLoss
- Train accuracy: 96.6%
- Validation accuracy: 63.2%
Class Distribution
Usage
With bashrs CLI
# Classify a single script
bashrs classify script.sh
# Classify with format detection
bashrs classify Makefile --format makefile
# Multi-label classification
bashrs classify script.sh --multi-labelWith aprender (Rust)
use aprender::models::shell_safety::{ShellSafetyClassifier, SafetyClass};
let classifier = ShellSafetyClassifier::load("/path/to/model")?;
let result = classifier.predict("echo $HOME")?;
// result: SafetyClass::NeedsQuotingFiles
Limitations
- The v2.0 MLP architecture has limited validation accuracy (63.2%) due to class imbalance and simple architecture
- Best suited for binary safe/unsafe classification (96%+ accuracy when collapsing to 2 classes)
- A Qwen2.5-Coder fine-tuned version is planned for higher accuracy on minority classes
License
MIT
