Skip to main content

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.

  1. Download the .ipynb file from this repository.
  2. Upload it to Google Colab.
  3. Runtime Setup:
    • Go to Runtime > Change runtime type.
    • Select T4 GPU as the hardware accelerator.
  4. 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:

  1. 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.

  2. Initialization: Instantiate the framework with your specific class labels:

    nle = NLEFramework(class_names={0: "Loan Denied", 1: "Loan Approved"})
    
  3. 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 provided UNIVERSAL_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)

Source distribution for nle-framework-pappppx 0.1.0
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)

Table of built distributions (wheels) for nle-framework-pappppx 0.1.0
File Interpreter ABI Platform Actions
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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page