Views
No views yet
| Model | Accuracy | Mal. Recall | Ben. Recall | Macro F1 |
|---|---|---|---|---|
| ThreatQwen-1.7B-Detect (ours) | 95.1% | 96.1% | 94.2% | 0.951 |
| Base Qwen3-1.7B (no fine-tune) | 85.1% | 92.1% | 78.2% | 0.851 |
| GPT-4o (Azure, zero-shot) | 51.8% | 85.0% | 18.6% | 0.458 |
| GPT-4o-mini (Azure, zero-shot) | 51.9% | 59.6% | 44.2% | 0.516 |
{"verdict": "malicious | benign"}| Parameter | Value |
|---|---|
| Base model | unsloth/Qwen3-1.7B-unsloth-bnb-4bit |
| Method | QLoRA 4-bit NF4 |
| LoRA rank / alpha | 16 / 32 |
| Epochs | 3 |
| Effective batch size | 16 (batch 4 × accum 4) |
| Learning rate | 2e-4 cosine |
| MAX_SEQ_LEN | 512 |
| Hardware | Tesla T4 (Kaggle free tier) |
| Training time | ~10 min |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch, json
4
5base = AutoModelForCausalLM.from_pretrained(
6 "unsloth/Qwen3-1.7B-unsloth-bnb-4bit",
7 torch_dtype=torch.float16, device_map="auto",
8)
9model = PeftModel.from_pretrained(base, "minar-svn/ThreatQwen-1.7B-Detect")
10tokenizer = AutoTokenizer.from_pretrained("minar-svn/ThreatQwen-1.7B-Detect")
11
12SYSTEM = 'You are a cybersecurity detection model. Respond ONLY with valid JSON. Format: {"verdict": "malicious | benign"}'
13
14event = "EventID: 1 Image: rundll32.exe CommandLine: comsvcs.dll MiniDump User: admin"
15
16msgs = [{"role":"system","content":SYSTEM},{"role":"user","content":f"Analyze:\n\n{event}"}]
17prompt = tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True).strip()
18inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
20with torch.no_grad():
21 out = model.generate(**inputs, max_new_tokens=40, do_sample=False,
22 pad_token_id=tokenizer.eos_token_id)
23
24response = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()
25blocks = [b.strip() for b in response.split("\n\n") if b.strip()]
26print(json.loads(blocks[-1]))
27# {"verdict": "malicious"}1@misc{threatqwen2026,
2 author = {Md. Minaruzzaman Shovon},
3 title = {ThreatQwen-1.7B-Detect},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/minar-svn/ThreatQwen-1.7B-Detect}
7}