DeliLaw: A Chinese Legal Counselling System Based on a Large Language Model

Nan Xie, Yuelin Bai, Hengyuan Gao, Feiteng Fang, Qixuan Zhao, Zhijian Li, Ziqiang Xue, Liang Zhu, Shiwen Ni, Min YangCIKM 2024 · DOI

TL;DR

This paper introduces DeliLaw, a novel Chinese legal counseling system that leverages a large language model (LLM) to provide accurate and context-aware legal information. By integrating specialized legal retrieval and case retrieval modules, DeliLaw aims to overcome the "hallucination" problem common in LLMs and offer users professional legal advice, article searches, and case retrieval in a conversational format.

What Problem Does This Paper Address?

Traditional legal retrieval systems often struggle with semantic understanding, failing to provide satisfactory answers to complex legal questions. While large language models (LLMs) have shown promise in various domains, their application in specialized fields like Chinese law is hindered by the scarcity of high-quality, fine-tuned data and the inherent issue of generating factually incorrect or fabricated information (hallucination). Existing Chinese legal LLMs, even those fine-tuned on legal data, often fall short of practical application due to these challenges.

Methods

DeliLaw employs a multi-module approach to address the limitations of standalone LLMs:

  • Intent Classifier: A RoBERTa-large based model trained to classify user queries into four categories: "LawQuestion," "LawSearch," "CaseSearch," and "General." This allows for targeted routing of queries to the appropriate system module.
  • Law Retriever: This module utilizes a fine-tuned BGE-large-zh-v1.5 embedding model for dense retrieval of legal statutes. The fine-tuning process involves a two-stage approach using query-statute pairs from the internet and LLM-generated data, incorporating in-batch negatives and BM25-mined hard negatives to improve accuracy. It retrieves the top three most similar statutes.
  • Case Retriever: For its large case database, DeliLaw uses a two-step approach: first, keywords are extracted from the query, and then ElasticSearch is used to retrieve relevant cases based on these keywords.
  • Law-specific Fine-tuned LLM: The core LLM is fine-tuned on a combination of open general data and high-quality, lawyer-annotated legal Q&A data. This fine-tuning process aims to enhance the model's legal knowledge and conversational abilities.
  • Inference Process: For "LawQuestion" queries, the system first calls the Law Retriever, then uses a prompting process to combine the retrieved laws with the user's question, feeding this into the fine-tuned LLM for a comprehensive answer.

Datasets

  • Open General Data: Collected Chinese public datasets to maintain the LLM's general conversational capabilities.
  • Legal Q&A Data: A large amount of legal Q&A data from legal websites, cleaned and enriched by extracting cited legal texts and using GPT-3.5 for answer expansion.
  • Human Annotated Data: 3,492 manually annotated data points covering seven common areas of law (intellectual property, criminal offenses, labor disputes, property disputes, corporate compliance, matrimonial and family matters, and urban renewal) to ensure professionalism and accuracy.
  • Cause of Actions in GPT-4 Data: Data augmented by curating diverse legal contexts, including criminal and administrative case inquiries, with the top five most pertinent statutes extracted and refined by legal professionals.
  • Judicial Syllogism Data: Collated complex legal inquiries from various sources, with expert-crafted answers following a judicial syllogism framework (statutes as major premises, case facts as minor premises, judgments as conclusions).
  • Guided Conversations Data: Inspired by multi-turn dialogues, this dataset was generated using GPT-4 to simulate client-attorney interactions in legal consultations.

Key Insights and Ideas

  • Modular Approach for Accuracy: The integration of specialized retrieval modules (Law Retriever and Case Retriever) alongside the LLM is crucial for grounding responses in factual legal information and mitigating hallucinations.
  • Importance of High-Quality Legal Data: The paper emphasizes that even with LLMs, the quality and domain-specificity of training data, especially lawyer-annotated data, are paramount for achieving practical legal applications.
  • Two-Stage Fine-tuning for Retrieval: The layered fine-tuning strategy for the Law Retriever, incorporating both in-batch and hard negatives, significantly improves its ability to identify relevant legal statutes.
  • Bridging the Gap to Practical Application: DeliLaw represents a significant step towards making LLMs truly useful in complex, high-stakes domains like law, moving beyond general-purpose capabilities.

Key Results

  • The Intent Classifier achieved high accuracy: 99.9% for "LawQuestion," 100% for "LawSearch" and "CaseSearch," and 99.6% for "General" on an internal test set.
  • The Law Retriever demonstrated strong performance with an MRR of 61.6% and a Recall of 71.1% under three regulatory frameworks.
  • Human evaluation across 100 test questions showed DeliLaw outperforming baselines like ChatGPT, Baichuan, and ChatGLM2 in providing accurate references and logical applicability. DeliLaw was also noted to perform better than TongYiFaRui in 30 evaluation questions.
  • The system currently serves over 20,000 professional users and handles nearly 3,000 calls daily, indicating practical adoption and utility.

Limitations and Future Work

  • Limitations: The paper notes that while the collected data improved the model's ability to understand queries, the questions were relatively short, potentially limiting the model's understanding of longer, more complex legal inquiries.
  • Future Work: The authors plan to focus on enhancing the system's contextual understanding, broadening its coverage of legal fields, and further optimizing the user experience.

Summary updated

BibTeX
@inproceedings{xie2024delilaw,
  author = {Nan Xie and Yuelin Bai and Hengyuan Gao and Feiteng Fang and Qixuan Zhao and Zhijian Li and Ziqiang Xue and Liang Zhu and Shiwen Ni and Min Yang},
  title = {{DeliLaw: A Chinese Legal Counselling System Based on a Large Language Model}},
  booktitle = {ACM International Conference on Information and Knowledge Management},
  year = {2024},
  doi = {10.1145/3627673.3679219},
}
Figure