cunxin/gemma-4-E4B-email-fraud-detector
Gemma 4 E4B Email Fraud Detector
A fine-tuned Google Gemma 4 E4B-it model specialized in email fraud detection, phishing identification, and spam classification. This model analyzes raw email content and outputs structured JSON verdicts with threat analysis, risk scoring, and actionable suggestions.
Highlights
- Three-class output: Distinguishes between safe, spam, and fraud/phishing emails with calibrated risk scores (0-100)
- 11 threat detectors: Identifies
CREDENTIAL_REQUEST,DOMAIN_MISMATCH,URL_DISCREPANCY,TOO_GOOD_TO_BE_TRUE,PROMPT_INJECTION,URGENCY_FEAR,REPLY_TO_MISMATCH,GENERIC_SALUTATION,ANOMALOUS_TIMING,MISSING_SIGNATURE,GRAMMAR_ANOMALY - Structured JSON output: Every response is a parseable JSON object with
is_fraud,risk_score,confidence_level,detected_threats,reason, andsuggestion - Prompt injection resistant: Trained to detect and flag prompt injection attempts embedded in email content
- Discriminative model hint fusion: Supports optional
[CLASSIFIER HINT]from a companion RoBERTa classifier, with learned override logic for known false-positive patterns
Training
Data
Fine-tuned on a curated dataset of 1,300+ labeled emails spanning:
- Real-world phishing emails collected from enterprise and academic environments
- Production email corpuses including modern SaaS notifications, automated alerts, marketing, and legitimate business correspondence
- Enron corpus subsets with fraud/spam labels from
SetFit/enron_spam - AI-augmented hard examples targeting edge cases: credential harvesting, domain spoofing, predatory conference invitations, fake SaaS renewal notices, and subtle social engineering
- False positive correction pools derived from iterative evaluation — legitimate automated emails (LMS, CI/CD, calendar invites) that earlier models misclassified
Each training example includes a conversation-format prompt with:
- 75% correct classifier hints (teaching hint-agreement behavior)
- 15% intentionally wrong hints at low confidence (teaching independent override)
- 10% no hints (maintaining standalone analysis capability)
Method
- Base model:
google/gemma-4-E4B-it(8B total params, 4B effective via Per-Layer Embeddings) - Technique: QLoRA (4-bit NF4 quantization + LoRA rank-16 adapters)
- LoRA targets:
q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj - Trainable parameters: 42.4M (0.53% of total)
- Training hardware: NVIDIA RTX 4090 (24GB VRAM)
- Training time: ~10 minutes (3 epochs, batch size 2, gradient accumulation 8)
Results
Usage
With vLLM (recommended for production)
# Serve the model
vllm serve cunxin/gemma-4-E4B-email-fraud-detector --dtype bfloat16 --max-model-len 4096
# Query
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "cunxin/gemma-4-E4B-email-fraud-detector",
"messages": [
{"role": "system", "content": "You are an anti-fraud email analyzer. Output ONLY valid JSON."},
{"role": "user", "content": "Analyze the following email:\n{\"sender\": \"security@paypa1-verify.com\", \"subject\": \"Account Suspended\", \"content\": \"Dear Customer, your account has been limited. Verify your identity at http://paypa1-verify.com/login\"}"}
]
}'With Transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model = AutoModelForCausalLM.from_pretrained(
"cunxin/gemma-4-E4B-email-fraud-detector",
torch_dtype=torch.bfloat16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("cunxin/gemma-4-E4B-email-fraud-detector")
messages = [
{"role": "system", "content": "You are an anti-fraud email analyzer. Output ONLY valid JSON."},
{"role": "user", "content": 'Analyze the following email:\n{"sender": "noreply@university.edu", "subject": "Grade Posted", "content": "Your final grade for CS120 has been posted to the student portal."}'},
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
outputs = model.generate(inputs, max_new_tokens=512, temperature=0.1)
print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))Example Output
{
"is_fraud": false,
"risk_score": 0,
"confidence_level": 0.95,
"detected_threats": [],
"reason": "Score: 0. Sender is on official university.edu domain. Routine grade notification with no suspicious links or credential requests.",
"suggestion": "This appears legitimate. Check your grades through the official student portal."
}Quantized Versions
Limitations
- Optimized for English-language emails; multilingual phishing detection may be less reliable
- Training data skews toward academic/enterprise email patterns
- Gemma 4 E4B's heterogeneous attention heads (head_dim 256/512) disable FlashAttention, resulting in slower inference than comparable models
- Risk scores are heuristic-weighted sums, not calibrated probabilities
Architecture Note
Gemma 4 E4B uses Per-Layer Embeddings (PLE) with a 262K token vocabulary, giving it 8B total parameters but only 4B "effective" parameters. The model includes vision and audio encoders that are unused for this text-only task. For deployment, we recommend using the GPTQ quantized variants to reduce memory footprint.
License
This model inherits the Gemma license from the base model.
Citation
@misc{gemma4-email-fraud-detector,
title={Gemma 4 E4B Email Fraud Detector},
author={Ruibo Sun},
year={2026},
url={https://huggingface.co/cunxin/gemma-4-E4B-email-fraud-detector}
}Gemma 4 E4B 邮件欺诈检测模型
基于 Google Gemma 4 E4B-it 微调的邮件欺诈检测、钓鱼识别和垃圾邮件分类专用模型。输入原始邮件内容,输出结构化 JSON 分析结果,包含威胁分析、风险评分和处置建议。
核心特性
- 三类输出:区分正常邮件、垃圾邮件(spam)和欺诈/钓鱼邮件,输出校准后的风险评分(0-100)
- 11 种威胁检测器:覆盖凭证窃取、域名仿冒、URL 伪装、天上掉馅饼、提示注入攻击、紧迫恐吓、回复地址不一致、泛称问候、异常发送时间、缺少签名、语法异常
- 结构化 JSON 输出:每次响应均为可解析的 JSON,包含
is_fraud、risk_score、confidence_level、detected_threats、reason、suggestion字段 - 提示注入防护:经过训练识别并标记嵌入在邮件内容中的提示注入攻击
- 判别模型融合:支持来自 RoBERTa 分类器的
[CLASSIFIER HINT],并具备学习到的覆盖逻辑,可纠正已知的误报模式
训练详情
数据
在 1,300+ 封标注邮件的精选数据集上微调,涵盖:
- 真实钓鱼邮件:采集自企业和学术环境的生产数据
- 生产环境邮件语料:包括现代 SaaS 通知、自动化告警、营销邮件和正常商务往来
- Enron 语料库子集,带有
SetFit/enron_spam的欺诈/垃圾标签 - AI 增强困难样本:针对边缘场景生成,包括凭证窃取、域名仿冒、掠夺性会议邀请、虚假 SaaS 续费通知、精巧社会工程攻击
- 假阳性纠正池:通过迭代评估收集的合法自动化邮件(LMS、CI/CD、日历邀请等)——此前版本误判为欺诈的正常邮件
方法
- 基座模型:
google/gemma-4-E4B-it(总参数 8B,通过 Per-Layer Embeddings 实现 4B 有效参数) - 技术:QLoRA(4-bit NF4 量化 + LoRA rank-16 适配器)
- 可训练参数:42.4M(占总参数的 0.53%)
- 训练硬件:NVIDIA RTX 4090(24GB 显存)
- 训练时间:约 10 分钟(3 个 epoch)
训练结果
量化版本
许可证
本模型继承基座模型的 Gemma 许可证。
