Customer Satisfaction Processing Bot
This tool processes customer satisfaction survey data to:
- Classify sentiment of customer reviews (positive/negative)
- Send customized discounts for negative reviews
- Recommend 3 best trips for positive reviews
- Extract mentioned locations using Named Entity Recognition (NER)
- Compare classification metrics against ground truth data
- Save all output to CSV files
- Sentiment analysis of customer reviews
- Personalized responses for both positive and negative reviews
- Trip recommendations for positive reviews
- Discount codes for negative reviews
- CSV output of processed reviews
- Named Entity Recognition (NER) to extract mentioned locations
- Sentiment analysis metrics calculation (accuracy, precision, recall, F1 score)
- Comparison against ground truth sentiment data
- Install dependencies:
pip install -r requirements.txt
- Download spaCy language model:
python -m spacy download en_core_web_sm
- Set your OpenAI API key:
export OPENAI_API_KEY=your_api_key_here
Run the processor:
cd src
python processor.py
This will:
- Process all reviews in
data/customer_surveys.json - Save processed reviews to
data/processed_reviews.csv - Save extracted locations to
data/extracted_locations.csv - Display sentiment analysis metrics
After processing the reviews, generate visualizations:
cd src
python visualize.py
This will create:
confusion_matrix.png: Confusion matrix for sentiment analysismetrics_chart.png: Bar chart of accuracy, precision, recall, and F1 scoresatisfaction_by_sentiment.png: Average satisfaction scores by sentimenttop_locations.png: Top 10 mentioned locationsentity_types.png: Distribution of entity types
-
processed_reviews.csv: Contains all processed reviews with:- Original review text
- Detected sentiment
- Reasoning for sentiment classification
- Ground truth sentiment
- Customer satisfaction score
- Personalized response message
- Recommended trips (for positive reviews)
- Discount code (for negative reviews)
-
extracted_locations.csv: Contains all extracted locations with:- Review ID
- Location name
- Entity type
The system uses:
- LangChain for orchestrating the LLM workflow
- OpenAI's GPT-4o for sentiment analysis and response generation
- spaCy for Named Entity Recognition
- scikit-learn for calculating sentiment analysis metrics
- Matplotlib for visualization of metrics and results
-
Data Processing Pipeline:
- Load customer review data from JSON
- Perform sentiment analysis with LLM
- Generate personalized responses based on sentiment
- Extract locations using NER
- Save processed results to CSV files
-
Sentiment Analysis Workflow:
- Uses a branching chain to route reviews to appropriate handling
- Positive reviews: Generate thank-you message and trip recommendations
- Negative reviews: Generate apology, improvement plan, and discount code
-
NER Implementation:
- Uses spaCy's named entity recognition to extract locations
- Identifies Geopolitical Entities (GPE), Locations (LOC), and Facilities (FAC)
- Tracks entity types for further analysis
-
Metrics Evaluation:
- Compares predicted sentiment against ground truth
- Calculates accuracy, precision, recall, and F1 score
- Generates visualizations to understand model performance