CS781-Legal-Models / README.md
sarweshbarnwal's picture
Add comprehensive Model Card and Phase documentation README
b23de38 verified
|
Raw History Blame Contribute Delete
5.87 kB
---
language:
- en
license: other
tags:
- legal
- indian-legal
- custom-decoder
- peft
- lorma
- lora
- qlora
- adalora
- knowledge-distillation
- pytorch
- cs781
- iit-kanpur
pipeline_tag: text-generation
---
# CS-781 Legal Language Models (IIT Kanpur)
Master repository hosting the foundation models, Parameter-Efficient Fine-Tuning (PEFT) adapters, and evaluation artifacts for the **CS-781 Capstone Project: Legal Language Modelling Challenge** at the **Indian Institute of Technology Kanpur (IITK)** under the supervision of **Prof. Ashutosh Modi**.
---
## πŸ›οΈ Project & Research Overview
This repository establishes a unified model hub for legal NLP tailored to the jurisdictional, statutory, and linguistic complexities of the **Indian Judicial System**, benchmarked against the [IL-TUR](https://arxiv.org/abs/2407.05399) benchmark.
In strict compliance with competition constraints:
- **Zero Pretrained Weights:** No commercial LLMs (GPT-4, Claude, Gemini) or off-the-shelf open-source checkpoints (BERT, LLaMA-3, Mistral) were utilized.
- **Scratch Foundation Pretraining:** Four decoder-only transformer architectures were pre-trained strictly from scratch on Indian Supreme Court and High Court judgments.
---
## 🧠 Phase 1 Foundation Models (Trained from Scratch)
| Model Subfolder | Architecture Style | Layers | $d_{\text{model}}$ | Attention Heads (Q / KV) | Max Context | Parameters | Core Structural Innovation |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| **`model1-deep-llama-135m/`** | Deep LLaMA Causal Decoder | 16 | 768 | 12 / 4 (GQA 3:1) | 1024 | 134.7M | Deep representational capacity, RMSNorm, SwiGLU FFN |
| **`model2-wide-mistral-136m/`** | Wide Mistral Long-Flow | 12 | 896 | 14 / 7 (GQA 2:1) | 1536 | 136.2M | Wide channel dimension, extended 1536 context flow |
| **`model3-statutory-mha-110m/`** | Statutory Precision Decoder | 12 | 768 | 12 / 12 (Full MHA) | 1024 | 109.5M | Full unshared multi-head attention for fine syntax |
| **`model4-capacity-boundary-154m/`** | Peak Capacity Boundary | 14 | 896 | 14 / 14 (Full MHA) | 1024 | 153.9M | Tied embeddings, peak capacity boundary model |
---
## πŸ“‚ Repository Checkpoint Architecture
Checkpoints and CodaBench evaluation files are continuously synchronized from Kaggle Dual-T4 training sessions into dedicated phase namespaces:
```text
sarweshbarnwal/CS781-Legal-Models/
β”œβ”€β”€ model1-deep-llama-135m/ # Phase 1 scratch-trained backbone
β”œβ”€β”€ model2-wide-mistral-136m/ # Phase 1 scratch-trained backbone
β”œβ”€β”€ model3-statutory-mha-110m/ # Phase 1 scratch-trained backbone
β”œβ”€β”€ model4-capacity-boundary-154m/ # Phase 1 scratch-trained backbone
β”‚
β”œβ”€β”€ Phase_7/ # Prior Case Retrieval (PCR)
β”‚ β”œβ”€β”€ sub01_model4_full_ft_hierarchical/
β”‚ β”œβ”€β”€ sub02_model1_true_lorma_hard_negs/ # COMPULSORY LoRMA
β”‚ β”œβ”€β”€ sub03_model2_qlora_ratio/
β”‚ β”œβ”€β”€ sub04_model1_adalora_margin_mse/
β”‚ β”œβ”€β”€ sub05_model2_houlsby_cosent/
β”‚ β”œβ”€β”€ sub06_model3_distill_alignment/ # MANDATORY KD
β”‚ β”œβ”€β”€ sub07_model4_bm25_dense_hybrid/
β”‚ └── sub08_master_ensemble/
β”‚
β”œβ”€β”€ Phase_6/ # Abstractive Summarization
β”‚ β”œβ”€β”€ sub01_model4_full_ft/
β”‚ β”œβ”€β”€ sub02_model1_true_lorma/ # COMPULSORY LoRMA
β”‚ β”œβ”€β”€ sub03_model2_qlora/
β”‚ β”œβ”€β”€ sub04_model1_adalora/
β”‚ β”œβ”€β”€ sub05_model2_houlsby/
β”‚ β”œβ”€β”€ sub06_model4_to_model3_distill/ # MANDATORY KD
β”‚ β”œβ”€β”€ sub07_model4_hierarchical_summary/
β”‚ └── sub08_master_ensemble/
β”‚
β”œβ”€β”€ Phase_5/ # Legal Statute Identification (LSI)
β”‚ β”œβ”€β”€ sub01_model4_full_ft_asl/
β”‚ β”œβ”€β”€ sub02_model1_true_lorma/ # COMPULSORY LoRMA
β”‚ β”œβ”€β”€ sub03_model2_qlora/
β”‚ β”œβ”€β”€ sub04_model1_adalora/
β”‚ β”œβ”€β”€ sub05_model2_houlsby/
β”‚ β”œβ”€β”€ sub06_model4_to_model3_distill/ # MANDATORY KD
β”‚ β”œβ”€β”€ sub07_model4_hierarchical_pool/
β”‚ └── sub08_master_ensemble/
β”‚
β”œβ”€β”€ Phase_4/ # Court Judgment Prediction (CJPE)
β”‚ β”œβ”€β”€ sub01_model4_full_ft/
β”‚ β”œβ”€β”€ sub02_model1_true_lorma/ # COMPULSORY LoRMA
β”‚ β”œβ”€β”€ sub03_model2_qlora/
β”‚ β”œβ”€β”€ sub04_model1_adalora/
β”‚ β”œβ”€β”€ sub05_model2_houlsby/
β”‚ β”œβ”€β”€ sub06_model4_to_model3_distill/ # MANDATORY KD
β”‚ β”œβ”€β”€ sub07_model4_hierarchical_pool/
β”‚ └── sub08_master_ensemble/
β”‚
β”œβ”€β”€ Phase_3/ # Rhetorical Role Prediction (RR)
└── Phase_2/ # Legal Named Entity Recognition (L-NER)
```
---
## πŸ”¬ Methodological Innovations
### 1. Compulsory Method: True Multiplicative LoRMA
Implemented according to Bihany, Patel, and Modi (2025):
$$y_{\text{adapted}} = y + \frac{\alpha}{r} B( A(y) )$$
- Zero-initialized $B$ strictly guarantees identity mapping at step 0.
- All base model weights are frozen; trainable parameters $< 1.5\%$.
### 2. Mandatory Method: Cross-Model Knowledge Distillation
Transfers rich representations from 153.9M Model 4 to compact 109.5M Model 3:
$$\mathcal{L}_{\text{total}} = 0.5 \mathcal{L}_{\text{hard}} + 0.4 T^2 \text{KL}\left(\sigma\left(\frac{z_s}{T}\right) \parallel \sigma\left(\frac{z_t}{T}\right)\right) + 0.1 \left(1 - \cos\left(W_{\text{proj}}(u_s), u_t\right)\right)$$
---
## πŸ‘¨β€πŸ’» Author & Attribution
- **Student:** Sarwesh Barnwal (Roll No: 250987)
- **Course:** CS-781: Deep Learning for Natural Language Processing
- **Institution:** Department of Computer Science and Engineering, Indian Institute of Technology Kanpur (IITK)
- **Course Supervisor:** Prof. Ashutosh Modi