|
Download README.md from Neerajkadari/Context-Aware_Conversational_Intelligence_System: direct link, hf CLI and curl.
- Browser
- Download file 8.56 kB
-
https://huggingface.co/spaces/Neerajkadari/Context-Aware_Conversational_Intelligence_System/resolve/main/README.md
- Command line
-
hf download hf://spaces/Neerajkadari/Context-Aware_Conversational_Intelligence_System/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Neerajkadari/Context-Aware_Conversational_Intelligence_System/resolve/main/README.md
8.56 kB
metadata
title: Context-Aware Conversational Intelligence System
sdk: docker
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/XLNet
Transformer Models
| Model | Architecture | Base Model | Parameters | Training |
|---|---|---|---|---|
| BERT | Bidirectional Transformer Encoder | bert-base-uncased | 110M | Full fine-tune |
| GPT-2 | Autoregressive Transformer Decoder | gpt2 | 124M | Full fine-tune |
| LLaMA | Decoder-based Large Language Model | TinyLlama-1.1B | 1.1B | LoRA (r=8) |
| Mistral | Transformer with Sliding Window Attention | Mistral-7B-v0.1 / Mistral-7B-Instruct-v0.2 | 7B | HF Inference API (Remote) |
| XLNet | Permutation-based Autoregressive Transformer | xlnet-base-cased | 110M | Full fine-tune |
Dataset
AG News β A 4-class text classification benchmark:
| Class | Label |
|---|---|
| World | 0 |
| Sports | 1 |
| Business | 2 |
| Sci/Tech | 3 |
- 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 logs
Installation
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.txt
How to Run
Step 1: Train Models (One-time, Optional)
python train.py
This 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.py
Open 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 chat
Evaluation 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).