Neerajkadari/Context-Aware_Conversational_Intelligence_System
0
Context-Aware Conversational Intelligence using Transformer Models
Transforming Unstructured Data into Context-Aware Conversational Intelligence
Project Overview
This system is a modular AI application that combines transformer model experimentation with Retrieval-Augmented Generation (RAG) to create a dual-mode conversational intelligence system.
Dual-Mode Operation
- Document-Aware Assistant — Upload PDF/DOCX files, process them into embeddings, and ask contextual questions
- General Conversational Chatbot — Ask any question, get explanations, reasoning, and conversational responses (no document required)
Key Capabilities
- Document Upload — Drag-and-drop PDF/DOCX files for instant analysis
- RAG Pipeline — Extract text, generate embeddings, store in vector DB, and retrieve relevant context
- Groq Integration — Use Groq API (e.g., mixtral-8x7b) for fast, contextual answers
- General Chatbot — Full conversational AI that works even without uploaded documents
- Model Training — Fine-tune BERT, GPT-2, LLaMA, Mistral, and XLNet on AG News dataset
- Model Evaluation — Accuracy, precision, recall, F1-score, confusion matrices
- Model Comparison — Side-by-side performance comparison with charts and best model identification
- Report Generation — Automated visualizations, training curves, and performance summaries
System Architecture
User Interface (Flask Web App)
|
AI Agent Controller
|
Intelligent Router
|
+-----+------+-------+
| | |
Document QA General Chat Classification
(RAG Mode) (LLM Mode) (Transformer)
| | |
ChromaDB Groq API BERT/GPT-2
Embeddings LLaMA/Mistral/XLNetTransformer Models
Dataset
AG News — A 4-class text classification benchmark:
- Training samples: 200 (configurable in
config.py) - Test samples: 50 (configurable in
config.py)
Project Structure
project/
├── app.py # Flask web app + RAG engine + General chatbot
├── config.py # Central configuration
├── train.py # Model training (5 transformers) + report generation
├── requirements.txt # Python dependencies
├── README.md # This file
│
├── rag/
│ ├── __init__.py
│ └── document_loader.py # PDF/DOCX text extraction & chunking
│
├── ui/
│ ├── templates/
│ │ └── index.html # Web UI (Chat + Upload + General chatbot)
│ └── static/ # Static assets
│
├── models/ # Saved model checkpoints (created by train.py)
│ ├── bert/
│ ├── gpt2/
│ ├── llama/
│ ├── mistral/
│ └── xlnet/
│
├── data/ # Uploaded documents
├── reports/ # Generated charts & evaluation reports
├── vector_store/ # ChromaDB persistent storage
└── logs/ # Application logsInstallation
Prerequisites
- Python 3.9 or higher
- pip package manager
- (Optional) NVIDIA GPU with CUDA for faster training
- (Optional) Groq API key for enhanced chat responses
- (Optional) HuggingFace API key (HF_TOKEN) for Mistral text classification
Setup
# 1. Navigate to the project directory
cd "d:\major project-2"
# 2. Create a virtual environment (recommended)
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# 3. Install dependencies
pip install -r requirements.txtHow to Run
Step 1: Train Models (One-time, Optional)
python train.pyThis trains BERT, GPT-2, LLaMA, Mistral, and XLNet on the AG News dataset and generates:
- Confusion matrix heatmaps for each model
- Model comparison bar chart
- Training loss and accuracy curves
- Per-class classification reports
- JSON evaluation summary
- Best model identification
Step 2: Start the Web Application
python app.pyOpen your browser at http://127.0.0.1:8509
Using the Application
General Chatbot Mode (No document needed)
- Open the application
- (Optional) Enter your Groq API key in the left panel
- Start chatting — ask any question, get explanations, and conversational responses
Document Q&A Mode
- Upload a file — Drag-and-drop or click "Browse files" to select a PDF or DOCX
- Enter API Key — (Optional) Enter your Groq API key for enhanced responses
- Click Process — The system extracts text, creates embeddings, and indexes chunks
- Chat with your file — Ask questions about the uploaded document
- Get answers — The system retrieves relevant chunks and generates contextual answers
Workflow
User opens application
↓
Mode A: General Chat Mode B: Document Q&A
↓ ↓
User asks question User uploads document (PDF/DOCX)
↓ ↓
Groq generates User clicks Process
general response ↓
↓ System extracts text from document
Response displayed ↓
Text split into overlapping chunks
↓
Chunks converted to embeddings
↓
Embeddings stored in ChromaDB
↓
User asks question in chat
↓
Retriever finds relevant chunks
↓
LLM generates contextual answer
↓
Answer displayed in chatEvaluation Metrics
- Accuracy — Overall correctness
- Precision — Proportion of correct positive predictions
- Recall — Proportion of actual positives correctly identified
- F1-Score — Harmonic mean of precision and recall
- Confusion Matrix — Detailed prediction breakdown per class
Generated Reports
After running train.py, the reports/ directory will contain:
confusion_matrix_bert.png— BERT confusion matrix heatmapconfusion_matrix_gpt2.png— GPT-2 confusion matrix heatmapconfusion_matrix_llama.png— LLaMA confusion matrix heatmapconfusion_matrix_mistral.png— Mistral confusion matrix heatmapconfusion_matrix_xlnet.png— XLNet confusion matrix heatmapmodel_comparison.png— Bar chart comparing all metricstraining_curves.png— Training loss and validation accuracy curvesclassification_report_*.txt— Per-class classification reportsmodel_comparison.csv— Comparison table as CSVevaluation_summary.json— Machine-readable metrics with best model
Configuration
Edit config.py to customize:
- MAX_SAMPLES_TRAIN / MAX_SAMPLES_TEST — Dataset size
- MODELS dict — Learning rate, batch size, epochs per model
- EMBEDDING_MODEL — Sentence transformer for RAG
- CHUNK_SIZE / TOP_K_RESULTS — RAG retrieval parameters
- GROQ_MODEL — Groq model for chat responses (default: mixtral-8x7b-32768)
- PORT — Web server port (default: 8509)
License
This project is for educational and research purposes (capstone project).
