# shivamlth27/predicting-judgment-decisions-using-llm architecture

> Architecture diagram of the GitHub repository shivamlth27/predicting-judgment-decisions-using-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shivamlth27/predicting-judgment-decisions-using-llm
- Repository: https://github.com/shivamlth27/predicting-judgment-decisions-using-llm

## Overview

##### Main Project Components
- Data Preparation & Input:
- Notebooks and scripts like data_prep.ipynb and train.ipynb handle dataset preparation.
- The PredEx dataset (Indian legal judgments) is an external input placed in a designated data directory.
- Model Training & Fine-Tuning:
- Dedicated scripts include roberta.py, roberta_train.py, instruction_fine_tuning.py, and rag_fine_tuning.py.
- Models include fine-tuned versions of RoBERTa, Legal-BERT, and a pre-trained LLama (pretrained_llama.py).
- Hierarchical data processing (e.g., aggregating paragraph-level embeddings) is used to manage very long legal texts.
- Vector Storage & Retrieval:
- The "legal_vectorstore" directory (with files like index.faiss and index.pkl) suggests use of a vector store to speed up similarity search and retrieval.
- Inference & Explainability:
- The inference.py script is responsible for running model predictions.
- Attention-based explainability methods provide interpretable rationales for judicial predictions.
- Web Application & User Interface:
- app.py acts as the backend API or web server.
- The templates directory (with about.html, index.html, model.html) provides the HTML pages for interfacing with end users.
- Supporting Documents & Assets:
- The images directory stores visual assets, while the report.pdf contains detailed project documentation.

##### Relationships and Data Flow
- Role of the Vector Store:
- That once models are trained, the resulting embeddings or indexes (stored in the vector store) facilitate rapid similarity searches during inference.
- Inference Process:
- That the vector store is used in the inference process.
- Web Application:
- Link the Inference component and the Web Application (app.py).
- Connections to the front-end templates where users view results, explanation visualizations (attention heatmaps), or interact further with the system.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Distinguish between the data preparation/training layer and the inference/serving layer.
- Modularity:
- Clearly separated scripts/notebooks for different tasks (training, inference, web serving), allowing independent development and potential microservices if needed.
- Integration of AI Explainability:
- That the system integrates attention-based mechanisms for legal decision explainability.

##### Relevant Technologies & Frameworks
- NLP & Deep Learning Libraries:
- RoBERTa, Legal-BERT, and LLama-based models.
- Vector Search Tools:
- FAISS is likely used for vector similarity indexing (referenced by index.faiss).
- Web Framework:
- The presence of app.py and HTML templates suggests use of a framework like Flask.
- Notebook-based Experimentation:
- Data preparation and training are supported through Jupyter notebooks (data_prep.ipynb and train.ipynb).

##### Elements
- Each Component Should be Clearly Labeled:
- “Data Preparation”, “Model Training”, “Vector Store”, “Inference”, “Web API/Backend”, and “User Interface/Frontend”.

##### Putting It All Together
- Next, branch to the Model Training layer, illustrating fine-tuning with RoBERTa and Legal-BERT, and noting the pre-trained LLama.
- From the Vector Store, indicate its use in the Inference module.
- Finally, connect the Inference module to the Web Application (app.py) and illustrate how the web templates render the outputs to end users.
- Optionally, add a feedback loop for user input or expert evaluations that might help in refining models.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    DS["PredEx Dataset"]:::external

    %% Data Preparation Layer
    subgraph "Data Preparation Layer"
        DP["Data Preparation & Input"]:::data
        DPN1["data_prep.ipynb"]:::data_file
        DPN2["train.ipynb"]:::data_file
    end

    %% Model Training Layer
    subgraph "Model Training Layer"
        MT["Model Training & Fine-Tuning"]:::training
        R1["roberta.py"]:::training_file
        R2["roberta_train.py"]:::training_file
        R3["instruction_fine_tuning.py"]:::training_file
        R4["rag_fine_tuning.py"]:::training_file
        R5["pretrained_llama.py"]:::training_file
    end

    %% Vector Store Layer
    subgraph "Vector Store Layer"
        VS["Vector Storage & Retrieval"]:::vector
        VSD["legal_vectorstore"]:::vector_dir
    end

    %% Inference Layer
    subgraph "Inference Layer"
        INF["Inference & Explainability"]:::inference
        INF_F["inference.py"]:::inference_file
    end

    %% Web Layer
    subgraph "Web Layer"
        WEB["Web Application & Backend"]:::web
        APP["app.py"]:::web_file
        UI["User Interface/Frontend"]:::frontend
        TMPL["templates"]:::template_dir
    end

    %% Documentation & Assets
    subgraph "Supporting Documents & Assets"
        DOCS["Documentation & Assets"]:::docs
        IMG["images"]:::docs_dir
        REP["report.pdf"]:::docs_file
    end

    %% Data Flow Connections
    DS -->|"ingests"| DP
    DPN1 --> DP
    DPN2 --> DP

    DP -->|"processed data"| MT
    R1 --> MT
    R2 --> MT
    R3 --> MT
    R4 --> MT
    R5 --> MT

    MT -->|"embeddings"| VS
    VSD --> VS

    VS -->|"retrieval"| INF
    MT -->|"model output"| INF
    INF_F --> INF

    INF -->|"predictions"| WEB
    APP -->|"renders"| UI
    TMPL --> UI

    %% Click Events
    click DPN1 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/data_prep.ipynb"
    click DPN2 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/train.ipynb"
    click R1 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/roberta.py"
    click R2 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/roberta_train.py"
    click R3 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/instruction_fine_tuning.py"
    click R4 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/rag_fine_tuning.py"
    click R5 "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/pretrained_llama.py"
    click VSD "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/tree/main/legal_vectorstore"
    click INF_F "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/inference.py"
    click APP "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/app.py"
    click TMPL "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/tree/main/templates"
    click IMG "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/tree/main/images"
    click REP "https://github.com/shivamlth27/predicting-judgment-decisions-using-llm/blob/main/report.pdf"

    %% Styles
    classDef external fill:#D5DBDB,stroke:#000,stroke-width:1px;
    classDef data fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef data_file fill:#D6EAF8,stroke:#000,stroke-width:1px;
    classDef training fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef training_file fill:#FCF3CF,stroke:#000,stroke-width:1px;
    classDef vector fill:#A3E4D7,stroke:#000,stroke-width:2px;
    classDef vector_dir fill:#D1F2EB,stroke:#000,stroke-width:1px;
    classDef inference fill:#F5CBA7,stroke:#000,stroke-width:2px;
    classDef inference_file fill:#FDEBD0,stroke:#000,stroke-width:1px;
    classDef web fill:#D7BDE2,stroke:#000,stroke-width:2px;
    classDef web_file fill:#E8DAEF,stroke:#000,stroke-width:1px;
    classDef frontend fill:#E8DAEF,stroke:#000,stroke-width:1px;
    classDef template_dir fill:#FADBD8,stroke:#000,stroke-width:1px;
    classDef docs fill:#FADBD8,stroke:#000,stroke-width:2px;
    classDef docs_dir fill:#FDEDEC,stroke:#000,stroke-width:1px;
    classDef docs_file fill:#FDEDEC,stroke:#000,stroke-width:1px;
```
