Current deep learning-based methods for text sentiment classification have not fully exploited character-level information and sentiment source information, leaving room for improvement in the field. To address this, we propose a novel method, Character-BERT-Sentiment-Attention (CBSA), which leverages a pretrained BERT model and focuses on multi-sentiment character-level information. This approach enhances the semantic representation of text by capturing character-level features and concatenating BERT’s pretrained word embeddings of BERT to form a unified semantic vector. Subsequently, contextual words are integrated with four types of sentiment source information (sentiment words, negation words, degree adverbs, and conjunctions) into a gated recurrent unit(GRU) neural network. An attention mechanism is employed to generate a sentence representation that incorporates sentiment-related resources, followed by a softmax classification layer to predict sentiment polarity. By extracting both character-level and multi-sentiment source information, the proposed method captures sentiment-relevant features from diverse representational subspaces, thereby improving the sentiment prediction accuracy. Experimental results on five benchmark datasets demonstrate that the proposed method significantly improves classification accuracy.
随着深度学习技术的发展,基于深度学习的文本情感分类方法成为领域内的主流[8-11],其相较传统方法能更有效处理复杂语言结构和上下文信息,提供更准确的情感分析。Catelli等[12]将基于BERT的深度学习模型与传统的基于词典的模型进行对比,其研究显示基于BERT的深度学习模型在数据集充足的情况下性能得到大幅提升,但在小规模数据集上则表现不佳,这表明在数据受限的情况下可能需要进一步优化以提高其性能。Bhuvaneshwari等[13]提出的用于文本情感分析的模型结合了双向长短期记忆网络(Bidirectional Long Short-Term Memory, Bi-LSTM)、自注意力机制和卷积神经网络(Convolutional Neural Network, CNN),能自动学习和提取分类特征,有效捕捉n-gram特征和上下文关键信息,与主流模型的比较结果表明,该模型在性能上具有显著优势。总体而言,基于深度学习的文本情感分类方法在多个方面展现出显著的优势。首先,该方法能够更有效地处理复杂和抽象的语言特征,例如上下文关系、语义细节和词语间的隐含关联,这些是传统基于词典或简单机器学习方法难以捕捉的。其次,深度学习模型(如BERT、Bi-LSTM)结合自注意力机制,使得模型在理解和分析文本时,不仅关注单词本身,还能够捕捉到更深层次的语义和情感倾向,从而提供更准确和细腻的文本情感分类结果。
然而,基于深度学习的文本情感分类方法与传统情感分类方法一样未能充分发掘文本字符级的信息,且没有利用好文本情感分类核心特征之一的情感来源词。因此,本文提出了一种基于BERT的面向多情感字符级信息的文本情感分类方法(Character-BERT-Sentiment-Attention, CBSA),该方法基于BERT,结合字符级信息、情感来源词以及自注意力机制,旨在优化文本情感分类。CBSA方法通过利用门控循环单元网络(Gated Recurrent Unit, GRU)整合字符级信息与词级向量,并通过情感来源词和注意力机制增强句子表示,从而提升情感分析的准确性和深度。本文主要贡献包括:
BERT的自注意力机制是其最重要的结构[16-17],它能有效地学习文本中的长距离依赖关系,取代了传统的卷积神经网络和循环神经网络。自注意力机制使得每个单词能够间接地“看到自己”,通过掩盖式语言模型(Masked Language Model, MLM)和下一个句子预测(Next Sentence Prediction, NSP)方法进行预训练。自注意力机制使用尺度缩放点积注意力计算注意力权重,如(1)式所示:
其中,(查询矩阵)、(键矩阵)和(值矩阵)均由输入序列的向量转换而来。在计算注意力时,首先通过矩阵计算查询与键之间的相似性,并通过因子进行缩放,以避免数值过大导致梯度消失或爆炸。随后,使用Softmax归一化获得注意力分布,并利用其对矩阵进行加权求和。具体来说,设输入序列中的第i个单词对应的向量为,维度为dk, qi 、 ki 、 vi 分别是的第i行向量,则有:
其中,、、是学习到的权重矩阵, qi 与 ki 是dk 维向量, vi 是dv 维向量。这种机制可以动态调整序列中不同位置的关注程度,不依赖固定的序列长度,从而增强模型对全局信息的建模能力,提高文本理解效果。
其中, W 和 U 是权重参数矩阵,是激活函数,一般用sigmoid函数。在GRU中,重置门确定之前的隐藏状态单元是否被忽视,而更新门则控制当前的隐藏状态单元是否必须由一个新的隐藏状态单元进行更新,计算公式如下:
其中,为当前时间步的候选隐藏状态,为最后的输出,表示逐元素相乘运算, Wh 用于对当前输入进行线性变换并通过tanh激活函数进行处理, Wo 用于将隐藏状态映射到最终的输出空间,GRU的重置门和更新门分别有助于捕获短期时间步长和长期时间步长的依赖关系,在特定情况下,GRU可以取得比LSTM更好的表现。由于GRU参数更少,其效率更高,具有更快的计算速度和收敛速度,更加有利于学习文本中的上下文语义关系,提高文本情感分类的准确性。
式中,、、、、矩阵表示分别为文本上下文单词表示、情感词表示、否定词表示、程度副词表示以及连接词表示,维度都为dk,j、k、l、m、n分别为句子长度、情感词长度、否定词长度、程度副词长度以及连接词长度。为了更好地计算单词的相关性, W 矩阵中的每个向量都将标准化为单位向量,从而更好地计算单词之间的相关性,方便后续多情感注意力分数的计算。
Movie Review(MR)电影评论数据集[23]:该数据集包含10 662条电影评论,其中正面和负面情感的评论样本各占一半。每个样本都有一个二元标签,表示情感极性,该数据集被广泛用于评估和比较文本情感分类算法和模型的性能。实验中选取8 000个作为训练样本,其余2 662个作为测试样本进行实验。
通过表中数据对比显示,BERT+情感词典相比于传统的Word2Vec+情感词典以及Word2Vec+Glove+情感词典具有更强的语义信息提取能力,并在四项评价指标中均表现出色,特别是在精确率方面,BERT+情感词典相对于Word2Vec+Glove+情感词典在五个数据集上分别提高0.49%、1.26%、1.51%、0.78%、0.99%,这说明深度学习结合情感词典的方法确实能够提升模型性能。而对比Word2Vec+情感词典、Word2Vec+Glove+情感词典、LSTM和Att+Bi-GRU可以发现基于深度学习的情感分析方法未必都比传统的基于情感词的方法性能更优,因此虽然基于深度学习的情感分析方法是主流方法,但是传统的情感词仍有其独特优势可待发掘。尽管当前主流的情感分析方法多基于深度学习模型,但在部分数据集中,基于传统情感词典的模型同样表现出色。其原因主要有两点:1) 此类数据集中的评论数据含有丰富的情感词汇,且情感表达较为直接;2) 情感词典经过不断完善,覆盖面广,能较好匹配数据集的语境。在与BERT+情感词典、LSTM、Att+Bi-GRU和CBSA的准确率对比中发现,CBSA相较于其他模型表现出了较为优越的性能,在MR数据集上比BERT+情感词典准确率提高了2.53个百分点;在CSCHb-2数据集上比BERT+情感词典准确率提高了1.61个百分点;在IMDB数据集上比BERT+情感词典准确率提高了3.45个百分点;在外卖评论数据集上比Att+Bi-GRU提高了0.28个百分点;在SST-2数据集上比BERT+情感词典准确率提高了2.99个百分点。对比CBSA和DCNN-BiGRU-Att可以发现,在MR数据集上CBSA的准确率提升了约5.14个百分点,但在SST-2数据集上CBSA准确率却降低了2.51个百分点,这表明两个模型的泛化能力存在局限性,无法在不同类型的数据集上保持一致的性能。SST-2数据集为二元单句分类任务的数据集,其中的单条数据往往一句话或者一个短语概括,如:“a better movie”和“the situation in a well-balanced fashion”,本文方法在基于词级向量的基础上又增加了字符级信息,虽然能够更深层次地挖掘语境信息,但是可能存在过拟合的情况,所以导致准确率较低。而MR数据集相较SST-2数据集单条数据较长,能够有效地将提取到的字符级信息利用起来。总体而言,本文提出的CBSA在较多数据集上表现良好,但是泛化能力有待提高,在语境复杂的数据集能展现更好的性能。
AMEURA, HAMDIS, YAHIA SBEN. Sentiment analysis for hotel reviews: A systematic literature review[J]. ACM Computing Surveys, 2024, 56(2): 1-38. DOI: 10.1145/3605152 .
[2]
OJEDA-HERNÁNDEZM, LÓPEZ-RODRÍGUEZD, MORAÁ. Lexicon-based sentiment analysis in texts using Formal Concept Analysis[J]. International Journal of Approximate Reasoning, 2023, 155: 104-112. DOI: 10.1016/j.ijar.2023.02.001 .
[3]
MAHAJANIS J, SRIVASTAVAS, SMEATONA F. A comparison of lexicon-based and ML-based sentiment analysis: Are there outlier words? [EB/OL]. 2023: 2311.06221.DOI: 10.1109/aics60730.2023.10470734 .
[4]
ZHANGY, SONGJ H, SCIACCAA, et al. Novel sentiment lexica derived from user generating content by Chinese tourists in Pacific Islands[J]. Sustainability, 2022, 14(23): 15833. DOI: 10.3390/su142315833 .
[5]
MEHMOODY, BALAKRISHNANV. An enhanced lexicon-based approach for sentiment analysis: A case study on illegal immigration[J]. Online Information Review, 2020, 44(5): 1097-1117. DOI: 10.1108/oir-10-2018-0295 .
[6]
BAROR A, PAGUDPUDM V, PADIRAYONL M, et al. Classification of project management tool reviews using machine learning-based sentiment analysis[J]. IOP Conference Series: Materials Science and Engineering, 2019, 482(1): 012041. DOI: 10.1088/1757-899x/482/1/012041 .
LIY, WEIZ H, XUK. Hybrid feature selection method of Chinese emotional characteristics based on lasso algorithm[J]. Computer Science, 2018, 45(1): 39-46. DOI: 10.11896/j.issn.1002-137X.2018.01.006(Ch ).
[9]
ZHOUZ G. Research on sentiment analysis model of short text based on deep learning[J]. Scientific Programming, 2022, 2022(1): 2681533. DOI: 10.1155/2022/2681533 .
[10]
HEZ F. Text sentiment analysis based on multi-layer bi-directional LSTM with a trapezoidal structure[J]. Intelligent Automation & Soft Computing, 2023, 37(1): 639-654. DOI: 10.32604/iasc.2023.035352 .
[11]
MAY C, TENGY, DENGZ Z, et al. Does writing style affect gender differences in the research performance of articles? : An empirical study of BERT-based textual sentiment analysis[J]. Scientometrics, 2023, 128(4): 2105-2143. DOI: 10.1007/s11192-023-04666-w .
[12]
WUJ, ZHUT L, ZHUJ H, et al. A optimized BERT for multimodal sentiment analysis[J]. ACM Transactions on Multimedia Computing, Communications, and Applications, 2023, 19(2s): 1-12. DOI: 10.1145/3566126 .
[13]
CATELLIR, PELOSIS, ESPOSITOM. Lexicon-based vs. bert-based sentiment analysis: A comparative study in Italian[J]. Electronics, 2022, 11(3): 374. DOI: 10.3390/electronics11030374 .
[14]
BHUVANESHWARIP, RAOA N, ROBINSONY H, et al. Sentiment analysis for user reviews using Bi-LSTM self-attention based CNN model[J]. Multimedia Tools and Applications, 2022, 81(9): 12405-12419. DOI: 10.1007/s11042-022-12410-4 .
[15]
BOUALILIL, MORENOJ G, BOUGHANEMM. Highlighting exact matching via marking strategies for ad hoc document ranking with pretrained contextualized language models[J]. Information Retrieval Journal, 2022, 25(4): 414-460. DOI: 10.1007/s10791-022-09414-x .
[16]
ZHANGZ B, WUS, JIANGD W, et al. BERT-JAM: Maximizing the utilization of BERT for neural machine translation[J]. Neurocomputing, 2021, 460: 84-94. DOI: 10.1016/j.neucom.2021.07.002 .
[17]
ZHANGA M, LIB H, WANGW H, et al. MII: A novel text classification model combining deep active learning with BERT[J]. Computers, Materials & Continua, 2020, 63(3): 1499-1514. DOI: 10.32604/cmc.2020.09962 .
[18]
SHENT, ZHOUT Y, LONGG D, et al. DiSAN: Directional self-attention network for RNN/CNN-free language understanding[J]. Proceedings of the AAAI Conference on Artificial Intelligence, 2018, 32(1): 5446-5455. DOI: 10.1609/aaai.v32i1.11941 .
[19]
RAWATA, AHMAD WANIM, ELAFFENDIM, et al. Drug adverse event detection using text-based convolutional neural networks (TextCNN) technique[J]. Electronics, 2022, 11(20): 3336. DOI: 10.3390/electronics11203336 .
[20]
SHAND H, LIH L. Group emotion recognition for weibo topics based on BERT with TextCNN[J]. American Journal of Information Science and Technology, 2023, 7(3): 95-100. DOI: 10.11648/j.ajist.20230703.11 .
LIL Q, YANGL, ZENGY Y. Improving sentiment classification of restaurant reviews with attention-based Bi-GRU neural network[J]. Symmetry, 2021, 13(8): 1517. DOI: 10.3390/sym13081517 .
[24]
ZHANGX, ZHAOJ B, LECUNY. Character-level convolutional networks for text classification[EB/OL]. [2015-09-04]. DOI: 10.48550/arXiv.1509.01626 .
[25]
LEIZ Y, YANGY J, YANGM, et al. A multi-sentiment-resource enhanced attention network for sentiment classification[C]//Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers). Stroudsburg: Association for Computational Linguistics, 2018: 758-763. DOI: 10.18653/v1/p18-2120 .
WUC B. Application of text emotion classification algorithm in public opinion analysis[D]. Nanchang: Nanchang University, 2021. DOI: 10.27232/d.cnki.gnchu.2021.001993(Ch ).
[28]
TANS B, ZHANGJ. An empirical study of sentiment analysis for Chinese documents[J]. Expert Systems with Applications, 2008, 34(4): 2622-2629. DOI: 10.1016/j.eswa.2007.05.028 .
YANGS X, ZHANGN. Text sentiment analysis based on sentiment lexicon and context language model[J]. Journal of Computer Applications, 2021, 41(10): 2829-2834. DOI: 10.11772/j.issn.1001-9081.2020121900(Ch ).
TAOW. Research and application of sentiment analysis model based on Weibo’s text[D]. Nanchang: Nanchang University, 2021.DOI: 10.27232/d.cnki.gnchu.2021.003317(Ch ).
[33]
SOCHERR, PERELYGINA, WUJ Y, et al. Recursive deep models for semantic compositionality over a sentiment treebank[C]//Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing. Stroudsburg:Association for Computational Linguistics, 2013: 1631-1642. DOI: 10.18653/v1/d13-1170 .
[34]
THAVAREESANS, MAHESANS. Sentiment lexicon expansion using Word2vec and fastText for sentiment prediction in Tamil texts[C]//2020 Moratuwa engineering research conference (MERCon). New York: IEEE Press, 2020: 272-276. DOI:10.1109/MERCon50084.2020.9185369
[35]
SHENY F, LIUJ H. Comparison of text sentiment analysis based on bert and word2vec[C]//2021 IEEE 3rd international conference on frontiers technology of information and computer (ICFTIC). New York: IEEE Press, 2021: 144-147. DOI: 10.1109/ICFTIC54370.2021.9647258
[36]
KODIYALAV S, MERCERR E. Emotion recognition and sentiment classification using bert with data augmentation and emotion lexicon enrichment[C]//2021 20th IEEE International Conference on Machine Learning and Applications (ICMLA). New York: IEEE Press, 2021: 191-198. DOI: 10.1109/ICMLA52953.2021.00037
[37]
MURTHYD G S N, ALLUS R, ANDHAVARAPUB, et al. Text based sentiment analysis using LSTM[J]. International Journal of Engineering Research & Technology, 2020, 9(5): 299-303. DOI: 10.17577/ijertv9is050290 .