CaseEncoder: A Knowledge-enhanced Pre-trained Model for Legal Case Encoding

Yixiao Ma, Yueyue Wu, Weihang Su, Qingyao Ai, Yiqun Liu

Introduction

In the legal domain, the ability to retrieve relevant precedents is fundamental to the judicial process. Legal case retrieval involves identifying prior cases that share critical legal elements with a current case to ensure consistency in sentencing and judgment. However, traditional information retrieval methods and general-domain pre-trained language models (PLMs) often fall short in this specialized field. This paper introduces CaseEncoder, a specialized PLM designed to bridge the gap between natural language processing and legal reasoning through structured knowledge integration and a novel contrastive learning objective.

Existing approaches to legal case retrieval typically rely on continuing the training of standard models (like BERT) on large corpora of legal text. While this helps the model learn legal vocabulary, it fails to address two core challenges:

  1. Surface-level Adaptation: Standard models do not inherently understand the underlying legal logic or the specific criteria judges use to determine relevance. They treat legal text as generic natural language.
  2. The Relevance Spectrum: Unlike general search, where a document is often either relevant or not, legal cases exist on a spectrum. Relevance is determined by "key circumstances" (factual details) and "key elements" (legal abstractions). Existing models struggle to capture these fine-grained distinctions, often treating all "positive" matches as identical.

Methodology: CaseEncoder

CaseEncoder addresses these limitations through a two-phase approach: fine-grained case sampling and legal-specific pre-training.

1. Fine-grained Case Sampling

To move beyond binary relevance labels, the authors developed a sampling method that leverages structured law article knowledge. They decomposed law articles into unambiguous branches. For instance, an article regarding "Dangerous Driving" might be split into distinct branches for "racing" versus "drunk driving."

The process involves:

  • Extracting Holdings: The model focuses on the "Holding" section of a case—the part where the judge explains their legal reasoning—rather than just the raw "Facts."
  • Mapping to Law Branches: Using BM25, the Holdings are matched to specific law article branches.
  • Calculating Relevance Weights ($w_{ij}$): By analyzing the overlap in law article branches between cases, the authors calculate a continuous relevance weight. This provides a much richer training signal than a simple binary label.

CaseEncoder utilizes two primary training tasks to refine its embeddings:

  • Masked Language Modeling (MLM): Applied specifically to the "Facts" section of legal documents, this helps the model learn to identify and represent "key circumstances."
  • Biased Circle Loss (BCL): This is the core innovation of the pre-training phase. While standard contrastive learning pushes all positive pairs together with equal force, BCL uses the relevance weights ($w_{ij}$) derived from the sampling phase to scale the "push" and "pull" operations. This forces the model to learn that some cases are more legally relevant than others, effectively capturing the nuances of the legal relevance spectrum.

Evaluation and Results

CaseEncoder was evaluated on three major Chinese legal benchmarks: LeCaRD, CAIL2021-LCR, and CAIL2022-LCR. It was compared against several strong baselines, including BERT-XS, Lawformer, and RoBERTa-Legal.

Performance Metrics

CaseEncoder consistently outperformed all baselines across key metrics such as NDCG@10, 20, and 30. On the LeCaRD dataset, CaseEncoder achieved an NDCG@30 of 0.839, a significant improvement over RoBERTa-Legal (0.806) and Lawformer (0.636).

Key Insights

  • The Importance of Holdings: The research confirms that the judge’s reasoning (the Holding) is a superior indicator of legal relevance compared to raw factual descriptions. Aligning these Holdings with structured law articles effectively bridges the gap between natural language and legal logic.
  • Ablation Results: Ablation studies revealed that removing the Biased Circle Loss resulted in the most significant performance drop, highlighting BCL as the model's most critical component.
  • Zero-Shot Capability: CaseEncoder demonstrated strong performance in zero-shot settings, suggesting a robust ability to generalize to new types of crimes without specific fine-tuning.
  • Embedding Quality: t-SNE visualizations indicated that CaseEncoder produces embeddings that cluster cases by criminal charge (e.g., Bribery vs. Theft) much more distinctly than competing models.

Conclusion and Future Directions

CaseEncoder represents a significant advancement in legal case retrieval by integrating domain-specific knowledge into the pre-training process. By moving beyond binary relevance and focusing on the legal logic embedded in judicial Holdings, the model achieves state-of-the-art performance.

Future work will address current limitations, including expanding the model's capacity for longer document sequences and adapting the "unambiguous branch" logic to civil and administrative law. Additionally, while the current study focuses on the Chinese legal system, the framework offers a promising template for adaptation to Common Law jurisdictions.

Summary updated

BibTeX
@inproceedings{ma2023caseencoder,
  author = {Yixiao Ma and Yueyue Wu and Weihang Su and Qingyao Ai and Yiqun Liu},
  title = {{CaseEncoder: A Knowledge-enhanced Pre-trained Model for Legal Case Encoding}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.441},
}
Figure