This project is designed to perform sentiment analysis on Amharic text using a neural network model. The model is built using PyTorch for the machine learning component and Flask for the web interface. The project includes preprocessing of Amharic text, training a sentiment analysis model, and deploying it as a web application.
-
Clone the repository:
git clone https://github.com/Danitilahun/Amharic_NLP_Sentiment_Analysis_Neural_Networks_LSTM.git
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Run the Flask application:
flask run --port=5001
-
Access the web interface: Open your browser and go to
http://127.0.0.1:5001/
. -
Analyze sentiment: Enter Amharic text in the provided input field and submit to get the sentiment analysis result.
The model's performance on the train and test datasets is as follows:
- Accuracy: 0.9461
- Precision: 0.9757
- Recall: 0.9185
- F1 Score: 0.9464
- AUC: 0.9781
- Accuracy: 0.9219
- Precision: 0.9522
- Recall: 0.8937
- F1 Score: 0.9220
- AUC: 0.9575
- Class 0.0:
- Precision: 0.9179
- Recall: 0.9754
- F1-Score: 0.9458
- Support: 26757.0
- Class 1.0:
- Precision: 0.9756
- Recall: 0.9188
- F1-Score: Missing
- Support: Missing
- Class 0.0:
- Precision: 0.8939
- Recall: 0.9529
- F1-Score: 0.9218
- Support: 2983.0
- Class 1.0:
- Precision: 0.9523
- Recall: 0.8937
- F1-Score: Missing
- Support: Missing
The Flask application provides the following API endpoints:
- GET
/
: Renders the home page with the sentiment analysis form. - POST
/analyze
: Accepts JSON data with atext
field and returns the sentiment analysis result.
{
"text": "ይህ ፕሮጀክት በጣም ጥሩ ነው!"
}
{
"sentiment": "positive",
"probability": 95.7
}
The project relies on the following Python libraries:
- Flask: For building the web interface.
- gunicorn: For deploying the Flask app.
- torch: For building and training the neural network.
- nltk: For text tokenization.
- numpy: For numerical operations.
- pickle: For loading pre-trained embeddings.
You can install all dependencies by running:
pip install -r requirements.txt
Note: This project is for educational purposes and may require further tuning for production use.