--- 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