Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5# Load base model and tokenizer
6base_model = AutoModelForCausalLM.from_pretrained(
7 "meta-llama/Llama-3.2-3B-Instruct",
8 torch_dtype=torch.float16,
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
12
13# Load LoRA adapters
14model = PeftModel.from_pretrained(base_model, "{REPO_ID}")
15
16# Extract clause
17prompt = \"\"\"<|begin_of_text|><|start_header_id|>user<|end_header_id|>
18
19Copy the exact 'Indemnification' clause from this contract:
20
21[Your contract text here]
22<|eot_id|><|start_header_id|>assistant<|end_header_id|>
23
24\"\"\"
25
26inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
27outputs = model.generate(**inputs, max_new_tokens=200)
28print(tokenizer.decode(outputs[0], skip_special_tokens=True))| Metric | Value |
|---|---|
| Training Loss | 0.407 |
| Average Similarity | 73.6% |
| Excellent (>90%) | 39% |
| Good (>70%) | 60% |
| Partial (>50%) | 78% |
1@misc{{llama32-legal-clause-extractor,
2 author = {{{HF_USERNAME}}},
3 title = {{Legal Clause Extraction with Llama 3.2 3B}},
4 year = {{2025}},
5 publisher = {{HuggingFace}},
6 url = {{https://huggingface.co/{REPO_ID}}}
7}}