Introduction

The legal industry is facing an ever-increasing volume of documents, contracts, and case law, making it challenging for lawyers and legal professionals to efficiently summarize and extract key information. Generative AI models present an opportunity to automate this process, enhancing the productivity and accuracy of legal document analysis. This research-level documentation outlines the development of a generative AI-powered legal document summarization system.

Executive Summary

This project aims to revolutionize legal research and case law analysis, with a specific focus on employment discrimination cases under Title VII of the Civil Rights Act of 1964. We have developed an advanced AI-powered system that leverages a Hybrid Retrieval-Augmented Generation (RAG) approach, combining the strengths of vector-based and graph-based methods to improve the accuracy and relevance of legal information retrieval and analysis.

Project Objectives

Background

The legal industry faces an ever-increasing volume of documents, contracts, and case law. This abundance of information presents significant challenges for legal professionals in efficiently researching, analyzing, and extracting key information. Traditional methods of legal research are time-consuming and often struggle to capture the full nuances of court cases, especially in complex areas such as employment discrimination law.

Problem Statement

Legal professionals struggle with the time-consuming and complex task of identifying relevant precedents and predicting case outcomes based on historical decisions. This can lead to inefficiencies, increased costs, and potentially inconsistent legal interpretations.

Project Scope

This project focuses on developing an AI-powered system for enhancing legal research and case law analysis, with a specific emphasis on employment discrimination cases under Title VII of the Civil Rights Act of 1964. The system incorporates advanced natural language processing techniques, including a novel Hybrid RAG approach that combines vector-based and graph-based retrieval methods.

The primary objectives of this project are:

  • Create a generative AI model capable of accurately summarizing legal documents.
  • Develop a user-friendly interface that allows legal professionals to efficiently interact with the summarization tool.
  • Evaluate the system's performance and iteratively improve it based on user feedback.
  • Deploy the solution and ensure its long-term maintenance and reliability.

Data Collection

The project team has identified the following data sources for training the generative AI model:

  • Publicly available legal case law databases
  • Curated legal document repositories from reputable law firms and legal organizations
  • Anonymized contracts and agreements from the client's own database

The data was collected from various sources, including government websites and legal databases. Below are the key sources of U.S. labor laws and court cases related to employment discrimination that were compiled for the project:

Here's the markdown converted to the requested format:

U.S. Labor Laws

  1. Employment Laws of the U.S.A:

    • Source: https://www.dol.gov/agencies/odep/publications/fact-sheets/employment-laws-disability-and-discrimination
    • Summary: Five important federal laws that protect individuals with disabilities from discrimination in employment and the job application process
  2. Major Laws of Department of Labor:

    • Source: https://www.dol.gov/general/aboutdol/majorlaws#wageand
    • Summary: Commonly applicable laws to businesses, job seekers, workers, retirees, contractors and grantees
  3. Occupational Safety & Health Administration:

    • Source: https://www.osha.gov/laws-regs/oshact/completeoshact
    • Summary: Safe and healthful working conditions for working men and women
  4. Wages & Fair Labor Standards Act:

    • Source: https://www.dol.gov/agencies/whd/flsa
    • Summary: Fair Labor Standards Act (FLSA) establishes minimum wage, overtime pay, recordkeeping, and youth employment standards
  5. Civil Rights Act, 1964:

    • Source: https://www.eeoc.gov/statutes/title-vii-civil-rights-act-1964
    • Summary: Prohibits employment discrimination based on race, color, religion, sex and national origin
  6. Equal Pay Act, 1963:

    • Source: https://www.eeoc.gov/statutes/equal-pay-act-1963
    • Summary: Prohibits sex-based wage discrimination between men and women in the same establishment who perform jobs that require substantially equal skill, effort and responsibility under similar working conditions
  7. Lilly Ledbetter Fair Pay Act of 2009:

    • Source: https://www.eeoc.gov/lilly-ledbetter-fair-pay-act-2009-original-text
    • Summary: A law enacted by Congress to bolster worker protections against pay discrimination
  8. National Labor Relations Act:

    • Source: https://www.nlrb.gov/guidance/key-reference-materials/national-labor-relations-act
    • Summary: Passed in 1935 to encourage collective bargaining by protecting workers' full freedom of association
  9. Family & Medical Leave Act:

    • Source: https://www.dol.gov/agencies/whd/fmla
    • Summary: Entitles eligible employees to take unpaid, job-protected leave for specified family and medical reasons
  10. Whistleblower Protection:

    • Source: https://www.dol.gov/general/topics/whistleblower
    • Summary: Employer cannot retaliate against you for exercising your rights under the Department of Labor's whistleblower protection laws
  11. The Pregnancy Discrimination Act of 1978:

    • Source: https://www.eeoc.gov/statutes/pregnant-workers-fairness-act
    • Summary: Requires employers to provide reasonable accommodations to employees affected by pregnancy, childbirth, or related medical conditions
  12. Title 1 of the Americans & Disabilities Act of 1990 (ADA):

    • Source: https://www.eeoc.gov/statutes/titles-i-and-v-americans-disabilities-act-1990-ada
    • Summary: Prohibits employment discrimination against qualified individuals with disabilities
  13. Age Discrimination in Employment Act of 1967:

    • Summary: Protects people who are age 40 or older from discrimination because of age
  14. The Genetic Information Nondiscrimination Act of 2008:

    • Source: https://www.eeoc.gov/statutes/genetic-information-nondiscrimination-act-2008
    • Summary: Makes it illegal to discriminate against employees or applicants because of genetic information

Supreme Court Judgments

  1. BOSTOCK v. CLAYTON COUNTY, GEORGIA:

    • Source: https://www.supremecourt.gov/opinions/19pdf/17-1618_hfci.pdf
    • Summary: An employer allegedly fired a long-time employee simply for being homosexual or transgender
  2. Muldrow v. City of St. Louis:

    • Source: https://frostbrowntodd.com/muldrow-v-city-of-st-louis-supreme-court-establishes-new-harm-standard-for-title-vii-discrimination-claims/
    • Summary: Discrimination in employment based on Gender

U.S. Employment Discrimination Statistics

  1. Workplace discrimination, Racism, Sexism, Ageism, Harassment, Mistreatment:

    • Source: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6612926/
    • Summary: Prevalence of workplace discrimination and mistreatment in a national sample of older U.S. workers
  2. Understanding Employment Discrimination statistics in U.S:

    • Source: https://www.wenzelfenton.com/blog/2022/07/18/employment-discrimination-statistics-employees-need-to-know/
    • Summary: In Fiscal Year 2022, the EEOC received 73,485 new discrimination charges
  3. Discrimination in the Job Market in the United States:

    • Source: https://www.povertyactionlab.org/evaluation/discrimination-job-market-united-states
    • Summary: Researchers examined the level of racial discrimination in the United States labor market
  4. Workplace Discrimination & Employment Law Statistics 2024:

    • Source: https://www.rekhiwolk.com/employment-law/employment-law-statistics/
    • Summary: Insights into the complex landscape of workplace discrimination in the United States

Methodology

The data was gathered using web scraping techniques and manual collection from public sites like the U.S. Department of Labor, OSHA, and the Equal Employment Opportunity Commission (EEOC). I have compiled summaries of key employment laws and court judgments, which were integral to the project's purpose of providing legal professionals with the required data.

Data Analysis

AI-Powered Insights for Case Law Analysis

AI-powered tools can enhance case law analysis by:

  • Identifying Key Themes and Patterns: AI can help identify recurring themes and patterns in judicial opinions, enabling researchers to uncover hidden insights and connections.
  • Analyzing Large Datasets: AI can quickly process and analyze large datasets of case law, providing researchers with a comprehensive understanding of the legal landscape.
  • Predicting Outcomes: AI-powered predictive models can help forecast the outcomes of cases based on historical data and trends.

Reference 1: Stanford University Law Library Guide

The Stanford University Law Library Guide provides an in-depth overview of judicial opinions and case law. Key points from this guide include:

  • Types of Judicial Opinions: The guide explains the different types of judicial opinions, including majority opinions, concurring opinions, dissenting opinions, and per curiam opinions.
  • Case Law Research: The guide offers tips and strategies for conducting case law research, including using online databases and print resources.
  • Citation and Quotation: The guide provides guidance on properly citing and quoting judicial opinions in legal writing.

Reference 2: UCSD Law Library Guide

The UCSD Law Library Guide offers additional resources and guidance on judicial opinions and case law. Key points from this guide include:

  • Judicial Opinions and Case Law: The guide explains the importance of judicial opinions and case law in shaping the US legal system.
  • Finding Judicial Opinions: The guide provides instructions on finding judicial opinions using online databases, such as Westlaw and LexisNexis.
  • Analyzing Judicial Opinions: The guide offers tips on analyzing judicial opinions, including identifying key issues and holdings.

Reference 3: Supreme Court Case

The Supreme Court case of United States v. White (401 U.S. 424) is a landmark case that illustrates the importance of judicial opinions and case law. Key points from this case include:

  • Facts and Procedural History: The case involved a challenge to the constitutionality of a federal statute that prohibited the possession of certain firearms.
  • Holding and Rationale: The Supreme Court held that the statute was constitutional, and provided a detailed rationale for its decision.
  • Impact and Significance: The case has had significant implications for the interpretation of the Second Amendment and the regulation of firearms.

Exploratory Data Analysis

  • Identifying common legal concepts, terminology, and structure
  • Analyzing the distribution of document lengths, sections, and complexity
  • Examining the presence of key information, such as parties, dates, and jurisdictions

Identifying Key Legal Concepts

Based on the EDA and domain expertise, the team will identify the most important legal concepts and entities that should be prioritized in the document summarization task. This will guide the fine-tuning of the generative AI model.

Model Development

Approaches Explored

Methodology

Our methodology involved implementing and comparing three distinct approaches: Vector RAG, Graph RAG, and Hybrid RAG. We used a combination of open-source libraries and custom implementations to build each system.

  • For Vector RAG, we utilized the LlamaIndex library, which provides efficient tools for document indexing and retrieval. We used the BAAI/bge-small-en-v1.5 model for generating embeddings and Qdrant as our vector database.

  • For Graph RAG, we employed Neo4j as our graph database and used a combination of LangChain and NetworkX for graph creation and querying.

  • The Hybrid RAG approach combined elements from both Vector and Graph RAG, using custom implementations to integrate the two methods seamlessly.

Language Model Selection

The project team will evaluate several state-of-the-art generative language models, such as GPT-3, BERT, and T5, to determine the most suitable model for the legal document summarization task. Factors like performance, domain-specific knowledge, and inference speed will be considered.

Vector RAG (Retrieval-Augmented Generation)

Vector RAG uses dense vector embeddings to capture semantic meanings in legal text. This approach is particularly effective for understanding nuances in legal language, including complaints, arguments, and opinions.

Key Components:

  • Embedding Model: BAAI/bge-small-en-v1.5
  • Vector Database: Qdrant
  • Retrieval Method: Semantic similarity search

In Vector RAG, documents and queries are converted into vector representations. When a query is processed, the system retrieves semantically similar documents or passages from the Qdrant database. This allows for nuanced understanding of legal concepts beyond simple keyword matching.

Strengths:

  • Excellent at capturing semantic similarities and nuances in legal text
  • Efficient for retrieving relevant information based on meaning rather than exact keyword matches

Limitations:

  • May not explicitly capture structured relationships between legal entities

Graph RAG

Graph RAG constructs a knowledge graph to represent and query structured relationships between legal entities and concepts. This approach excels at capturing and querying the structured aspects of legal cases.

Key Components:

  • Graph Database: Neo4j
  • Entity Types: Judges, courts, plaintiffs, defendants, attorneys
  • Relationship Types: PRESIDES_OVER, HEARD_IN, REPRESENTS, CITES, etc.

In Graph RAG, legal documents are processed to extract entities and relationships, which are then stored in the Neo4j database. Queries can traverse these relationships to find relevant information, such as all cases heard by a specific judge or all precedents cited in a particular case.

Strengths:

  • Excels at representing and querying structured relationships in legal cases
  • Provides clear visibility into the connections between different legal entities

Limitations:

  • May not fully capture the semantic nuances in legal arguments and opinions

Graph Rag

Hybrid RAG

The Hybrid RAG approach combines both Vector RAG and Graph RAG methods to leverage their respective strengths.

In this approach:

  1. A query is processed by both the vector and graph components.
  2. The vector component retrieves semantically similar passages from Qdrant.
  3. The graph component retrieves relevant structured information from Neo4j.
  4. Results from both are combined and sent to the Language Model (LLM) for final answer generation.

This hybrid approach allows for comprehensive analysis of legal documents, capturing both semantic nuances and structured relationships. It enables flexible querying for both unstructured aspects of legal information and structured entity relationships.

Design Diagram

Hybrid Rag

Fine Tuning The Model

The selected language model will be fine-tuned on the preprocessed legal documents to enhance its understanding of legal terminology, document structure, and the task of summarization. Techniques like transfer learning and prompt engineering will be explored.

Generating Summaries

The fine-tuned model will be used to generate concise summaries of legal documents, focusing on the key information, such as parties, dates, jurisdictions, and legal conclusions.

Ui Design And Deployment

User Interface Mockups

The design team will create user interface mockups that prioritize the needs of legal professionals, ensuring the summarization tool is intuitive and efficient to use. The mockups will include features like document upload, summary generation, and customization options.

Front End Implementation

The approved UI designs will be implemented using modern front-end technologies, ensuring a responsive and visually appealing user experience.

Integration With Backend

The front-end will be seamlessly integrated with the backend, which will handle the document processing, model inference, and summary generation.

Evaluation, Finetuning And Refinement

Objective

The purpose of the finetuning and evaluation process is to prepare the application to perform Question and Answer (Q&A) and Summarization tasks within the legal domain.

Selection of the model:

An initial study was conducted on various language models to assess their suitability for legal research tasks. The following models were shortlisted for further exploration based on their architecture and legal domain-specific finetuning:

  1. AdaptLLM/law-chat

    • Finetuned on LLaMA-2-Chat-7B.
    • Quantized versions are available (GGUF, GPTQ).
  2. SaulLM

    • Finetuned on Mistral-7B.
    • Quantized version available (GGUF).
  3. legalbert-base

    • Finetuned on BERT and uses a masked language modeling approach.
  4. Legalbert-large

    • Finetuned on BERT with 1.7M parameters, trained on the "Pile of Law" dataset.
    • May exhibit racial biases.

Model Features Comparison

Featureslegal-llmLegalbert-pile of lawsaul7b
DatasetFreeLaw Opinions from the Pile (Gao et al., 2021)Pile of lawFreeLaw, EDGAR, English MultiLegal Pile, English EuroParl, GovInfo7 Statutes, Opinions & Codes, Law Stack Exchange, Commercial Open Australian Legal Corpus, EU Legislation, UK Legislation, Court Transcripts, UPSTO1
Tokens16.7B~30B94B
TasksMasked

Dataset for 'Pile of Law'

The "Pile of Law" dataset includes various data sources, such as:

Pile of law

Comparison Study

SaulLM-7B

SaulLM-7B is a large language model (LLM) specifically designed for the legal domain. It has 7 billion parameters and is built on the Mistral-7B architecture. Trained on an English legal corpus of over 30 billion tokens, SaulLM-7B excels in legal document comprehension and generation tasks, demonstrating state-of-the-art capabilities in understanding legal texts.

AdaptLLM

AdaptLLM is further trained on reading comprehension texts constructed from raw legal corpora mixed with general instructions. This approach allows the model to learn from large-scale domain-specific raw corpora and improves its performance in comprehension tasks, making it more suitable for legal research.

LegalBERT

LegalBERT models are finetuned on BERT, with two variants, Legalbert-base and Legalbert-large. But this model possesses a potential bias issue.

Based on the application's use cases, AdaptLLM is chosen as it performs better than the other models in legal research tasks.

Evaluation Process

LLM Evaluation

To evaluate the performance of the LLM, the similarity between the LLM-generated answers and the ground truth answers was measured. The evaluation employed BertScore, with metrics such as Precision, Recall, and F1 Score.

Methodology:

  1. A dataset of questions and ground truth answers was manually verified for quality.
  2. The questions were fed to the LLM to generate corresponding answers.
  3. The generated answers were compared to the ground truth using BertScore.

Evaluating RAG (Retrieval-Augmented Generation) Capabilities

The faithfulness of the LLM-generated answers was assessed by checking whether the generated answers were factually consistent with the context. HHEM (The Hughes Hallucination Evaluation Model) from Vectara was used for computing faithfulness.

Methodology:

  1. A dataset of questions, context, and ground truth answers was prepared and verified.
  2. The questions and context were input into the LLM to generate answers.
  3. The similarity between the context and the LLM-generated answer was evaluated using HHEM.

Results:

Results of LLM Evaluation are shown below:

  • Sample size: 500
  • Mean Precision: 0.8852
  • Mean Recall: 0.8942
  • Mean F1 Score: 0.8889

And the following is the Faithfulness evaluation results:

  • Sample size: 290
  • HHEM Score: 0.88

Evaluation Methodologies

We used the RAGAS framework to evaluate our RAG systems, focusing on the following metrics:

  • Faithfulness: Measures how well the generated answer aligns with the provided context
  • Answer Relevance: Assesses how well the answer addresses the original question
  • Context Relevance: Evaluates the relevance of retrieved context chunks
  • Context Recall: Measures how well the retrieved context aligns with the ground truth answer

Evaluation Results

[This section needs to be filled with numerical results after testing]

Rationale for Choosing Hybrid RAG

We ultimately chose the Hybrid RAG approach for the following reasons:

  • Comprehensive Information Capture: Captures both structured relationships and semantic nuances
  • Enhanced Entity Representation: Maintains clear representation of legal entities and relationships
  • Improved Semantic Understanding: Ensures deep understanding of complex legal language
  • Flexible Querying: Allows for both structured and open-ended legal queries
  • Improved Accuracy: Leverages both structured and unstructured information for comprehensive responses

User Feedback

The generative AI-powered legal document summarization system will be tested by a group of legal professionals, who will provide feedback on the tool's accuracy, usefulness, and user experience.

Iterative Improvements

Based on the user feedback, the project team will make iterative improvements to the model, user interface, and overall system performance. This may involve further fine-tuning of the language model, UI enhancements, and integration of additional features.

Deployment And Maintenance

Deployment Strategy

The refined legal document summarization system will be deployed as a web-based application, allowing legal professionals to access the tool from any device with an internet connection.

Monitoring And Maintenance

The project team will implement robust monitoring and maintenance processes to ensure the ongoing reliability and performance of the deployed system. This will include:

  • Continuous monitoring of summary quality and user feedback
  • Periodic retraining and fine-tuning of the language model
  • Proactive software updates and security patches
  • Scalable infrastructure to handle increasing user demand

Challenges and Future Work

  • Scalability: Optimize for large-scale legal databases
  • Fine-tuning: Improve balance between vector and graph components
  • Explainability: Enhance reasoning capabilities
  • Expansion: Adapt to broader range of legal domains

Ethical Considerations

When developing a generative AI system for the legal domain, it is crucial to consider the ethical implications. The team will ensure that the summarization tool does not introduce biases, respects client confidentiality, and aligns with the legal profession's ethical standards. Appropriate safeguards and transparency measures will be implemented to maintain the trust and confidence of legal professionals.

Conclusion

This research-level documentation outlines the development of a generative AI-powered legal document summarization system, addressing the key requirements of data collection, data analysis, model development, and UI design and development. By leveraging the latest advancements in language models and user-centric design, the project aims to enhance the productivity and accuracy of legal document analysis, ultimately benefiting legal professionals and their clients.

The Hybrid RAG approach represents a significant advancement in AI-powered legal research and analysis. By combining the strengths of vector-based semantic understanding and graph-based structured relationship representation, our system offers a more comprehensive and nuanced approach to legal document analysis. This project demonstrates the potential of AI to enhance the efficiency and accuracy of legal research, particularly in complex areas such as employment discrimination law.

References

  1. Chalkidis, I., Fergadiotis, M., Malakasiotis, P., Aletras, N., & Androutsopoulos, I. (2019). Legal-BERT: The Muppets straight out of Law School. arXiv preprint arXiv:1903.10225.

  2. Sukhbaatar, H., Khishigsuren, B., Ganbold, A., Gankhuyag, G., & Aulov, O. (2020). Automatic summarization of Mongolian legal documents. Proceedings of the 28th International Conference on Computational Linguistics.

  3. Zhong, H., Xiao, C., Tu, C., Zhang, T., Liu, Z., & Sun, M. (2020). JEC-QA: A Legal-domain Question Answering Dataset. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.

  4. https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/6649331/d12d0c30-b74e-4474-b819-e9945e2ca17a/paste.txt

  5. https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/6649331/fa9791ca-2ef5-4fd1-90eb-3db699c2dc55/rag_evaluate_ragas-1.ipynb

Appendices

  • Glossary of Terms
  • System Architecture Diagram

  • Detailed Evaluation Metrics
  • Sample Queries and Responses

Citations

Contributors

NameGitHubLinkedIn
Hulejigithub.com/kinghendrix10linkedin.com/in/huleji-tukura
Jaelin Leegithub.com/jaelin215linkedin.com/in/jaelin-lee-23678458
Narayan Adhikarigithub.com/adhikarinarayanlinkedin.com/in/adhikarinarayan
Rana Kabirajgithub.com/Rakabi007linkedin.com/in/rana-kabiraj-991495167
Hanieh Moshkigithub.com/haniehmlinkedin.com/in/hanieh-moshki-b90a132
Trishika Boyilagithub.com/boyilalinkedin.com/in/trishikab
Namya Kgithub.com/nxmyx-klinkedin.com/in/namya-kumar/
Subhrajit Makurgithub.com/avyukthlinkedin.com/in/subhrajitmakur
Ednalyn De Diosgithub.com/michaeldavislinkedin.com/in/michaeldavis
Saurav Yadavgithub.com/sauravyadav01linkedin.com/in/saurav-yadav-b4051b246
William Greengithub.com/wbgreen0405linkedin.com/in/greenwilliam
Soumya Shastrigithub.com/Soumya-Shastrilinkedin.com/in/soumya-shastri-629756192
Cristian Moralesgithub.com/crismolavlinkedin.com/in/cmoraleso
Safni Usmangithub.com/UsmanSafnilinkedin.com/in/safniusman
Chhavi Kirtanigithub.com/chhavikirtani2000linkedin.com/in/chhavi-kirtani-85b347178
Kaustubh Patilgithub.com/alexanderthompsonlinkedin.com/in/kaustubh-patil-5825811a2
Nijaguna Darshangithub.com/nijdarshanlinkedin.com/in/nijaguna-darshan
Eshaan Kushwahagithub.com/abigailleelinkedin.com/in/eshaan-kushwaha-335b7a1b1
Rohan Manigithub.com/rohan-mani96linkedin.com/in/rohan-mani-profile/
Melat Kebedegithub.com/MelatKebedeAbrahamlinkedin.com/in/melat-kebede-291309203
Tasbirul Alomgithub.com/tasbirullinkedin.com/in/tasbirul
Sweta Jenagithub.com/sweta-jenalinkedin.com/in/sweta-jena
Nikhil Mekkattuparambangithub.com/Nikhil-Mekkattuparambanlinkedin.com/in/Nikhil-Mekkattuparamban
Novedeep Jeerhgithub.com/NovedeepJeerhlinkedin.com/in/novedeep-jeerh/
Komal Patragithub.com/Komal-patralinkedin.com/in/komal-patra
Rohan Guptagithub.com/roohanguptaalinkedin.com/in/rohan-gupta-064614209
John Paulgithub.com/dvhub7linkedin.com/in/otiz/