A Model-Agnostic Framework for Natural Language Explanations of Predictive Models
Project description
A Model-Agnostic Framework for Natural Language Explanations of Predictive Models
This repository contains the source code for the Master's Thesis: "A Model-Agnostic Framework for Natural Language Explanations of Predictive Models".
The framework introduces a robust, Object-Oriented architecture that integrates Feature Importance Methods (SHAP, LIME) and Logic-based Approaches (Araucana-XAI) with Large Language Models (Llama-3 via Unsloth). The system generates coherent, truthful, and role-adapted clinical reports, specifically designed to mitigate LLM hallucinations through structural logic injection.
📂 Repository Contents
A_Model_Agnostic_Framework_for_NLE_of_Predictive_Models.ipynb: The complete, self-contained Jupyter Notebook implementing the OOP framework and experimental pipeline.
🚀 Quick Start (Google Colab)
The easiest way to replicate the experiments is utilizing Google Colab's free GPU tier.
- Download the
.ipynbfile from this repository. - Upload it to Google Colab.
- Runtime Setup:
- Go to
Runtime>Change runtime type. - Select T4 GPU as the hardware accelerator.
- Go to
- Execution:
- Run the installation cells to set up the environment.
- The framework automatically handles the download and caching of the Llama-3 model.
🛠️ System Architecture & Requirements
The project is built on Python 3.10 and utilizes a Singleton Pattern to manage GPU memory efficiently.
- Core Class:
NLEFramework(Orchestrates XAI extraction and Prompt Generation). - Hardware: NVIDIA Tesla T4 (Required for 4-bit quantization).
- Key Libraries:
unsloth(Efficient LLM Inference)araucanaxai(Symbolic Decision Tree Surrogates)shap&lime(Feature Attribution)scikit-learn(Black-box modeling)
🔄 Extensibility & Domain Adaptation
This framework is designed with modularity in mind, using an Adapter Pattern to switch between different domains (e.g., Oncology, Finance, Law) without modifying the core codebase.
How to Adapt to a New Domain:
-
Data Layer: Replace the data loading function in Block 2 with your custom tabular dataset. Retrain the
black_box_model(e.g., Random Forest) on your new data. -
Initialization: Instantiate the framework with your specific class labels:
nle = NLEFramework(class_names={0: "Loan Denied", 1: "Loan Approved"})
-
Adapter Layer (Prompt Engineering): Do not edit the source code. Instead, register a new Adapter using the
register_adapter()method. Define a new System Role and use the providedUNIVERSAL_USER_TEMPLATE.# Example: Defining a Financial Analyst Persona finance_system = """ SYSTEM ROLE: You are a Senior Financial Analyst. OBJECTIVE: Explain the credit score decision based on debt-to-income ratio. ... """ # Registering the new capability nle.register_adapter("finance_expert", finance_system, UNIVERSAL_USER_TEMPLATE)
🔬 Experimental Reproducibility
The notebook includes a comparative experiment block comparing:
- Baseline Approach: Explanations based solely on SHAP/LIME weights.
- Hybrid Approach (Proposed): Explanations grounded in Araucana's symbolic logic trees.
Run Block 5 in the notebook to generate the side-by-side comparison reports for specific test instances.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nle_framework_pappppx-0.1.0.tar.gz.
File metadata
- Download URL: nle_framework_pappppx-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e8f86447b069f6a1f2a3755942dbbf795d25250b9fff974883f4c43556162e
|
|
| MD5 |
a3375444c3a3f311e3f5fce5f7a4a4f9
|
|
| BLAKE2b-256 |
91e7ebf52c0e943fa9543ba3fda92fd7cffa014840bbfd81dd8222c346c02ad5
|
File details
Details for the file nle_framework_pappppx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nle_framework_pappppx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08305eb8bb9b625e4d18207d5d80bd1bc102fdd0249ec9987e8f8fbf8d218b2a
|
|
| MD5 |
f1ca3642f6ac1b3fc25b88f5e55054e8
|
|
| BLAKE2b-256 |
042d52548bc9de10eaa3085adbdef86424a6a360b0b2992e83f3be3259e863ae
|