journal article·2025-06-05Open access

Optimizing an LSTM Self-Attention Architecture for Portuguese Sentiment Analysis Using a Genetic Algorithm

Daniel Parada, Alexandre Branco, Marcos Silva, Fábio Mendonça, Sheikh Mostafa, Fernando Morgado-Dias

Applied Sciences· Volume 15· Issue 11

Abstract

A sentiment analysis is a Natural Language Processing (NLP) task that identifies the opinion or emotional tone of documents such as customer reviews, either at the general or detailed level. Improving domain-specific models is important, as it provides smaller and better-suited models that can be implemented by entities that own textual data. This paper presents a deep learning model trained on Portuguese restaurant reviews using recurrent and self-attention mechanisms, which have consistently delivered strong results in prior research studies. Designing an effective model involves numerous hyperparameters and architectural choices. To address this complexity, a discrete genetic algorithm was used to find an optimal configuration, selecting the layer types, placement of self-attention, dropout rate, and model dimensions and shape. A key outcome of this study was that the optimization process produced a model that is competitive with a Bidirectional Encoder Representation from Transformers (BERT) model retrained for Portuguese, which was used as the baseline. The proposed model achieved an area under the curve of 92.1% and F1-score of 75.4%, demonstrating that a small, optimized model can compete and even outperform larger state-of-the-art models. Moreover, this work helps address the scarcity of NLP resources for Portuguese, and highlights the potential of customized architectures over generic solutions.
Source: crossref · Quality: baseline

Research context

OpenAlex topics: Sentiment Analysis and Opinion Mining · Topic Modeling · Speech Recognition and Synthesis

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

Affiliations

Faculty of Exact Sciences and Engineering, University of Madeira, 9000-082 Funchal, Portugal

ITI/LARSyS and ARDITI, 9020-105 Funchal, Portugal

Funding

ARDITI-Agência Regional para o Desenvolvimento da Investigação, Tecnologia e Inovação · Madeira · FCT

References (38)

Show source-provided references
1. Deep Learning for Sentiment Analysis: A Survey10.1002/widm.1253 ↗
2. Recent Trends in Deep Learning Based Natural Language Processing [Review Article]10.1109/MCI.2018.2840738 ↗
3. Natural Language Processing: State of The Art, Current Trends and Challenges10.1007/s11042-022-13428-4 ↗
4. Touvron, H., Lavril, T., Izacard, G., Martinet, X., Lachaux, M.A., Lacroix, T., Rozière, B., Goyal, N., Hambro, E., and Azhar, F. (2023). LLaMA: Open and Efficient Foundation Language Models. arXiv.
5. (2024, June 19). Languages Most Frequently Used for Web Content as of January 2024, by Share of Websites. Available online: https://www.statista.com/statistics/262946/most-common-languages-on-the-internet/.
6. Ferrone, L., and Zanzotto, F.M. (2020). Symbolic, Distributed and Distributional Representations for Natural Language Processing in the Era of Deep Learning: A Survey. Front. Robot. AI, 6.10.3389/frobt.2019.00153 ↗
7. A Survey of the Usages of Deep Learning for Natural Language Processing10.1109/TNNLS.2020.2979670 ↗
8. Sentiment analysis methods, applications, and challenges: A systematic literature review10.1016/j.jksuci.2024.102048 ↗
9. A Survey of Sentiment Analysis in the Portuguese Language10.1007/s10462-020-09870-1 ↗
10. Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K. (2019, January 2–7). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Long and Short Papers), Minneapolis, MN, USA.
11. A survey on sentiment analysis methods, applications, and challenges10.1007/s10462-022-10144-1 ↗
12. A Hybrid CNN-LSTM Model for Improving Accuracy of Movie Reviews Sentiment Analysis10.1007/s11042-019-07788-7 ↗
13. BERTimbau: Pretrained BERT Models for Brazilian Portuguese
14. Rodrigues, J., Gomes, L., Silva, J., Branco, A., Santos, R., Cardoso, H.L., and Osório, T. (2023). Advancing Neural Encoding of Portuguese with Transformer Albertina PT-*. arXiv.10.1007/978-3-031-49008-8_35 ↗
15. Characterizing Opinion Mining: A Systematic Mapping Study of the Portuguese Language
16. Souza, F.D., and Baptista de Oliveira e Souza Filho, J. (2021, January 2–4). Sentiment Analysis on Brazilian Portuguese User Reviews. Proceedings of the 2021 IEEE Latin American Conference on Computational Intelligence (LA-CCI), Temuco, Chile.10.1109/LA-CCI48322.2021.9769838 ↗
17. Brum, H.B., and Nunes, M.d.G.V. (2018, January 7–12). Building a Sentiment Corpus of Tweets in Brazilian Portuguese. Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC 2018), Miyazaki, Japan.
18. Gomes, F.B., Coello, J.M.A., and Kintschner, F.E. (2018). Studying the Effects of Text Preprocessing and Ensemble Methods on Sentiment Analysis of Brazilian Portuguese Tweets. Statistical Language and Speech Processing, Proceedings of the 6th International Conference, SLSP 2018, Mons, Belgium, 15–16 October 2018, Springer Nature Switzerland. Lecture Notes in Computer Science.10.1007/978-3-030-00810-9_15 ↗
19. dos Santos, F.L., and Ladeira, M. (2014, January 18–22). The Role of Text Pre-processing in Opinion Mining on a Social Media Language Dataset. Proceedings of the 2014 Brazilian Conference on Intelligent Systems, Sao Paulo, Brazil.10.1109/BRACIS.2014.20 ↗
20. Embedding Generation for Text Classification of Brazilian Portuguese User Reviews: From Bag-of-Words to Transformers10.1007/s00521-022-08068-6 ↗
21. (2023, June 30). Repositório de Word Embeddings do NILC. Available online: http://www.nilc.icmc.usp.br/embeddings.
22. Sentiment analysis in Portuguese tweets: An evaluation of diverse word representation models10.1007/s10579-023-09661-4 ↗
23. Cardoso, M.H., Maria Da Rocha Fernandes, A., Marin, G., Quietinho Leithardt, V.R., and Crocker, P. (2021, January 23–26). Comparison between Different Approaches to Sentiment Analysis in the Context of the Portuguese Language. Proceedings of the 16th Iberian Conference on Information Systems and Technologies (CISTI), Chaves, Portugal.10.23919/CISTI52073.2021.9476501 ↗
24. Merschmann, L.H. Joint Evaluation of Preprocessing Tasks with Classifiers for Sentiment Analysis in Brazilian Portuguese Language10.1007/s11042-020-10323-8 ↗
25. Sentiment Analysis of Tweets in Brazilian Portuguese with Convolutional Neural Networks10.31686/ijier.vol7.iss6.1547 ↗
26. Britto, L.F.S., Pessoa, L.A.S., and Agostinho, S.C.C. (December, January 28). Cross-Domain Sentiment Analysis in Portuguese using BERT. Proceedings of the Anais do XIX Encontro Nacional de Inteligência Artificial e Computacional (ENIAC 2022), Campinas, Brazil.10.5753/eniac.2022.227217 ↗
27. Branco, A., Parada, D., Silva, M., Mendonça, F., Mostafa, S.S., and Morgado-Dias, F. (2024). Sentiment Analysis in Portuguese Restaurant Reviews: Application of Transformer Models in Edge Computing. Electronics, 13.10.3390/electronics13030589 ↗
28. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, L., and Polosukhin, I. (2017). Attention Is All You Need. arXiv.
29. Sentiment Analysis Model Based on Self-Attention and Character-Level Embedding10.1109/ACCESS.2020.3029694 ↗
30. Wu, Z., Nguyen, T.-S., and Ong, D. (2020, January 20). Structured Self-Attention Weights Encode Semantics in Sentiment Analysis. Proceedings of the Third BlackboxNLP Workshop on Analyzing and Interpreting Neural Networks for NLP, Online.10.18653/v1/2020.blackboxnlp-1.24 ↗
31. A review on genetic algorithm: Past, present, and future10.1007/s11042-020-10139-6 ↗
32. De Olival, D., Branco, A., Silva, M., Mendonça, F., Mostafa, S.S., and Morgado-Dias, F. (2024). PT-EN Zomato Dataset. Mendeley Data.
33. Current State of Text Sentiment Analysis from Opinion to Emotion Mining10.1145/3057270 ↗
34. Gated Recurrent Unit with Multilingual Universal Sentence Encoder for Arabic Aspect-Based Sentiment Analysis10.1016/j.knosys.2021.107540 ↗
35. Random Search for Hyper-Parameter Optimization
36. Liashchynskyi, P.B., and Liashchynskyi, P. (2019). Grid Search, Random Search, Genetic Algorithm: A Big Comparison for NAS. arXiv.
37. Mendonça, F., Mostafa, S.S., Freitas, D., Morgado-Dias, F., and Ravelo-García, A.G. (2022). Multiple Time Series Fusion Based on LSTM: An Application to CAP A Phase Classification Using EEG. Int. J. Environ. Res. Public Health, 19.10.3390/ijerph191710892 ↗
38. Zhou, P., Qi, Z., Zheng, S., Xu, J., Bao, H., and Xu, B. (2016, January 11–16). Text Classification Improved by Integrating Bidirectional LSTM with Two-dimensional Max Pooling. Proceedings of the COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers, Osaka, Japan. Available online: http://dblp.uni-trier.de/db/conf/coling/coling2016.html#ZhouQZXBX16.