Leveraging open-source models for legal language modeling and analysis: a case study on the Indian constitution
Vikhyath Gupta, Srinivasa Rao P
TL;DR
This study tackles the challenge of applying open-source NLP to legal language by fine-tuning a Flan-T5-XXL model on the Indian Constitution using Hugging Face embeddings, LangChain, and ChromaDB. The approach preprocesses PDF text, chunks it for efficient processing, and trains the model to perform tasks such as keyword extraction, summarization, and sentiment analysis, with outcomes measured by metrics like $F1$. The findings demonstrate that an open-source, domain-adapted LLM can effectively analyze complex constitutional text, offering a scalable and cost-effective tool for legal research, policy analysis, and automated document review. The work highlights the potential for cross-jurisdictional legal NLP and advocates for broader adoption alongside careful attention to privacy, bias, and ethical deployment.
Abstract
In recent years, the use of open-source models has gained immense popularity in various fields, including legal language modelling and analysis. These models have proven to be highly effective in tasks such as summarizing legal documents, extracting key information, and even predicting case outcomes. This has revolutionized the legal industry, enabling lawyers, researchers, and policymakers to quickly access and analyse vast amounts of legal text, saving time and resources. This paper presents a novel approach to legal language modeling (LLM) and analysis using open-source models from Hugging Face. We leverage Hugging Face embeddings via LangChain and Sentence Transformers to develop an LLM tailored for legal texts. We then demonstrate the application of this model by extracting insights from the official Constitution of India. Our methodology involves preprocessing the data, splitting it into chunks, using ChromaDB and LangChainVectorStores, and employing the Google/Flan-T5-XXL model for analysis. The trained model is tested on the Indian Constitution, which is available in PDF format. Our findings suggest that our approach holds promise for efficient legal language processing and analysis.
