Enhancing Sentiment Analysis in Product Reviews: Fine-Tuning BERT for Class Imbalance and Optimal Sequence Representation
摘要
Sentiment analysis, a pivotal aspect of natural language processing (NLP), offers profound insights into public sentiment from vast swathes of unstructured textual data. This paper presents an empirical investigation into the applicability and effectiveness of the Bidirectional Encoder Representations from Transformers (BERT) algorithm for sentiment analysis, particularly focused on product reviews. The research delves into the nuances of consumer language expressions and evaluates the capacity of BERT to accurately classify sentiment in a large-scale dataset of food product reviews. The results achieved through this research are significant, with the fine-tuned BERT model demonstrating high accuracies, indicating its robustness and suitability for the sentiment classification task. In addressing the challenges posed by the varying lengths of consumer reviews, this study offers a methodological analysis for selecting the optimal maximum sequence length (max_seq_length) parameter within BERT’s framework. A critical balance is achieved between computational efficiency and the comprehensive inclusion of informative content within the reviews. Furthermore, the paper confronts the prevalent issue of class imbalance in sentiment analysis datasets by employing a weighted loss function during the training of BERT. This technique ensures equitable representation and consideration of all sentiment classes, enhancing the model’s accuracy and fairness.