This project focuses on sentiment analysis using a Convolutional Neural Network (CNN) model built with TensorFlow and Keras. The model is trained to classify the sentiment of hotel reviews as either positive or negative.
This project was built by Will Nzeuton, with help from Otzar Jaffe and Elias Xu.
-
Clone the repository:
git clone https://github.com/stuyai/sentiment_analysis.git cd sentiment_analysis
-
Install the required packages:
pip install -r requirements.txt
-
Download the dataset:
!wget https://stuyai.org/download/reviews.csv
-
Run the Jupyter notebook:
jupyter notebook STUYAI_SENTIMENTAL_ANALYSIS_FULL.ipynb
sentiment_analysis/
├── data/
│ └── reviews.csv
├── models/
│ └── sentiment_model.h5
├── notebooks/
│ ├── STUYAI_SENTIMENTAL_ANALYSIS_FULL.ipynb
│ └── STUYAI_SENTIMENTAL_ANALYSIS_BLANK.ipynb
├── README.md
├── LISCENSE and other files
└── requirements.txt
The model consists of the following layers:
- Embedding layer
- Convolutional layers with MaxPooling
- Dense layers with Dropout
- Output layer with softmax activation
The model is trained using the following hyperparameters:
max_features
: 12000embedding_dim
: 32sequence_length
: 600epochs
: 4batch_size
: 16validation_split
: 0.1
The model is evaluated on a test set, and the accuracy is printed:
Test Accuracy: 0.9563
To make predictions on new reviews, use the predict
function defined in the notebook:
new_reviews = ["The hotel was fantastic!", "I had a terrible experience."]
predict(new_reviews)
This project is licensed under the MIT License. See the LICENSE file for details.