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.
Metadata
Release files for nle-framework-pappppx 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nle_framework_pappppx-0.1.0.tar.gz | 7.7 kB | Without provenance | Details for nle_framework_pappppx-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nle_framework_pappppx-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for nle_framework_pappppx-0.1.0-py3-none-any.whl |
Total release size: 15.8 kB
Release files / nle_framework_pappppx-0.1.0.tar.gz
| Download URL | nle_framework_pappppx-0.1.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67e8f86447b069f6a1f2a3755942dbbf795d25250b9fff974883f4c43556162e
|
|
BLAKE2b-256 checksum How to use checksums |
91e7ebf52c0e943fa9543ba3fda92fd7cffa014840bbfd81dd8222c346c02ad5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / nle_framework_pappppx-0.1.0-py3-none-any.whl
| Download URL | nle_framework_pappppx-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08305eb8bb9b625e4d18207d5d80bd1bc102fdd0249ec9987e8f8fbf8d218b2a
|
|
BLAKE2b-256 checksum How to use checksums |
042d52548bc9de10eaa3085adbdef86424a6a360b0b2992e83f3be3259e863ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for nle-framework-pappppx 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.