⚖️ JustiFi
InLegalBERT Legal Outcome Predictor
AI-Powered Legal Intelligence for Indian Legal Documents
A fine-tuned transformer model for legal outcome classification, built using InLegalBERT and designed to support long legal documents through chunk-based inference.
📌 Overview
JustiFi is an AI-powered legal intelligence project that uses a fine-tuned InLegalBERT model to classify Indian legal documents into two outcome categories: ACCEPT and REJECT.
Legal documents often contain lengthy arguments, complex terminology, and contextual relationships. Standard BERT models also have a limited input length of 512 tokens per sequence.
JustiFi addresses this input limitation through chunk-based processing, in which long documents are divided into smaller segments, processed individually, and combined to produce a document-level prediction.
🎯 Key Features
- ⚖️ Legal Outcome Prediction: Classifies legal documents into ACCEPT or REJECT.
- 🧠 Domain-Specific Transformer: Fine-tuned InLegalBERT for Indian legal text.
- 📄 Long-Document Processing: Supports chunk-based inference for lengthy documents.
- 📊 Confidence Scoring: Returns model prediction scores.
- 🚀 API Integration: Designed for deployment through FastAPI.
- 📈 Model Evaluation: Includes classification metrics and evaluation visualizations.
📊 Model Performance
The reported evaluation results for the chunk-based document prediction system are:
| Evaluation Metric | Score |
|---|---|
| 🎯 Accuracy | 70% |
| Precision | 71% |
| Recall | 71% |
| F1 Score | 71% |
These are the reported project results and are not a guarantee of performance on unseen legal cases.
Evaluation Methods
The project includes the following evaluation analyses:
- Accuracy versus epoch
- Precision-recall curve
- Confusion matrix
- Prediction confidence distribution
- Response-time analysis
For reproducibility, the evaluation should specify the test-set size, dataset split, class distribution, and whether the metrics were calculated at the chunk or complete-document level.
🏗️ System Architecture
The model processes legal documents through extraction, preprocessing, tokenization, chunk generation, transformer classification, and document-level aggregation.
flowchart TD
A["Legal Document"] --> B["PDF / Text Extraction"]
B --> C["Text Preprocessing"]
C --> D["Tokenizer"]
D --> E["Chunk Generation"]
E --> F["InLegalBERT Classifier"]
F --> G["Chunk-Level Predictions"]
G --> H["Document-Level Aggregation"]
H --> I["Final Prediction"]
H --> J["Confidence Score"]
I --> K["REJECT (0)"]
I --> L["ACCEPT (1)"]
classDef input fill:#e8f1ff,stroke:#3b82f6,color:#172554
classDef process fill:#f1f5f9,stroke:#64748b,color:#0f172a
classDef model fill:#ede9fe,stroke:#7c3aed,color:#2e1065
classDef output fill:#dcfce7,stroke:#16a34a,color:#14532d
class A input
class B,C,D,E,G,H process
class F model
class I,J,K,L output
🔄 Processing Pipeline
- Document Input: Receives legal document text or PDF input.
- Text Extraction: Extracts readable content from PDF documents.
- Preprocessing: Prepares the extracted text for model inference.
- Tokenization: Converts text into tokens understood by InLegalBERT.
- Chunk Generation: Splits long documents into sequences within the model's input limit.
- Chunk Classification: Predicts a label for each text chunk.
- Document Aggregation: Combines chunk-level outputs into a final document-level prediction.
- Output Generation: Returns the predicted label, confidence score, and number of processed chunks.
The final prediction depends on the aggregation method implemented in the inference pipeline.
🧠 Model Details
| Property | Description |
|---|---|
| Model Name | JustiFi InLegalBERT Outcome Predictor |
| Base Model | law-ai/InLegalBERT |
| Architecture | BERT Sequence Classification |
| Task | Binary Text Classification |
| Classes | REJECT / ACCEPT |
| Maximum Input Length | 512 tokens per sequence |
| Inference Method | Chunk-Based Processing |
| Framework | PyTorch |
| Model Library | Hugging Face Transformers |
| Backend | FastAPI |
| Domain | Indian Legal NLP |
🏷️ Classification Labels
| Class ID | Label |
|---|---|
0 |
REJECT |
1 |
ACCEPT |
id2label = {
0: "REJECT",
1: "ACCEPT"
}
label2id = {
"REJECT": 0,
"ACCEPT": 1
}
🚀 Quick Start
1. Install Dependencies
pip install transformers torch
2. Load the Model
from transformers import pipeline
MODEL_ID = "vikas-maurya/justifi-inlegalbert-outcome-predictor"
classifier = pipeline(
task="text-classification",
model=MODEL_ID,
tokenizer=MODEL_ID
)
text = """
Insert the legal document text here.
"""
result = classifier(
text,
truncation=True
)
print(result)
3. Example Output
[
{
"label": "ACCEPT",
"score": 0.74
}
]
The output is illustrative and does not represent a live prediction.
Note: This example is intended for short text. Setting truncation=True does not implement long-document chunking or aggregation. For lengthy legal documents, use the project's complete inference pipeline.
📄 Long-Document Processing
Standard BERT models have a maximum input sequence length of 512 tokens. JustiFi uses chunk-based inference to process lengthy documents.
Legal Document
|
v
PDF / Text Extraction
|
v
Text Preprocessing
|
v
Tokenization
|
v
Chunk Generation
|
v
InLegalBERT Classification
|
v
Chunk-Level Predictions
|
v
Document-Level Aggregation
|
v
Final Prediction and Confidence
The inference implementation should specify whether chunks overlap and whether predictions are aggregated using majority voting, averaged probabilities, weighted aggregation, or another method.
🔌 API Response Format
The model is designed for integration with a FastAPI backend.
Example response:
{
"prediction": "ACCEPT",
"confidence": 0.64,
"num_chunks": 7
}
The values are illustrative and demonstrate the expected response structure.
The confidence score represents the model's output score. Unless calibration has been evaluated, it should not automatically be interpreted as the probability that the prediction is correct.
⚙️ Training Configuration
The reported training configuration is shown below.
| Parameter | Value |
|---|---|
| Learning Rate | 2e-5 |
| Batch Size | 4 |
| Gradient Accumulation Steps | 4 |
| Optimizer | AdamW |
| Loss Function | Cross Entropy |
| Mixed Precision | FP16 |
| Training Steps | Approximately 4,500 |
These values reflect the reported configuration. The effective batch size depends on the number of devices and the training setup.
🛠️ Technology Stack
| Component | Technology |
|---|---|
| Programming Language | Python |
| Base Model | InLegalBERT |
| Transformer Library | Hugging Face Transformers |
| Deep Learning Framework | PyTorch |
| NLP Task | Legal Text Classification |
| Backend | FastAPI |
| Document Processing | PDF and Text Extraction |
| Deployment | API-Based Inference |
⚠️ Limitations and Responsible Use
- Jurisdictional scope: The model is designed for Indian legal documents. Its performance in other jurisdictions has not been established.
- Dataset dependency: Performance depends on the training data, label definitions, and dataset representativeness.
- Long-document processing: Chunk boundaries and aggregation strategies can affect final predictions.
- Class-specific performance: Aggregate metrics may hide differences in performance between ACCEPT and REJECT.
- Confidence calibration: Prediction scores are not necessarily calibrated probabilities.
- Legal reasoning: A predicted label does not establish the reasoning behind a judicial decision or guarantee the actual legal outcome.
Intended Use
JustiFi is intended for research, experimentation, and prototyping legal NLP workflows. It should not be used as the sole basis for legal decisions or as a substitute for qualified legal advice.
👨💻 Author
Vikas Maurya
- 💼 LinkedIn Profile: Connect with me
- 🚀 Major Project Showcase: View my JustiFi project on LinkedIn
- 🤗 Hugging Face Profile: vikas-maurya
- 🧠 Published Model: JustiFi InLegalBERT Outcome Predictor
Project: JustiFi — AI-Powered Legal Intelligence System
Focus areas include Legal AI, Natural Language Processing, Deep Learning, Transformer Models, and Generative AI.
📚 Citation
If you use this model in academic or research work, you may cite it as follows:
@misc{justifi_inlegalbert,
title = {JustiFi: InLegalBERT Legal Outcome Predictor},
author = {Vikas Maurya},
year = {2026},
url = {https://huggingface.co/vikas-maurya/justifi-inlegalbert-outcome-predictor}
}
📜 License
This repository declares the Apache-2.0 license in its model card metadata. Ensure that your use and redistribution also comply with the applicable terms of the base model and training data.
JustiFi — Transformer-Based Legal Intelligence for Indian Legal Documents
Developed by Vikas Maurya