This project implements a lightweight Retrieval-Augmented Generation (RAG) chatbot designed to answer questions related to a Loan Approval Prediction Dataset. It combines vector-based semantic search with generative language modeling using a TinyLlama model for fast, contextual, and informative responses.
The chatbot enables users to ask natural language questions about a tabular dataset, returning informed answers based on both statistics and sample data. It uses:
SentenceTransformersfor embedding dataset chunks.FAISSfor vector similarity search.TinyLlama-1.1B-Chatfor generating responses.Gradiofor building a user-friendly chat interface.
The notebook expects a CSV file named Training Dataset.csv, representing a typical loan application dataset with features like:
- Income
- Credit History
- Employment Status
- And others...
Each column is described statistically using pandas.describe() and enriched with a few sample rows.
| Component | Description |
|---|---|
pandas |
Data loading and processing |
sentence-transformers |
Converts text chunks to embeddings |
faiss-cpu |
Efficient similarity search over embeddings |
transformers |
Loads the TinyLlama text generation model |
gradio |
Provides a web-based chat UI |
- Data Chunking: Each column's stats and a few sample rows are turned into textual "chunks" to form a knowledge base.
- Vector Indexing: These chunks are embedded and stored using
FAISSfor nearest-neighbor search. - Query Retrieval: At runtime, the chatbot retrieves top-K relevant chunks based on semantic similarity to the query.
- Contextual Answering: These chunks, along with chat history, are fed into a TinyLlama-based text generation pipeline to produce an answer.
The prompt to the model includes:
- Last 3 turns of conversation (user + bot)
- Top-K retrieved dataset chunks
- A task-specific instruction:
You are an assistant for questions about a loan approval dataset.
Previous conversation:
User: ...
Bot: ...
User: <query>
Based on the context below, answer the user’s question.
Context:
<retrieved chunks>
Answer:
To run the chatbot interface locally with sharing enabled:
!pip install pandas sentence-transformers transformers faiss-cpu gradioThen execute the notebook and follow the Gradio link:
gr.ChatInterface(...).launch(share=True)rag_answer("What features are most important for loan approval?", "")This will produce a model-generated response grounded in dataset features like income, credit history, etc.
- Ensure the dataset file is named correctly (
Training Dataset.csv). - TinyLlama is used for fast inference; this can be swapped with a larger model if needed.
- No external APIs or cloud resources are required—everything runs locally.