Views
No views yet
1# pip install git+https://github.com/huggingface/transformers.git
2# pip install git+https://github.com/huggingface/peft.git
3
4import torch
5from transformers import (
6 AutoModelForCausalLM,
7 AutoTokenizer,
8 BitsAndBytesConfig
9)
10from peft import PeftModel
11
12model = AutoModelForCausalLM.from_pretrained(
13 "meta-llama/Llama-3.1-8B",
14 quantization_config=BitsAndBytesConfig(load_in_8bit=True),
15 device_map="auto",
16)
17
18tokenizer = AutoTokenizer.from_pretrained("Equall/Saul-7B-Base")
19tokenizer.pad_token = tokenizer.eos_token
20
21model = PeftModel.from_pretrained(
22 model,
23 "auslawbench/Cite-Llama-3.1-8B",
24 device_map="auto",
25 torch_dtype=torch.bfloat16,
26 )
27model.eval()
28
29fine_tuned_prompt = """
30### Instruction:
31{}
32
33### Input:
34{}
35
36### Response:
37{}"""
38
39example_input="Many of ZAR’s grounds of appeal related to fact finding. Drawing on principles set down in several other courts and tribunals, the Appeal Panel summarised the circumstances in which leave may be granted for a person to appeal from findings of fact: <CASENAME> at [84]."
40model_input = fine_tuned_prompt.format("Predict the name of the case that needs to be cited in the text and explain why it should be cited.", example_input, '')
41inputs = tokenizer(model_input, return_tensors="pt").to("cuda")
42outputs = model.generate(**inputs, max_new_tokens=256, temperature=1.0)
43output = tokenizer.decode(outputs[0], skip_special_tokens=True)
44print(output.split("### Response:")[1].strip().split('>')[0] + '>')
45@misc{shareghi2024auslawcite,
title={Methods for Legal Citation Prediction in the Age of LLMs: An Australian Law Case Study},
author={Ehsan Shareghi, Jiuzhou Han, Paul Burgess},
year={2024},
eprint={arXiv:2412.06272},
archivePrefix={arXiv},
primaryClass={cs.CL}
}