Downloads · 30 days
10
25% of all-time downloads
hossam3759180/allam-qlora-legal-adapter
allam-qlora-legal-adapter is a text generation model from hossam3759180. Use it when you need the model to write or continue text. It is set up for peft.
A QLoRA adapter for ALLaM-AI/ALLaM-7B-Instruct-preview, fine-tuned on Egyptian and Saudi Arabic legal instruction data for three tasks: article analysis, plain-language simplification, and judgment prediction.
Downloads · 30 days
10
25% of all-time downloads
All-time downloads
40
Public
Repo size
675 MB
Likes
0
Public
Click a slice to open those files.
.safetensors320 MB · 98%
From the Hugging Face model README
A QLoRA adapter for ALLaM-AI/ALLaM-7B-Instruct-preview, fine-tuned on Egyptian and Saudi Arabic legal instruction data for three tasks: article analysis, plain-language simplification, and judgment prediction.
Code, notebooks, evaluation and the full write-up: AI_Portfolio / allam_finetune.
| Revision | What it is | Faithfulness (Gemini-judged, 1-10) |
|---|---|---|
main | v1, first fine-tune | 7.63 |
v2-synthetic | v2, current adapter (adds 780 curated synthetic analysis examples) | 8.47 |
Zero-shot base model on the same sample: 4.72. Use revision="v2-synthetic" unless you specifically want v1.
LLM-judged by Gemini (gemini-3.1-flash-lite, temperature 0) on a fixed 150-row held-out sample, stratified by task type and reused across all three stages. Scores are 1-10 against the reference response.
| Metric | Base (zero-shot) | v1 | v2 |
|---|---|---|---|
| Faithfulness | 4.72 | 7.63 | 8.47 |
| Relevance | 7.15 | 8.77 | 9.44 |
| Fluency | 8.94 | 9.11 | 9.88 |
Faithfulness by task:
| Task | Base | v1 | v2 |
|---|---|---|---|
| Analysis | 3.06 | 6.47 | 9.24 |
| Judgment prediction | 4.37 | 5.84 | 7.03 |
| Simplification | 5.50 | 9.76 | 9.74 |
The adapter was trained on an Alpaca-style prompt, so use the same format at inference.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
base_id = "ALLaM-AI/ALLaM-7B-Instruct-preview"
adapter_id = "hossam3759180/allam-qlora-legal-adapter"
bnb = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16,
)
tokenizer = AutoTokenizer.from_pretrained(base_id)
model = AutoModelForCausalLM.from_pretrained(base_id, quantization_config=bnb, device_map="auto")
model = PeftModel.from_pretrained(model, adapter_id, revision="v2-synthetic")
def build_prompt(instruction, input_text=""):
parts = [f"### Instruction:\n{instruction}"]
if input_text:
parts.append(f"### Input:\n{input_text}")
parts.append("### Response:")
return "\n\n".join(parts)
prompt = build_prompt("<your instruction>", "<optional input>")
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
text = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
# The model can continue with a made-up follow-up instruction after a correct
# answer, so cut the output at the first "### Input:" or "### Instruction:".
text = text.split("### Input:")[0].split("### Instruction:")[0].strip()
print(text)
The evaluation used greedy decoding. Adding repetition_penalty or no_repeat_ngram_size corrupted the model's Arabic output (dropped letters mid-word), so avoid both.
nf4, double quantization, fp16 compute), rank 32, alpha 64, dropout 0.1, on all seven attention and MLP projections (q/k/v/o_proj, gate/up/down_proj).fr3on/eg-legal-instruction-following (Egyptian legal; analysis and simplification kept) and mbayan/Arabic-LJP (Saudi judgment prediction), after exact-duplicate removal and a 10-2048 word length filter. judgment_prediction was capped from 3,610 to 954 rows to match the next-largest class. Split 90/10 stratified: 1,942 train, 216 validation.analysis rows repeated 3x.analysis rows plus 780 synthetic ones generated with Gemini using a few-shot prompt, then filtered for schema, language, PII and near-duplicates (839 generated, 59 rejected by the schema check).judgment_prediction gain in v2 has no dedicated fix behind it and may be run-to-run variance in a small sample.