Lawyer LLaMA Technical Report

Quzhe Huang, Mingxu Tao, Zhenwei An, Chen Zhang, Cong Jiang, Zhibin Chen, Zirui Wu, Yansong FengarXiv 2023

Abstract

Large Language Models (LLMs), like LLaMA, have exhibited remarkable performance across various tasks. Nevertheless, when deployed to specific domains such as law or medicine, the models still confront the challenge of a deficiency in domain-specific knowledge and an inadequate capability to leverage that knowledge to resolve domain-related problems. In this paper, we propose a new framework to adapt LLMs to specific domains and build Lawyer LLaMA, a legal domain LLM, based on this framework. Specifically, we inject domain knowledge during the continual training stage and teach the model to learn professional skills using properly designed supervised fine-tuning tasks. Moreover, to alleviate the hallucination problem during the model's generation, we add a retrieval module and extract relevant legal articles before the model answers any queries. When learning domain-specific skills, we find that experts' experience is much more useful than experiences distilled from ChatGPT, where hundreds of expert-written data outperform tens of thousands of ChatGPT-generated ones. We will release our model and data.

Introduction

While general-purpose LLMs like LLaMA are impressive, they often "fail the bar" when applied to specialized domains like law. The authors identify three primary hurdles:

  1. Knowledge Gaps: General models lack specific, up-to-date legal knowledge (e.g., the legal age of marriage in a specific jurisdiction).
  2. Reasoning Deficits: Even when they have the facts, models struggle to apply abstract legal articles to messy, real-world scenarios.
  3. Hallucinations: In legal contexts, "making things up" isn't just a quirk—it’s a liability. Models often cite non-existent articles or outdated regulations.

Methodology

The authors propose a three-stage framework to transform a general model into a legal professional:

  1. Injecting Knowledge (Continual Pre-training): The model was first trained on a massive corpus of Chinese legal texts, including judgments, interpretations, and news, to build a foundational legal vocabulary.
  2. Learning Reasoning (Supervised Fine-Tuning): To teach the model how to think like a lawyer, questions from the National Judicial Examination (JE) were used. The training pipeline compared different data sources to determine the most effective way to teach legal reasoning.
The multi-stage training pipeline for Lawyer LLaMA, showing the evolution from a general model to a legal specialist.
  1. Retrieval-Augmented Generation (RAG): A retrieval module was added to pull relevant legal articles for every query. Crucially, the model was trained to filter out irrelevant "noise" by including distractor articles during training, teaching it to distinguish between applicable law and irrelevant information.

Key Insights and Results

The most striking finding was the impact of data quality over quantity. The researchers compared three fine-tuning datasets:

  • JE-Q2EA: 42,000 explanations generated by ChatGPT.
  • JE-QA2E: 6,000 higher-quality ChatGPT explanations.
  • JE-EXPERT: Only 850 explanations written by human legal experts.
Human evaluation rankings showing that the model fine-tuned on 850 expert samples (EXPERT) significantly outperformed those trained on much larger ChatGPT-distilled datasets.

As shown in the evaluation, the model trained on 850 expert-written samples significantly outperformed the model trained on 42,000 ChatGPT samples. In head-to-head human evaluations, the JE-EXPERT model was ranked as the best (Rank 1) in 35.14% of cases, compared to only 17.83% for the model trained on 6,000 ChatGPT samples.

Other key results include:

  • Legal Accuracy: Continual pre-training alone boosted accuracy on Charge Prediction tasks from 18.89% to 73.56%.
  • Hallucination Reduction: The retrieval module and "filtering" training reduced the fabrication of non-existent legal articles from 64.8% to 25.9%.
  • Domain Synergy: Fine-tuning on legal reasoning improved performance on general Chinese logic tasks (CMNLI), suggesting legal training sharpens general analytical capabilities.

Conclusion and Future Work

Lawyer LLaMA demonstrates that for professional domains, human expertise is indispensable. While expert data is more expensive and slower to collect than synthetic data, its impact on model reasoning is disproportionately high. Currently, the model focuses primarily on marriage and family law. Future work will involve expanding this expertise to civil, criminal, and administrative law, and exploring the scaling laws of ChatGPT-distilled data versus expert data.

Summary updated

BibTeX
@misc{huang2023lawyer,
  author = {Quzhe Huang and Mingxu Tao and Zhenwei An and Chen Zhang and Cong Jiang and Zhibin Chen and Zirui Wu and Yansong Feng},
  title = {{Lawyer LLaMA Technical Report}},
  year = {2023},
  eprint = {2305.15062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.15062},
}
Figure