Skip to content

Purnachander-Konda/FinSentinel

Repository files navigation

🛡️ FinSentinel — LLM Fine-Tuning & Explainable AI Dashboard

Python PyTorch HuggingFace PEFT Streamlit Docker License: MIT

Production-ready Explainable AI platform combining LoRA-fine-tuned DistilBERT for financial sentiment analysis with XGBoost credit risk prediction — featuring real-time SHAP & LIME explanations and Fairlearn bias auditing, all served through an interactive Streamlit dashboard.


🏗️ Architecture

┌──────────────────────────────────────────────────────────────────────┐
│                         FinSentinel Pipeline                        │
├──────────────┬───────────────┬──────────────────┬───────────────────┤
│  DATA LAYER  │ TRAINING LAYER│ EXPLAINABILITY   │  DASHBOARD LAYER  │
│              │               │     LAYER        │                   │
│ HuggingFace  │ DistilBERT +  │ SHAP Text &      │ Streamlit App     │
│ Datasets     │ LoRA/PEFT     │ TreeExplainer    │ (4 pages)         │
│              │               │                  │                   │
│ Synthetic    │ XGBoost       │ LIME Text &      │ ┌── Sentiment ──┐ │
│ Credit Data  │ Classifier    │ Tabular          │ ├── Credit Risk ┤ │
│ (sklearn)    │               │                  │ ├── Fairness ───┤ │
│              │               │ Fairlearn        │ └── Metrics ────┘ │
│              │               │ Bias Audit       │                   │
└──────────────┴───────────────┴──────────────────┴───────────────────┘
         │              │               │                    │
         ▼              ▼               ▼                    ▼
    data/*.csv    models/         outputs/*.png      localhost:8501
                  finsentinel-    outputs/*.json
                  lora/           outputs/*.html

✨ Features

  • LoRA Fine-Tuning — Parameter-efficient fine-tuning of DistilBERT using PEFT (r=8, alpha=16) for 3-class financial sentiment classification
  • SHAP Explainability — Token-level SHAP values for text predictions + TreeExplainer waterfall & beeswarm plots for credit risk
  • LIME Explainability — LIME text explanations for sentiment + tabular explanations for credit risk
  • Fairlearn Bias Auditing — Demographic parity & equalized odds evaluation across age groups
  • Interactive Dashboard — 4-page Streamlit app with real-time inference, SHAP/LIME visualizations, and fairness reporting
  • Docker Ready — Single-command deployment with Docker

📁 Project Structure

FinSentinel/
├── data/
│   └── prepare_data.py          # Download & generate datasets
├── training/
│   └── finetune.py              # LoRA/PEFT fine-tuning
├── explainability/
│   ├── shap_explainer.py        # SHAP explanations
│   └── lime_explainer.py        # LIME explanations
├── fairness/
│   └── fairness_eval.py         # Fairlearn bias audit
├── dashboard/
│   └── app.py                   # Streamlit multi-page dashboard
├── models/                      # Saved model weights (auto-downloaded)
├── outputs/                     # Generated plots & metrics
├── .streamlit/config.toml       # Streamlit theme config
├── packages.txt                 # System deps for Streamlit Cloud
├── requirements.txt
├── Dockerfile
├── .gitignore
└── README.md

🚀 Quickstart

1. Clone & Install

git clone https://github.com/Purnachander-Konda/FinSentinel.git
cd FinSentinel
pip install -r requirements.txt

2. Prepare Data

python data/prepare_data.py

Downloads financial_phrasebank from HuggingFace and generates a synthetic credit risk dataset (500 rows).

3. Fine-Tune the Model

python training/finetune.py

Fine-tunes DistilBERT with LoRA on financial sentiment data (3 epochs). Saves model to models/finsentinel-lora/.

4. Generate Explanations

python explainability/shap_explainer.py
python explainability/lime_explainer.py
python fairness/fairness_eval.py

5. Launch Dashboard

streamlit run dashboard/app.py

Open http://localhost:8501 in your browser.


🐳 Docker

docker build -t finsentinel .
docker run -p 8501:8501 finsentinel

Note: Run data preparation and training steps before building the Docker image (or mount volumes for models/outputs).


📸 Screenshots

Sentiment Analyzer Credit Risk Predictor
Sentiment Credit
Fairness Report Training Metrics
Fairness Training

📊 Results

Metric Value
Sentiment Accuracy 93.82%
Sentiment F1 (weighted) 93.85%
Sentiment Precision 93.97%
Sentiment Recall 93.82%
Demographic Parity Diff 0.4701
Equalized Odds Diff 0.3333
Trainable Parameters ~1.09% (LoRA)

🛠️ Tech Stack

Component Technology
Base Model DistilBERT (HuggingFace)
Fine-Tuning PEFT / LoRA
Credit Risk Model XGBoost
Explainability SHAP, LIME
Fairness Fairlearn
Dashboard Streamlit
Data HuggingFace Datasets, scikit-learn
Containerization Docker
Deployment Streamlit Cloud
Language Python 3.14

👤 Author

Poorna Chander Konda


📄 License

This project is licensed under the MIT License. See LICENSE for details.

About

LLM Fine-Tuning & Explainable AI Dashboard for Financial Sentiment and Credit Risk — LoRA/PEFT, SHAP, LIME, Fairlearn, Streamlit

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors