https://github.com/markkreel/sentiment-analysis-api
A machine learning API for analyzing sentiment in text phrases using Natural Language Processing (NLP) techniques.
https://github.com/markkreel/sentiment-analysis-api
api flask machine-learning python sentiment-analysis
Last synced: 2 months ago
JSON representation
A machine learning API for analyzing sentiment in text phrases using Natural Language Processing (NLP) techniques.
- Host: GitHub
- URL: https://github.com/markkreel/sentiment-analysis-api
- Owner: Markkreel
- Created: 2022-02-22T13:36:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-03-24T19:07:12.000Z (over 1 year ago)
- Last Synced: 2025-04-07T13:20:05.190Z (about 1 year ago)
- Topics: api, flask, machine-learning, python, sentiment-analysis
- Language: Python
- Homepage:
- Size: 2.27 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sentiment Analysis API
A machine learning API for analyzing sentiment in text phrases using Natural Language Processing (NLP) techniques.
## Features
- Binary sentiment classification (positive/negative)
- REST API endpoint for predictions
- Model training pipeline with TF-IDF vectorization
- Multinomial Naive Bayes classifier
- ROC curve evaluation metrics
## Installation
1. Clone repository
2. Create virtual environment:
```bash
python -m venv venv
venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
## Dependencies
- Flask
- scikit-learn
- pandas
- matplotlib
## Project Structure
```json
├── app.py # Flask API endpoints
├── build_model.py # Model training script
├── model.py # NLP model class definition
├── requirements.txt # Dependency list
├── sentiment_data/ # Training data (TSV files)
└── chalicelib/models/ # Saved model artifacts
```
## Usage
1. Train the model:
```bash
python build_model.py
```
2. Start the API:
```bash
flask run
```
## API Endpoints
GET `/sentiment`
- Parameters:
- `sentence`: Text phrase to analyze
- Example:
```bash
http://localhost:5000/sentiment?sentence="I really enjoy this product"
```
- Response:
```json
{
"sentence": "I really enjoy this product",
"sentiment": "positive",
"probability": 0.92
}
```
## Implementation Details
The system uses:
- TF-IDF vectorization for text feature extraction
- Multinomial Naive Bayes classifier (scikit-learn)
- ROC AUC score of 0.93 on test data
- Model artifacts persisted as pickle files