Transfer learning for Twitter sentiment analysis: Choosing an effective source dataset

  • Eliseu Guimarães Universidade Federal Fluminense, Marinha do Brasil
  • Jonnathan Carvalho Instituto Federal Fluminense
  • Aline Paes Universidade Federal Fluminense
  • Alexandre Plastino Universidade Federal Fluminense


Sentiment analysis on social media data can be a challenging task, among other reasons, because labeled data for training is not always available. Transfer learning approaches address this problem by leveraging a labeled source domain to obtain a model for a target domain that is different but related to the source domain. However, the question that arises is how to choose proper source data for training the target classifier, which can be made considering the similarity between source and target data using distance metrics. This article investigates the relation between these distance metrics and the classifiers’ performance. For this purpose, we propose to evaluate four metrics combined with distinct dataset representations. Computational experiments, conducted in the Twitter sentiment analysis scenario, showed that the cosine similarity metric combined with bag-of-words normalized with term frequency-inverse document frequency presented the best results in terms of predictive power, outperforming even the classifiers trained with the target dataset in many cases.

Palavras-chave: dataset representation, machine learning, metrics, sentiment analysis, supervised learning, transfer learning


Bravo-Marquez, F., Frank, E., Mohammad, S. M., and Pfahringer, B. Determining word-emotion associations

from tweets by multi-label classification. In Proceedings of the 2016 IEEE/WIC/ACM International Conference on

Web Intelligence (WI). IEEE, Omaha, USA, pp. 536–539, 2016.

Cambria, E., Poria, S., Gelbukh, A., and Thelwall, M. Sentiment analysis is a big suitcase. IEEE Intelligent Systems 32 (6): 74–80, 2017.

Carvalho, J. and Plastino, A. On the combination and evaluation of state-of-the-art features in twitter sentiment analysis. Artificial Intelligence Review, 2020.

Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K. Bert: Pre-training of deep bidirectional transformers for language understanding. In NAACL-HLT (1). Association for Computational Linguistics, Minneapolis, MN, 2019.

Kusner, M., Sun, Y., Kolkin, N., and Weinberger, K. From word embeddings to document distances. In Proceedings of the International Conference on Machine Learning. PMLR, Lille, France, pp. 957–966, 2015.

Liu, B. Sentiment Analysis and Opinion Mining. Morgan & Claypool Publishers, San Rafael, USA, 2012.

Martínez-Cámara, E., Martín-Valdivia, M., López, L., and Montejo-Ráez, A. Sentiment analysis in twitter. Natural Language Engineering vol. 20, pp. 1–28, 01, 2014.

Mikolov, T., Chen, K., Corrado, G. S., and Dean, J. Efficient Estimation of Word Representations in Vector Space. CoRR vol. abs/1301.3781, 2013.

Pan, S. J. and Yang, Q. A Survey on Transfer Learning. IEEE Transactions on Knowledge and Data Engineering 22 (10): 1345–1359, 2010.

Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M., and Duchesnay, E. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research vol. 12, pp. 2825–2830, 2011.

Petrovic, S., Osborne, M., and Lavrenko, V. The edinburgh twitter corpus. In Proceedings of the NAACL HLT 2010 Workshop on Computational Linguistics in a World of Social Media. Association for Computational Linguistics, Los Angeles, CA, pp. 25–26, 2010.

Plank, B. and van Noord, G. Effective measures of domain similarity for parsing. In Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies. Association for Computational Linguistics, Portland, USA, pp. 1566–1576, 2011.

Remus, R. Domain adaptation using domain similarity- and domain complexity-based instance selection for cross-domain sentiment analysis. In Proceedings of the 2012 IEEE 12th International Conference on Data Mining Workshops. IEEE, Brussels, Belgium, pp. 717–723, 2012.

Ruder, S. Neural transfer learning for natural language processing. Ph.D. thesis, NUI Galway, 2019.

Ruder, S. and Plank, B. Learning to select data for transfer learning with Bayesian Optimization. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics, Copenhagen, Denmark, pp. 372–382, 2017.

Santos, J. S., Paes, A., and Bernardini, F. Combining labeled datasets for sentiment analysis from different domains based on dataset similarity to predict electors sentiment. In Proceedings of the 2019 8th Brazilian Conference on Intelligent Systems (BRACIS). IEEE, Salvador, Brazil, pp. 455–460, 2019.

Van Asch, V. and Daelemans, W. Using Domain Similarity for Performance Estimation. In Proceedings of the 2010 Workshop on Domain Adaptation for Natural Language Processing. Association for Computational Linguistics, Uppsala, Sweden, pp. 31–36, 2010.
GUIMARÃES, Eliseu; CARVALHO, Jonnathan; PAES, Aline; PLASTINO, Alexandre. Transfer learning for Twitter sentiment analysis: Choosing an effective source dataset. In: SYMPOSIUM ON KNOWLEDGE DISCOVERY, MINING AND LEARNING (KDMILE), 8. , 2020, Evento Online. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2020 . p. 161-168. ISSN 2763-8944. DOI: