Qwen3 LoRA for contract clause and legal text auditing
2 min readupdated
This LoRA adapter (a small add-on for the base model) is trained on tasks involving the analysis and review of legal and corporate documents. The model is built on Qwen/Qwen3-4B-Base using SFT (supervised fine-tuning) with the procurement_clause_audit dataset. It helps find and evaluate clauses in contracts and agreements. The model is useful for legal professionals, procurement specialists, and developers of enterprise document analysis systems.
Key features
- Qwen3-4B base: a compact open-weights language model.
- SFT training: fine-tuned on specialized data using the peft library.
- Domain specialization: trained on a dataset dominated by legal (61%) and corporate business (40%) texts.
- Integration: supports merging LoRA weights with the base model for faster inference.
What you can do
- Review contracts: analyze draft agreements for hidden risks and unfavorable terms.
- Corporate audit: automate initial checks of procurement documentation and regulations.
- Chat assistant: integrate the model into a local script or service to answer legal questions.
Example
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
from peft import PeftModel
BASE = "Qwen/Qwen3-4B-Base"
ADAPTER = "nirojaz/adaption_procurement_clause_audit"
base = AutoModelForCausalLM.from_pretrained(BASE, dtype="auto", device_map="auto")
model = PeftModel.from_pretrained(base, ADAPTER).merge_and_unload()
model.eval()
tokenizer = AutoTokenizer.from_pretrained(BASE)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [{"role": "user", "content": "Hello!"}]
out = pipe(messages, max_new_tokens=512, do_sample=True, temperature=0.6)
print(out[0]["generated_text"][-1]["content"])
Read more
DetailsDataset: 803 rows of adapted data (legal: 61%, corporate-business: 40%).
Benchmarks: win rate against the base model in the legal domain is 45%.
Hyperparameters: lora_r = 32, lora_alpha = 64, learning_rate = 0.00015, 6 epochs.
Trainable modules: k_proj, up_proj, o_proj, q_proj, down_proj, v_proj, gate_proj.










Comments