Enabling Discriminative Reasoning in LLMs for Legal Judgment Prediction
Paper • 2407.01964 • Published
How to use ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForMultimodalLM
tokenizer = AutoTokenizer.from_pretrained("ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765")
model = AutoModelForMultimodalLM.from_pretrained("ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765
How to use ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765 with Docker Model Runner:
docker model run hf.co/ChenlongDeng/ADAPT-Qwen2-7B-CAIL2018-step-8765
❗️Note: Our released model needs the Qwen chat_template to conduct correct generation.
We support the following four prompts to enable reasoning. You should use the same input format and prompt to achieve the best performance.
case_input = f"案件描述:{description}\n被告人姓名:{defendant_name}"
prompt = "请你采用ADAPT框架分析以上案件中该被告人可能被判处的罪名、适用法条和刑期"
model_input_str = '\n'.join(case_input, prompt)
case_input = f"案件描述:{description}\n被告人姓名:{defendant_name}"
prompt = "请你用法律理论分析以上案件中该被告人在行为主体,起因、行为和结果,行为对象,犯罪主观四个方面的信息"
model_input_str = '\n'.join(case_input, prompt)
case_input = f"案件描述:{description}\n被告人姓名:{defendant_name}"
prompt = "请你依次列出以上案件中被告人适用的法条具体内容,以及适用该法条的原因"
model_input_str = '\n'.join(case_input, prompt)
case_input = f"案件描述:{description}\n被告人姓名:{defendant_name}\n罪名:{crimes}" # e.g., 污染环境罪
prompt = "请你分析以上案件中的量刑区间和量刑因素,并给出最后的量刑预测结果"
model_input_str = '\n'.join(case_input, prompt)
@misc{deng2024enablingdiscriminativereasoningllms,
title={Enabling Discriminative Reasoning in LLMs for Legal Judgment Prediction},
author={Chenlong Deng and Kelong Mao and Yuyao Zhang and Zhicheng Dou},
year={2024},
eprint={2407.01964},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2407.01964},
}