Text Generation
PEFT
Safetensors
PyTorch
English
legal
indian-legal
custom-decoder
lorma
lora
qlora
adalora
knowledge-distillation
cs781
iit-kanpur
Instructions to use sarweshbarnwal/CS781-Legal-Models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sarweshbarnwal/CS781-Legal-Models with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Add comprehensive Model Card and Phase documentation README
Browse files
README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: other
|
| 5 |
+
tags:
|
| 6 |
+
- legal
|
| 7 |
+
- indian-legal
|
| 8 |
+
- custom-decoder
|
| 9 |
+
- peft
|
| 10 |
+
- lorma
|
| 11 |
+
- lora
|
| 12 |
+
- qlora
|
| 13 |
+
- adalora
|
| 14 |
+
- knowledge-distillation
|
| 15 |
+
- pytorch
|
| 16 |
+
- cs781
|
| 17 |
+
- iit-kanpur
|
| 18 |
+
pipeline_tag: text-generation
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# CS-781 Legal Language Models (IIT Kanpur)
|
| 22 |
+
|
| 23 |
+
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**.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## ποΈ Project & Research Overview
|
| 28 |
+
|
| 29 |
+
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.
|
| 30 |
+
|
| 31 |
+
In strict compliance with competition constraints:
|
| 32 |
+
- **Zero Pretrained Weights:** No commercial LLMs (GPT-4, Claude, Gemini) or off-the-shelf open-source checkpoints (BERT, LLaMA-3, Mistral) were utilized.
|
| 33 |
+
- **Scratch Foundation Pretraining:** Four decoder-only transformer architectures were pre-trained strictly from scratch on Indian Supreme Court and High Court judgments.
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## π§ Phase 1 Foundation Models (Trained from Scratch)
|
| 38 |
+
|
| 39 |
+
| Model Subfolder | Architecture Style | Layers | $d_{\text{model}}$ | Attention Heads (Q / KV) | Max Context | Parameters | Core Structural Innovation |
|
| 40 |
+
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
| 41 |
+
| **`model1-deep-llama-135m/`** | Deep LLaMA Causal Decoder | 16 | 768 | 12 / 4 (GQA 3:1) | 1024 | 134.7M | Deep representational capacity, RMSNorm, SwiGLU FFN |
|
| 42 |
+
| **`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 |
|
| 43 |
+
| **`model3-statutory-mha-110m/`** | Statutory Precision Decoder | 12 | 768 | 12 / 12 (Full MHA) | 1024 | 109.5M | Full unshared multi-head attention for fine syntax |
|
| 44 |
+
| **`model4-capacity-boundary-154m/`** | Peak Capacity Boundary | 14 | 896 | 14 / 14 (Full MHA) | 1024 | 153.9M | Tied embeddings, peak capacity boundary model |
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## π Repository Checkpoint Architecture
|
| 49 |
+
|
| 50 |
+
Checkpoints and CodaBench evaluation files are continuously synchronized from Kaggle Dual-T4 training sessions into dedicated phase namespaces:
|
| 51 |
+
|
| 52 |
+
```text
|
| 53 |
+
sarweshbarnwal/CS781-Legal-Models/
|
| 54 |
+
βββ model1-deep-llama-135m/ # Phase 1 scratch-trained backbone
|
| 55 |
+
βββ model2-wide-mistral-136m/ # Phase 1 scratch-trained backbone
|
| 56 |
+
βββ model3-statutory-mha-110m/ # Phase 1 scratch-trained backbone
|
| 57 |
+
βββ model4-capacity-boundary-154m/ # Phase 1 scratch-trained backbone
|
| 58 |
+
β
|
| 59 |
+
βββ Phase_7/ # Prior Case Retrieval (PCR)
|
| 60 |
+
β βββ sub01_model4_full_ft_hierarchical/
|
| 61 |
+
β βββ sub02_model1_true_lorma_hard_negs/ # COMPULSORY LoRMA
|
| 62 |
+
β βββ sub03_model2_qlora_ratio/
|
| 63 |
+
β βββ sub04_model1_adalora_margin_mse/
|
| 64 |
+
β βββ sub05_model2_houlsby_cosent/
|
| 65 |
+
β βββ sub06_model3_distill_alignment/ # MANDATORY KD
|
| 66 |
+
β βββ sub07_model4_bm25_dense_hybrid/
|
| 67 |
+
β βββ sub08_master_ensemble/
|
| 68 |
+
β
|
| 69 |
+
βββ Phase_6/ # Abstractive Summarization
|
| 70 |
+
β βββ sub01_model4_full_ft/
|
| 71 |
+
β βββ sub02_model1_true_lorma/ # COMPULSORY LoRMA
|
| 72 |
+
β βββ sub03_model2_qlora/
|
| 73 |
+
β βββ sub04_model1_adalora/
|
| 74 |
+
β βββ sub05_model2_houlsby/
|
| 75 |
+
β βββ sub06_model4_to_model3_distill/ # MANDATORY KD
|
| 76 |
+
β βββ sub07_model4_hierarchical_summary/
|
| 77 |
+
β βββ sub08_master_ensemble/
|
| 78 |
+
β
|
| 79 |
+
βββ Phase_5/ # Legal Statute Identification (LSI)
|
| 80 |
+
β βββ sub01_model4_full_ft_asl/
|
| 81 |
+
β βββ sub02_model1_true_lorma/ # COMPULSORY LoRMA
|
| 82 |
+
β βββ sub03_model2_qlora/
|
| 83 |
+
β βββ sub04_model1_adalora/
|
| 84 |
+
β βββ sub05_model2_houlsby/
|
| 85 |
+
β βββ sub06_model4_to_model3_distill/ # MANDATORY KD
|
| 86 |
+
β βββ sub07_model4_hierarchical_pool/
|
| 87 |
+
β βββ sub08_master_ensemble/
|
| 88 |
+
β
|
| 89 |
+
βββ Phase_4/ # Court Judgment Prediction (CJPE)
|
| 90 |
+
β βββ sub01_model4_full_ft/
|
| 91 |
+
β βββ sub02_model1_true_lorma/ # COMPULSORY LoRMA
|
| 92 |
+
β βββ sub03_model2_qlora/
|
| 93 |
+
β βββ sub04_model1_adalora/
|
| 94 |
+
β βββ sub05_model2_houlsby/
|
| 95 |
+
β βββ sub06_model4_to_model3_distill/ # MANDATORY KD
|
| 96 |
+
β βββ sub07_model4_hierarchical_pool/
|
| 97 |
+
β βββ sub08_master_ensemble/
|
| 98 |
+
β
|
| 99 |
+
βββ Phase_3/ # Rhetorical Role Prediction (RR)
|
| 100 |
+
βββ Phase_2/ # Legal Named Entity Recognition (L-NER)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## π¬ Methodological Innovations
|
| 106 |
+
|
| 107 |
+
### 1. Compulsory Method: True Multiplicative LoRMA
|
| 108 |
+
Implemented according to Bihany, Patel, and Modi (2025):
|
| 109 |
+
$$y_{\text{adapted}} = y + \frac{\alpha}{r} B( A(y) )$$
|
| 110 |
+
- Zero-initialized $B$ strictly guarantees identity mapping at step 0.
|
| 111 |
+
- All base model weights are frozen; trainable parameters $< 1.5\%$.
|
| 112 |
+
|
| 113 |
+
### 2. Mandatory Method: Cross-Model Knowledge Distillation
|
| 114 |
+
Transfers rich representations from 153.9M Model 4 to compact 109.5M Model 3:
|
| 115 |
+
$$\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)$$
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## π¨βπ» Author & Attribution
|
| 120 |
+
|
| 121 |
+
- **Student:** Sarwesh Barnwal (Roll No: 250987)
|
| 122 |
+
- **Course:** CS-781: Deep Learning for Natural Language Processing
|
| 123 |
+
- **Institution:** Department of Computer Science and Engineering, Indian Institute of Technology Kanpur (IITK)
|
| 124 |
+
- **Course Supervisor:** Prof. Ashutosh Modi
|