Views
No views yet
Fine-tuned model for automated legal contract redlining
1from peft import PeftModel, PeftConfig
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Load adapter config
5config = PeftConfig.from_pretrained("UmaiTech/qwen-2.5-7b-redline-llm-v1")
6
7# Load base model
8model = AutoModelForCausalLM.from_pretrained(
9 config.base_model_name_or_path,
10 torch_dtype=torch.bfloat16,
11 device_map="auto"
12)
13tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
14
15# Load adapter
16model = PeftModel.from_pretrained(model, "UmaiTech/qwen-2.5-7b-redline-llm-v1")
17
18# Generate redline
19prompt = """Redline this contract clause to be more protective:
20
21Original: Either party may terminate this Agreement at will without notice.
22
23Redlined:"""
24
25inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
26outputs = model.generate(**inputs, max_new_tokens=512)
27redline = tokenizer.decode(outputs[0], skip_special_tokens=True)
28print(redline)1from peft import PeftModel
2from transformers import AutoModelForCausalLM
3
4# Load and merge
5base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
6model = PeftModel.from_pretrained(base_model, "UmaiTech/qwen-2.5-7b-redline-llm-v1")
7merged_model = model.merge_and_unload()
8
9# Save merged model
10merged_model.save_pretrained("./merged_model")| Model | Overall Score | BERTScore | ROUGE-L | BLEU | Edit Sim | Clause Pres | Latency |
|---|---|---|---|---|---|---|---|
| Qwen 2.5 7B (This Model) | 0.5591 | 0.6895 | 0.4509 | 0.2784 | 0.4064 | 0.9024 | 4.6s |
| GPT-4.1-mini (Baseline) | 0.5632 | 0.6841 | 0.4694 | 0.2918 | 0.3905 | 0.8805 | 2.6s |
1@misc{qwen_2.5_7b_redline_llm_v1_2025},
2 author = {UmaiTech},
3 title = {qwen-2.5-7b-redline-llm-v1: Fine-tuned Model for Legal Contract Redlining},
4 year = {2025},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/UmaiTech/qwen-2.5-7b-redline-llm-v1}}
7}