This repository contains explainable AI pipelines and functions that provide insightful visualizations and explanations for models across various domains, including computer vision and financial applications.
The tools and algorithms offered in this repository aim to enhance transparency in AI models by identifying and explaining feature contributions, uncovering patterns, and providing a deeper understanding of model behavior.
You can run the vision-focused or banking-focused apps independently:
- Banking Application:
streamlit run xai_banking/app.py
- Vision Application:
streamlit run main_page.py
If you want to run a combined app for both vision and banking functionalities, use the multipage application:
bash streamlit run multi_app/main.py
The multipage app provides a single interface to select between Banking Pilot and Fmake Pilot, dynamically loading the respective application.
To ensure a smooth setup and execution of the repository, follow these steps:
-
Clone the Repository Clone this repository to your local machine:
git clone <repository-url> cd <repository-name>
-
Set Up Conda Environment Create a Conda environment with all necessary dependencies:
Create the environment:
bash conda create --name xai_env python=3.11 -y
Activate the environment:
bash conda activate xai_env
Install dependencies:
bash pip install -r requirements.txt
-
To build and run the Streamlit application using Docker, follow these steps:
Build the Docker Image:
bash docker build -t xai-app . -f streamlit.Dockerfile
Run the Docker Container:
bash docker run -d -p 8501:8501 --name xai-container --env-file .env xai-app
-
To build and run the FastAPI service using Docker, follow these steps:
Build the Docker Image:
bash docker build -t xai-api -f api.Dockerfile .
Build the Docker Image:
bash docker run -d -p 8000:8000 --name api-container --env-file .env xai-api
-
Creating the .env File
Both the Streamlit app and the FastAPI service rely on environment variables defined in a .env file. Below is an example of how to create the .env file:
# Paths for Banking Models and Data BANKING_MODEL_PATH=xai_banking/utils/random_forest_model.pkl BANKING_DATA_PATH=xai_banking/utils/synthetic_dataset.csv # Paths for Vision Models and Data VISION_MODEL_PATH=xaivision/model.onnx VISION_DATA_PATH=xaivision/data1.h5 # API Key for FastAPI API_KEYS=["Your preference API key"] # Token for Streamlit Authentication STREAMLIT_TOKEN="Your preference Streamlit token"
The general use tools that are currently offered in the repository are listed in the table below.
Tool | Description | Applicable Domain |
---|---|---|
Model Details | Visualize the model architecture with details about total parameters and number of operations. | Vision, Banking |
Sample Details | Display input with the estimated output of the model. | Vision, Banking |
Convolution Layers Activation | Display the values of the convolutional layers stacked together. | Vision |
Independent Components | Split the input into independent components to identify patterns. | Vision |
Preprocessed Data Overview | Visualize and inspect preprocessed data, such as encoded features or transformed datasets. | Banking |
Feature Contributions | Analyze the impact of specific features (e.g., categorical or numerical) on model predictions. | Banking |
The XAI algorithms currently offered in the repository are listed in the table below:
Tool | Description | Applicable Domain |
---|---|---|
Model Details | Visualize the model architecture with details about total parameters and number of operations. | Vision, Banking |
Sample Details | Display input with the estimated output of the model. | Vision, Banking |
Convolution Layers Activation | Display the values of the convolutional layers stacked together. | Vision |
Independent Components | Split the input into independent components to identify patterns. | Vision |
Preprocessed Data Overview | Visualize and inspect preprocessed data, such as encoded features or transformed datasets. | Banking |
Feature Contributions | Analyze the impact of specific features (e.g., categorical or numerical) on model predictions. | Banking |
The repository now includes additional features and tools tailored for financial and banking applications:
Tool | Description |
---|---|
Lime Explanation Viewer | Visualize feature contributions for individual predictions using LIME. |
SHAP Explanation Viewer | Display global and local feature contributions using SHAP visualizations. |
Top Features Viewer | Highlight the top contributing features for a given prediction. |
Data Preprocessing Tools | Preprocess and encode financial datasets for explainability tasks. |
Visualization | Description |
---|---|
Bar Chart (LIME) | Display the contribution of each feature for an individual prediction using LIME. |
SHAP Summary Plot | Visualize the global feature importance and contribution distributions. |
SHAP Waterfall Plot | Show the breakdown of individual feature contributions for a specific instance. |
SHAP Heatmap Plot | Highlight patterns and clusters of feature contributions across multiple data points. |
SHAP Beeswarm Plot | Combine feature importance and distribution across data points for global insights. |
This repository supports two primary domains:
- Vision Models:
- Explainability for image classification models.
- Focus on pixel-level contributions and visual feature activations.
- Tools: Vision SHAP, Integrated Gradients, DeepLift.
- Banking Models:
- Explainability for financial and tabular data models.
- Feature-level analysis for predictions, such as fraud detection and credit scoring.
- Tools: LIME, SHAP, Preprocessed Data Overview, Feature Contributions.
- Select the Application:
- For vision tasks, use tools like Vision SHAP and Integrated Gradients.
- For banking tasks, use tools like LIME and SHAP Explanation Viewers.
- Visualize and Interpret:
- Explore detailed visualizations, such as SHAP Summary and Waterfall plots for banking models, or pixel-level explanations for vision models.
- Extend the Framework:
Add custom explainability tools or algorithms for other domains as needed.