ml-classifier-training

Trains TF-IDF baselines and fine-tunes DeBERTa-v3 transformers for prompt injection detection.

1|Updated Sep 1, 2026
One-click install
npx skills add https://github.com/nvtruongops/pi-guard --skill ml-classifier-training-nvtruongops
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ml-classifier-training
Source: https://github.com/nvtruongops/pi-guard/tree/main/.agents/skills/ml-classifier-training
Command: npx skills add https://github.com/nvtruongops/pi-guard --skill ml-classifier-training-nvtruongops

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires scikit-learn, transformers, torch, evaluate, joblib, numpy.

What problem does it solve? Building a machine-learning guardrail against prompt injection and jailbreak attacks requires training both fast classical baselines and accurate transformer classifiers, which involves many error-prone choices in feature engineering, hyperparameters, and evaluation. ## Core Features & Use Cases - Classical ML Baseline: Builds a hybrid word (1-3) and character (3-5) n-gram TF-IDF pipeline with LogisticRegression or LinearSVC, saved via joblib. - Transformer Fine-Tuning: Fine-tunes DeBERTa-v3, RoBERTa, or BERT with the Hugging Face Trainer, tracking accuracy, precision, recall, and F1. - Latency Optimization: Exports models to ONNX with dynamic INT8 quantization for low-latency CPU inference. - Use Case: A student training a prompt-injection classifier can follow the provided pipeline code to train a TF-IDF baseline, fine-tune deberta-v3-base, and quantize it for a guardrail API. ## Quick Start Train a baseline TF-IDF classifier and fine-tune a DeBERTa-v3 model on my prompt injection dataset, then export the best model to ONNX with INT8 quantization.

Frequently Asked Questions about ml-classifier-training

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a TF-IDF baseline for prompt injection detection?

Build a FeatureUnion combining word n-grams (1-3) and character n-grams (3-5) with TfidfVectorizer, then fit LogisticRegression or LinearSVC with class_weight balanced. Save the trained pipeline with joblib for later inference.

How to fine-tune DeBERTa-v3 for sequence classification with Hugging Face?

Load AutoModelForSequenceClassification with num_labels=2, configure TrainingArguments with learning rate 2e-5 and 4 epochs, and train with the Trainer API. Use load_best_model_at_end with metric_for_best_model set to f1.

DeBERTa-v3 vs TF-IDF logistic regression for prompt injection detection?

TF-IDF with LogisticRegression is fast and lightweight, serving as an empirical baseline. DeBERTa-v3 uses disentangled attention for stronger semantic boundary detection, making it the primary high-accuracy model.

Does ONNX quantization reduce model accuracy significantly?

Dynamic INT8 quantization reduces model size by 4x and latency by roughly 2-3x with less than 0.5% accuracy loss. It is applied after exporting the fine-tuned transformer to ONNX format for CPU inference.

Why use character n-grams in a text classification pipeline?

Character n-grams (3-5) catch obfuscation techniques like leetspeak, character spacing, and encoding tricks that word-level features miss. Combining them with word n-grams in a FeatureUnion improves robustness against evasion.