Long Dang
commited on
add item describe
Browse files- .gitattributes +1 -0
- Overall.png +3 -0
- README.md +73 -3
- requirements.txt +10 -0
.gitattributes
CHANGED
|
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
lstm_cnn.keras filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
lstm_cnn.keras filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
Overall.png filter=lfs diff=lfs merge=lfs -text
|
Overall.png
ADDED
|
Git LFS Details
|
README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sentiment Analysis Using LSTM and CNN
|
| 2 |
+
This project implements a hybrid deep learning model combining **Long Short-Term Memory (LSTM)** networks and **Convolutional Neural Networks (CNN)** for sentiment analysis. The architecture leverages the strengths of both LSTM and CNN to process textual data and classify sentiments effectively.
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
## Model Architecture
|
| 7 |
+

|
| 8 |
+
The architecture consists of two parallel branches that process the input text sequences and merge their outputs for final classification:
|
| 9 |
+
|
| 10 |
+
### **Branch 1: CNN-Based Processing**
|
| 11 |
+
1. **Embedding Layer**: Converts input sequences into dense vector representations.
|
| 12 |
+
2. **Conv1D + Activation**: Extracts local features from the text using convolutional filters.
|
| 13 |
+
3. **MaxPooling1D**: Reduces the spatial dimensions while retaining the most important features.
|
| 14 |
+
4. **BatchNormalization**: Normalizes the activations to stabilize and accelerate training.
|
| 15 |
+
5. **Conv1D + MaxPooling1D + BatchNormalization**: Repeats the convolution and pooling process to extract deeper features.
|
| 16 |
+
6. **Flatten**: Converts the 2D feature maps into a 1D vector.
|
| 17 |
+
|
| 18 |
+
### **Branch 2: LSTM-Based Processing**
|
| 19 |
+
1. **Embedding Layer**: Similar to the CNN branch, converts input sequences into dense vector representations.
|
| 20 |
+
2. **Bidirectional LSTM**: Captures long-term dependencies in the text by processing it in both forward and backward directions.
|
| 21 |
+
3. **LayerNormalization**: Normalizes the outputs of the LSTM layer.
|
| 22 |
+
4. **Bidirectional GRU**: Further processes the sequence with Gated Recurrent Units for efficiency.
|
| 23 |
+
5. **LayerNormalization**: Normalizes the GRU outputs.
|
| 24 |
+
6. **Flatten**: Converts the sequence outputs into a 1D vector.
|
| 25 |
+
|
| 26 |
+
### **Merging and Classification**
|
| 27 |
+
1. **Concatenate**: Combines the outputs of the CNN and LSTM branches.
|
| 28 |
+
2. **Dense Layers with Dropout**: Fully connected layers with ReLU activation and dropout for regularization.
|
| 29 |
+
3. **Output Layer**: A dense layer with a softmax activation function to classify the sentiment into three categories: Positive, Neutral, and Negative.
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## Why LSTM + CNN for Sentiment Analysis?
|
| 34 |
+
|
| 35 |
+
### **LSTM Strengths**
|
| 36 |
+
- LSTMs are well-suited for capturing long-term dependencies in sequential data, such as text.
|
| 37 |
+
- They excel at understanding the context and relationships between words in a sentence.
|
| 38 |
+
|
| 39 |
+
### **CNN Strengths**
|
| 40 |
+
- CNNs are effective at extracting local patterns and features, such as n-grams, from text data.
|
| 41 |
+
- They are computationally efficient and can process data in parallel.
|
| 42 |
+
|
| 43 |
+
### **Hybrid Approach**
|
| 44 |
+
By combining LSTM and CNN, the model benefits from:
|
| 45 |
+
- **Contextual Understanding**: LSTM captures the sequential nature of text.
|
| 46 |
+
- **Feature Extraction**: CNN identifies important local patterns.
|
| 47 |
+
- **Robustness**: The merged architecture ensures better generalization and performance on sentiment classification tasks.
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Applications
|
| 52 |
+
This model can be used for:
|
| 53 |
+
- Social media sentiment analysis (e.g., Twitter, Reddit).
|
| 54 |
+
- Customer feedback classification.
|
| 55 |
+
- Opinion mining in reviews and surveys.
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## Training and Evaluation
|
| 60 |
+
The model is trained on labeled datasets with text and sentiment labels. It uses:
|
| 61 |
+
- **Sparse Categorical Crossentropy** as the loss function.
|
| 62 |
+
- **AdamW Optimizer** for efficient training.
|
| 63 |
+
- **Early Stopping** and **Model Checkpoints** to prevent overfitting and save the best model.
|
| 64 |
+
|
| 65 |
+
The performance is evaluated using metrics like accuracy, confusion matrix, and classification report.
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## Conclusion
|
| 70 |
+
The hybrid LSTM + CNN architecture provides a powerful framework for sentiment analysis, combining the strengths of sequential modeling and feature extraction. This approach is versatile and can be adapted to various text classification tasks.
|
| 71 |
+
|
| 72 |
+
## Lisence
|
| 73 |
+
MIT Lisence
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow-macos
|
| 2 |
+
tensorflow-metal
|
| 3 |
+
text_hammer
|
| 4 |
+
scikit-learn
|
| 5 |
+
setuptools
|
| 6 |
+
wheel
|
| 7 |
+
spacy
|
| 8 |
+
bs4
|
| 9 |
+
html5lib
|
| 10 |
+
lxml
|