Downloads · 30 days
38
14% of all-time downloads
cycloevan/gdpr_gemma-2-2b
gdpr_gemma-2-2b is a text generation model from cycloevan. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
A specialized fine-tune of google/gemma-2-2b-it for English GDPR (General Data Protection Regulation) Q&A. The model is aligned with expert GDPR answers via a 3-stage pipeline — Supervised Fine-Tuning, Dynamic Rejecti…
Downloads · 30 days
38
14% of all-time downloads
All-time downloads
279
Public
Parameters
2.6B
10.5 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors5.2 GB · 100%
From the Hugging Face model README
A specialized fine-tune of google/gemma-2-2b-it for English GDPR
(General Data Protection Regulation) Q&A. The model is aligned with expert
GDPR answers via a 3-stage pipeline — Supervised Fine-Tuning, Dynamic
Rejection sampling, and Direct Preference Optimization (DPO) — using QLoRA
for resource-friendly training.
Disclaimer: This model provides informational guidance only and does not constitute legal advice. Always consult a qualified legal professional for binding GDPR compliance decisions.
cycloevan)google/gemma-2-2b-it ┌──────────────┐ ┌────────────────────┐ ┌──────────────┐
Base Gemma-2 ─►│ Stage 1: SFT │ ──► │ Stage 2: Dynamic │ ──► │ Stage 3: DPO │
│ (knowledge) │ │ Rejection Sampling │ │ (alignment) │
└──────────────┘ └────────────────────┘ └──────────────┘
| Stage | Goal | Method |
|---|---|---|
| 1. SFT | Inject GDPR domain knowledge | QLoRA SFT on expert Q&A |
| 2. Dynamic Rejection | Build realistic preference pairs | Sample SFT outputs (T=0.9) as rejected; expert answer = chosen |
| 3. DPO | Align preferences toward expert answers | DPO on top of SFT adapter (β=0.1) |
This pipeline is more faithful than naive DPO because Stage 2 produces rejection candidates that match the model's actual failure modes, rather than synthetic or generic wrong answers.
| Component | Value |
|---|---|
| Base model | google/gemma-2-2b-it |
| Quantization | 4-bit NF4 (QLoRA), bf16 compute |
LoRA r / alpha / dropout | 16 / 32 / 0.05 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| SFT epochs / LR | 3 / 2e-5 |
| DPO epochs / LR / β | 3 / 5e-6 / 0.1 |
| Batch size / Grad accum | 1 / 4 |
| Max prompt / total length | 1024 / 2048 |
| Optimizer | paged_adamw_8bit |
| Hardware | NVIDIA DGX Spark (CUDA, bf16) |
Quantitative on 100 samples from sims2k/GDPR_QA_instruct_dataset;
qualitative via GPT-4o LLM-as-a-Judge on 10 samples (1–5 scale).
| Metric | Base | SFT | DPO (this model) |
|---|---|---|---|
| ROUGE-L | 0.2072 | 0.2331 | 0.2252 |
| BLEU | 0.0838 | 0.1146 | 0.1034 |
| BertScore F1 | 0.8432 | 0.8541 | 0.8527 |
| Criterion | Base | SFT | DPO (this model) |
|---|---|---|---|
| Legal Correctness | 3.10 | 3.00 | 3.40 |
| Article Accuracy | 2.20 | 2.30 | 2.60 |
| Compliance Alignment | 3.70 | 3.40 | 3.80 |
| Clarity | 4.10 | 4.10 | 3.80 |
DPO improves legal correctness, GDPR-article citation accuracy, and compliance alignment over both Base and SFT. It trades a small amount of surface-level lexical overlap (ROUGE/BLEU) and clarity in exchange for substantively more accurate legal content — a typical alignment trade-off.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "cycloevan/gdpr_gemma-2-2b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
attn_implementation="eager", # recommended for Gemma-2
)
SYSTEM = (
"You are a professional GDPR compliance assistant. "
"Provide accurate, legal, and clear guidance based on the General Data "
"Protection Regulation."
)
def ask_gdpr(question: str, max_new_tokens: int = 512) -> str:
messages = [{"role": "user", "content": f"{SYSTEM}\n\nQuestion: {question}"}]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=0.1,
top_p=0.2,
pad_token_id=tokenizer.eos_token_id,
)
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return text.split("model")[-1].strip() if "model" in text else text
print(ask_gdpr("What are the main principles of GDPR?"))
GDPR compliance affects individuals' fundamental rights to privacy and data protection. Errors in legal interpretation may cause organisations to mishandle personal data or mislead data subjects. Use only as a decision-support tool, never as the sole basis for compliance actions.
@misc{gdpr_gemma_2_2b_2024,
title = {GDPR-Gemma-2-2B: A 3-Stage Aligned GDPR Compliance Assistant},
author = {seok-hee97},
year = {2024},
howpublished = {Hugging Face Model Hub},
url = {https://huggingface.co/cycloevan/gdpr_gemma-2-2b}
}