LegalLens: Leveraging LLMs for Legal Violation Identification in Unstructured Text

Dor Bernsohn, Gil Semo, Yaron Vazana, Gila Hayat, Ben Hagag, Joel Niklaus, Rohit Saha, Kyryl Truskovskyi

Abstract

The proliferation of unstructured data across the internet—from news reports to social media—contains latent evidence of legal breaches that often go undetected by legal professionals. This paper introduces LegalLens, a novel framework designed to identify legal violations and their victims within diverse text sources. By employing a dual-stage pipeline consisting of Named Entity Recognition (NER) and Natural Language Inference (NLI), and utilizing high-quality synthetic data validated by experts, LegalLens achieves F1-scores of up to 81.02%. Our findings highlight a performance trade-off: while smaller encoder-based models excel at token-level identification, large language models (LLMs) demonstrate superior reasoning capabilities for legal entailment.

Introduction

Modern legal practice is increasingly challenged by the sheer volume of unstructured information available online. Hidden within news articles, blog posts, and social media rants are "digital trails" of legal violations, such as data privacy breaches, consumer protection failures, and wage theft. However, existing Natural Language Processing (NLP) tools in the legal domain are often specialized for narrow tasks like contract review or judicial name extraction, leaving a significant gap in general-purpose systems capable of scanning the broader web for actionable legal breaches.

LegalLens addresses this gap by providing a versatile framework to surface potential class-action cases from everyday text. The system not only identifies that a violation has occurred but also extracts the specific regulation breached, the perpetrator, and the affected parties.

Methodology

The LegalLens framework operates through a two-stage pipeline designed to move from raw text to structured legal insight.

1. Identification via Named Entity Recognition (NER)

In the first stage, the model scans unstructured text to extract four critical entities:

  • LAW: The specific regulation or legal standard allegedly breached.
  • VIOLATION: The specific act or omission constituting the breach.
  • VIOLATED BY: The entity or individual responsible for the violation.
  • VIOLATED ON: The victim or party harmed by the action.

2. Resolution via Natural Language Inference (NLI)

The second stage focuses on legal reasoning. Using an NLI approach, the system determines whether a specific individual's account (the "premise") logically entails a known legal violation (the "hypothesis"). This allows the system to verify if a user's narrative actually constitutes a valid legal claim.

Technical Implementation

To overcome the scarcity and high cost of labeled legal data, the researchers utilized GPT-4 to generate synthetic training datasets based on real-world legal contexts. These datasets were then used to fine-tune a variety of models. The study compared traditional encoder models (BERT, RoBERTa, Legal-BERT) against open-source LLMs (Falcon-7B, Llama-2) using QLoRA (Quantized Low-Rank Adaptation) for parameter-efficient fine-tuning.

To ensure the integrity of the synthetic data, seasoned legal annotators performed a validation study, reviewing the outputs for realism and legal accuracy.

Datasets

The study introduces two new benchmark datasets designed to mimic "raw" inputs like news and social media, rather than formal court judgments:

  • LegalLens NER: Contains 2,202 labeled entities extracted from summaries of class-action complaints.
  • LegalLens NLI: Comprises 312 samples focused on four major legal domains: Consumer Protection, Privacy, TCPA (telemarketing), and Wage and Hour law.

Key Insights and Results

The Objective Function Divide

A primary finding of the research was the performance disparity between model architectures based on the task. Smaller BERT-based models outperformed larger LLMs in the NER task. The researchers attribute this to the cross-entropy loss per token used by BERT, which provides a stronger gradient signal for classification compared to the causal language modeling (next-token prediction) objective used by LLMs.

Conversely, LLMs excelled at NLI tasks. Their superior reasoning capabilities allowed them to generalize effectively to "out-of-distribution" (OOD) data, identifying violations in legal domains not explicitly covered during the fine-tuning phase.

Performance Metrics

  • NER: The roberta-base model achieved the highest performance with an F1-score of 62.69%. While specialized models like Legal-BERT were competitive, the general-purpose RoBERTa proved the most robust across diverse text types.
  • NLI: Falcon-7B was the top performer, reaching an average F1-score of 81.02% across the four legal domains.
  • Zero-Shot Capabilities: While GPT-4 showed promise in few-shot settings (achieving ~13.5% F1 for NER), it was significantly outperformed by smaller, task-specific fine-tuned models.

The AI "Turing Test" for Law

In a validation experiment, human legal experts were asked to distinguish between machine-generated and human-written legal scenarios. The experts achieved an average F1-score of only 44.86%, suggesting that synthetic data generated by LLMs is now virtually indistinguishable from human-authored legal text to trained professionals.

Limitations and Future Work

Despite its success, LegalLens faces several challenges:

  • Jurisdictional Constraints: The current model is optimized for US Common Law and may require significant adaptation for Civil Law jurisdictions.
  • Entity Complexity: The VIOLATION entity remains difficult to tag accurately due to its length and contextual complexity, often leading to truncation errors.
  • Domain Scope: Future iterations aim to expand beyond the current four domains into Intellectual Property, Environmental Law, and International Law.
  • Fact Matching: The authors plan to integrate fact-matching algorithms to cross-reference identified violations across multiple sources, further reducing the potential for false positives.

Conclusion

LegalLens demonstrates that the combination of synthetic data and a dual NER-NLI pipeline can effectively surface legal violations from the noise of the internet. By leveraging the specific strengths of both encoder models and LLMs, the framework provides a scalable solution for identifying victims of legal breaches and supporting the discovery phase of class-action litigation.

Summary updated

BibTeX
@inproceedings{bernsohn2024legallens,
  author = {Dor Bernsohn and Gil Semo and Yaron Vazana and Gila Hayat and Ben Hagag and Joel Niklaus and Rohit Saha and Kyryl Truskovskyi},
  title = {{LegalLens: Leveraging LLMs for Legal Violation Identification in Unstructured Text}},
  booktitle = {EACL},
  year = {2024},
  url = {https://openreview.net/forum?id=mxm4ijszHs},
}
Figure