Skip to main content

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.

  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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nle_framework_pappppx-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nle_framework_pappppx-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

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

Hashes for nle_framework_pappppx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67e8f86447b069f6a1f2a3755942dbbf795d25250b9fff974883f4c43556162e
MD5 a3375444c3a3f311e3f5fce5f7a4a4f9
BLAKE2b-256 91e7ebf52c0e943fa9543ba3fda92fd7cffa014840bbfd81dd8222c346c02ad5

See more details on using hashes here.

File details

Details for the file nle_framework_pappppx-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nle_framework_pappppx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08305eb8bb9b625e4d18207d5d80bd1bc102fdd0249ec9987e8f8fbf8d218b2a
MD5 f1ca3642f6ac1b3fc25b88f5e55054e8
BLAKE2b-256 042d52548bc9de10eaa3085adbdef86424a6a360b0b2992e83f3be3259e863ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page