This is a proof-of-concept implementation of aspect based sentiment analysis using multi-task learning. The model architecture was taken from Eram Munawwar's blog post.
The prototype neural network model was trained on ~3000 restaurant reviews with polarity labels over 5 different aspects. The model achieved a test accuracy of 0.7434 compared against the majority baseline of 0.6410. The accuracy of different aspects is reported as follows.
Aspect | Baseline accuracy | ABSA accuracy |
---|---|---|
food | 0.7225 | 0.7823 |
service | 0.5872 | 0.8430 |
price | 0.6145 | 0.7590 |
ambience | 0.6441 | 0.7542 |
anecdotes/miscellaneous | 0.5427 | 0.5897 |
Overall | 0.6410 | 0.7434 |
Python >3.8 is required.
virtualenv absa_env
source absa_env/bin/activate
pip install -r requirements.txt
python -m spacy download en_core_web_md
python src/make_reviews.py
will process the restaurant review data and export it into parquet format.
python src/train.py
will train a multi-task neural network model for sentiment analysis.
python src/evaluate.py
will make prediction for the test data and compute the accuracy for different aspects.
python src/debug_dataset.py
can be used for debugging the process of datasets creation.
python src/debug_model.py
can be used for debugging the network architecture.
- Tunstall, L., Werra, L. von, & Wolf, T. (2022). Natural language processing with transformers, Revised edition. O'Reilly Media, Inc.
- Aspect Based Sentiment Analysis
- Splitting a Dataset for Machine Learning
- SemEval-2014 Task 4: Aspect Based Sentiment Analysis
- SemEval-2016 Task 5: Aspect Based Sentiment Analysis
- A detailed example of how to generate your data in parallel with PyTorch
- RANZCR: Multi-Head Model [training]
- Tutorial 6: Transformers and Multi-Head Attention