This repository demonstrates a comprehensive approach to building an intelligent loan approval system, progressing from model interpretability to an interactive RAG-based assistant.
The first part focuses on understanding and explaining AI model predictions in the loan approval context using state-of-the-art interpretability techniques.
- LIME (Local Interpretable Model-agnostic Explanations) for individual predictions
- SHAP (SHapley Additive exPlanations) for feature importance analysis
- Comparison with inherently interpretable models like decision trees
- Comprehensive visualizations
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start Jupyter Notebook
jupyter notebookNavigate to model_interpretability/model_explanations.ipynb to explore the demonstrations.
Building upon our understanding of model interpretability, we've developed an interactive loan approval assistant using Retrieval Augmented Generation (RAG) technology.
- Interactive Streamlit web interface
- RAG-based decision explanation using domain-specific knowledge
- Real-time loan approval decisions
- Detailed criteria analysis and explanations
- Integration with Microsoft's Phi-2 language model
# Ensure you're in the virtual environment
cd loan_approval_rag
pip install -r requirements.txt
# Run the Streamlit app
streamlit run loan_approval_rag/src/app.py --server.fileWatcherType noneThe architecture of the RAG-based Intelligent Loan Approval Assistant is as follows:
+----------------------+ +------------------+ +----------------------+
| User Interface | | RAG Pipeline | | Domain Knowledge |
| (Streamlit) |<--->| Coordinator | | Loan Documents |
+----------------------+ +------------------+ +----------------------+
| |
v v
+------------------+ +----------------------+
| Retriever |<----| Document Indexing & |
| FAISS + Sentence | | Embedding Process |
| Transformers | +----------------------+
+------------------+
|
v
+------------------+
| Generator |
| (Phi-2 LLM) |
+------------------+
|
v
+------------------+
| Final Answer |
| Loan Decision & |
| Explanation |
+------------------+
flowchart TD
style UI fill:#e3f6fc,stroke:#38b6ff,stroke-width:2px
style FILES fill:#f9f9f9,stroke:#bdbdbd,stroke-width:2px
style LLM fill:#fffbe7,stroke:#f9d923,stroke-width:3px
style DOCS fill:#f0e6fa,stroke:#a259d9,stroke-width:2px
UI([👤<br/>User<br/>Interface])
FILES([🗂️<br/>User<br/>Files])
DOCS([📄<br/>Domain<br/>Knowledge])
LLM([🧠<br/>AI Model])
%% Step flows
UI -- "1️⃣ Provide Files" --> FILES
FILES -- "2️⃣ Indexed & Embedded" --> DOCS
UI -- "3️⃣ Application & Questions" --> LLM
DOCS -- "4️⃣ Relevant Info" --> LLM
LLM -- "5️⃣ Decision & Explanation" --> UI
The diagram shows the key components and data flow of our RAG-based loan approval system:
- Domain Knowledge: Loan documents are indexed and embedded
- Retrieval: FAISS retrieves relevant context based on user queries
- Generation: Phi-2 LLM generates responses using retrieved context
- Pipeline: Coordinates the flow between components
- User Interface: Streamlit web app for user interaction
This repository showcases the evolution of AI in loan approval systems:
-
Understanding the Black Box: We start with model interpretability, making AI decisions transparent and trustworthy through LIME and SHAP analysis.
-
Enhancing with Intelligence: We then progress to a RAG-based system that not only makes decisions but also provides context-aware explanations by leveraging domain knowledge and large language models.
- LIME & SHAP for model explanations
- Scikit-learn for traditional ML models
- Matplotlib & Seaborn for visualizations
- LangChain for RAG pipeline
- Microsoft Phi-2 for language modeling
- Streamlit for web interface
- FAISS for vector storage
- Sentence Transformers for embeddings
If you use or reference this project as part of academic work or publications, please cite the following chapter from the book project:
@incollection{Lu2026Computer,
author = {Tianxiang Lu},
title = {Den Computer verstehen: Von Erklärbarkeit zu automatisiertem Reasoning},
booktitle = {Technologie und Organisation},
editor = {Cornelia Reindl and Bernhard Wecke and Ulrich Irnich},
publisher = {Springer Gabler, Wiesbaden},
year = {2026},
pages = {17--32},
doi = {10.1007/978-3-658-51511-9_2},
url = {https://doi.org/10.1007/978-3-658-51511-9_2}
}This repository is part of a book project demonstrating the practical evolution of AI systems, from explainable models to intelligent assistants. Each component is designed to showcase best practices in both technical implementation and user experience.

