Text sentiment analysis method and system based on prompt multi-scale learning
By introducing a multi-scale learning method for prompts in text sentiment analysis, combining pre-trained language model, self-attention mechanism and PMSL network model, the accuracy problem of the existing technology in complex contexts and small sample scenarios is solved, and higher text sentiment classification accuracy and model adaptability are achieved.
Patent Information
- Application Number
- CN202510054967.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-13
AI Technical Summary
Existing text sentiment analysis methods have limited accuracy when dealing with complex contexts and varied emotional expressions, especially in small sample scenarios.
Using a method based on cue multi-scale learning, by adding a cue multi-scale learning template to the text, the pre-trained language model is combined with the self-attention mechanism and the PMSL network model to extract emotional knowledge and perform feature fusion.
It significantly improves the accuracy of text emotion classification, especially in the case of few samples, which improves the interpretability and adaptability of the model and reduces the demand for computing resources.
Smart Images

Figure CN119990137A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a text sentiment analysis method and system based on prompt multi-scale learning. Background Art
[0002] Text sentiment analysis refers to the process of identifying and classifying the emotional tendencies in text, aiming to determine whether the emotions expressed in the text are positive, negative, or neutral. Text sentiment analysis has many applications, such as public opinion monitoring, opinion polls, market research, user research, psychological emotion monitoring, etc.
[0003] Traditional text sentiment analysis methods need to rely on manually designed features, such as sentiment dictionaries, or need to use simple machine learning algorithms, such as decision trees, support vector machines, or naive Bayes classifiers. However, these methods are often limited by the effect of feature engineering and the expressiveness of the model, and are difficult to handle complex contexts and changing emotional expressions, and have limited accuracy.
[0004] Knowledge extraction is the process of extracting various knowledge points from the text through identification, understanding, screening and formatting, and storing them in a knowledge base in a certain form. This method has attracted much attention in the field of natural language processing and has also developed with the development of natural language processing methods. In the early days, it relied heavily on feature engineering. Prompt learning is a new natural language processing research paradigm that has emerged in recent years. It adapts the pre-trained language model to downstream tasks by adding additional text prompts to the input context, so that the knowledge embedded in the language model can be detected and task-related clues can be provided. Prompt learning can fully stimulate the potential of pre-trained language models, bridge the gap between pre-training and fine-tuning, reduce the demand for training data and time, and improve the efficiency and generalization ability of pre-trained language models.
[0005] In recent years, the application of deep learning technology in the field of natural language processing has achieved remarkable results, especially the emergence of pre-trained language models such as BERT and its variants (such as RoBERTa), which greatly improved the performance of text sentiment analysis. These pre-trained models have learned rich language knowledge and semantic representations through pre-training on large-scale corpora, and can better understand and process complex structures and implicit meanings in natural language. However, although these models perform well on many tasks, their performance is still limited in few-sample scenarios. Summary of the invention
[0006] The purpose of the present invention is to provide a text sentiment analysis method and system based on prompt multi-scale learning to solve the problems raised in the above background technology.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] A text sentiment analysis method and system based on prompt multi-scale learning, the method comprising:
[0009] Step 1: Obtain text and build a text dataset;
[0010] Step 2: preprocess the text and add a prompt multi-scale learning template to the text;
[0011] Step 3: construct a sentiment analysis model, which includes an input layer, a feature extraction layer, a feature fusion layer and an output layer, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism;
[0012] Step 4: Input the text into the sentiment analysis model. The input layer of the sentiment analysis network model converts the text input into a text word vector.
[0013] Step 5: The feature extraction layer of the sentiment analysis model is composed of the PMSL network model and the self-attention mechanism. The self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vectors, and the PMSL network model focuses on extracting contextual semantic features and sentiment knowledge.
[0014] Step 6: The feature fusion layer of the sentiment analysis model performs feature fusion on the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features;
[0015] Step 7: The output layer of the sentiment analysis model sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
[0016] Preferably, before inputting the text into the sentiment analysis model in step 4, the sentiment analysis model is trained, specifically including the following steps:
[0017] Get text and build text dataset;
[0018] Preprocess the text and add prompt multi-scale learning templates to the text;
[0019] Inputting the text in the text dataset into the sentiment analysis model, and training the sentiment analysis model using a cross entropy loss function;
[0020] The sentiment analysis model is trained using the cross entropy loss function according to the formula:
[0021]
[0022] Optimize model parameters by penalizing the model for samples that are misclassified, so that the model can better distinguish different categories;
[0023] In the formula, N represents the total number of samples in the text dataset, i represents the index of the sample, and y i represents the true label of the i-th sample, p i It represents the probability that the i-th sample predicted by the model belongs to the first category.
[0024] Preferably, the text word vector in step 4 includes:
[0025] The text word vector is obtained by encoding the input text by the pre-trained model RoBERTa in the input layer;
[0026] The text {W = w1, w2, ..., w n-1 ,w n} is input to RoBERTa, and RoBERTa is used to encode the text into word vectors to obtain word vectors and word vector matrices {H∈R L×d} and the last layer output vector v[CLS] containing the semantics of the entire sentence;
[0027] Among them, L represents the number of words in the input text, that is, the text length; d represents the word vector dimension, and each row of the word vector matrix represents the vector mapped to a single word.
[0028] Preferably, the extraction of contextual semantic features in step 5 includes:
[0029] Use PMSL network model and self-attention mechanism to process input text word vectors;
[0030] The PMSL network model has the ability to read input sequences from both forward and backward directions to capture contextual information, and uses its memory units to retain long-term dependency information;
[0031] The output of the PMSL network model will serve as the refined contextual semantic features.
[0032] Preferably, the emotional knowledge extraction in step 5 includes:
[0033] Through the knowledge decomposition of entity extraction, sentences with masks are constructed as prompt multi-scale learning templates and added to the text. Through training, the emotions in the text can be mined.
[0034] Preferably, a text sentiment analysis system based on prompt multi-scale learning comprises:
[0035] The text acquisition module is used to acquire text as the basic input data of the entire system;
[0036] A model building module, used to build a sentiment analysis model, the sentiment analysis model includes an input layer, a feature extraction layer, a feature fusion layer and an output layer, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism;
[0037] The feature extraction module is used to convert the text input into text word vectors in the text data analysis model. The self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vectors. The PMSL network model focuses on extracting contextual semantic features and sentiment knowledge. The feature fusion layer fuses the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features. The output layer sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
[0038] The present invention also provides a computer device, including a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the text sentiment analysis method based on prompt multi-scale learning.
[0039] The present invention also provides a computer-readable storage medium, which stores a computer program, and the computer program is suitable for being loaded by a processor to execute the text sentiment analysis method based on prompt multi-scale learning.
[0040] Compared with the prior art, the beneficial effects achieved by the present invention are:
[0041] The present invention combines a pre-trained language model with prompt learning to extract emotional knowledge. This method can significantly reduce the number of model parameters and improve the interpretability of the model. At the same time, this combination can efficiently utilize computing resources and speed up the training and reasoning speed of the model, which is particularly critical for application scenarios that require rapid response; the present invention can significantly improve the accuracy of text sentiment classification in a few sample scenarios. This is due to the powerful semantic representation ability of the RoBERTa model and the advantages of prompt learning in knowledge extraction. Through this method, the model can more accurately capture and understand the emotional information in the text; the present invention enables the model to flexibly respond to different types of text data and sentiment analysis tasks. By adjusting the prompt multi-scale learning template, it can easily adapt to different application scenarios and needs, and improve the adaptability and generalization ability of the model; in addition, the present invention is applicable to a variety of practical application needs, including but not limited to social media comment analysis, customer feedback processing, product evaluation analysis, etc. By providing accurate sentiment analysis results, it can help companies and individuals better understand the public's emotional attitude towards a certain thing or topic, so as to make more informed decisions. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0043] Figure 1 It is a flow chart of a text sentiment analysis method and system based on prompt multi-scale learning of the present invention;
[0044] Figure 2 This is an overall flow chart of the text sentiment analysis method of embodiment 1 of the present invention;
[0045] Figure 3 This is a structural diagram of the self-attention mechanism of Example 1 of the present invention;
[0046] Figure 4 This is an overall framework diagram of the text emotion system based on prompt multi-scale learning provided in Example 2 of the present invention. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] See also Figure 1-Figure 4 , the present invention provides a technical solution:
[0049] Embodiment 1:
[0050] The present invention provides a text sentiment analysis method based on prompt multi-scale learning, specifically Figure 2 As shown, the following steps are included:
[0051] Step 1: Obtain text and build a text dataset.
[0052] Step 2: Preprocess the text and add prompt multi-scale learning templates to the text.
[0053] Step 3: Construct a sentiment analysis model, which includes an input layer, a feature extraction layer, a feature fusion layer and an output layer, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism.
[0054] Step 4: The input layer of the sentiment analysis network model converts the text input into text word vectors;
[0055] Step 5: The feature extraction layer of the sentiment analysis model is composed of the PMSL network model and the self-attention mechanism. The self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vectors, and the PMSL network model focuses on extracting contextual semantic features and sentiment knowledge.
[0056] Step 6: The feature fusion layer of the sentiment analysis model performs feature fusion on the extracted global semantic features, contextual semantic features, and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features;
[0057] Step 7: The output layer of the sentiment analysis model sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
[0058] The overall flow chart is as follows Figure 1 As shown in the figure, the text is input into the pre-trained model RoBERTa to obtain the text word vector {x1,x2,…,x n-1 ,x n}, by embedding the prompt multi-scale learning template into the text word vector and introducing the mask tag to form a Token to facilitate the model to extract emotional knowledge; the obtained text word vector is input into the feature extraction layer, and the global emotional vector {a1, a2, …, a n-1 ,a n}, and the context semantic vector {h1,h2,…,h n-1 ,h n}, and then the final context vector {m1,m2,…,m n-1 ,m n}, and then the global sentiment vector, the final contextual semantic vector and the sentiment knowledge extracted from the prompt multi-scale learning template are fused in the fully connected layer, and the final output is obtained through the softmax classifier in the output layer.
[0059] The specific process is as follows:
[0060] (1) Train the sentiment analysis model. The training process is as follows:
[0061] Get text and build text dataset;
[0062] Preprocess the text and add prompt multi-scale learning templates to the text;
[0063] The text data in the text dataset is input into the sentiment analysis model, and the sentiment analysis model is trained using the cross entropy loss function.
[0064] The cross entropy loss function is a commonly used loss function in classification tasks. The essential idea is a log-likelihood function, which has achieved good results in practical applications. In the binary classification problem, its calculation formula is:
[0065]
[0066] Where N is the total number of samples and i is the index of the sample. i is the true label of the i-th sample, usually 0 or 1. i is the probability that the i-th sample belongs to the first category as predicted by the model.
[0067] This loss function optimizes the model parameters by penalizing the model for samples that are misclassified, so that the model can better distinguish different categories. During the training process, this loss function can be minimized through optimization algorithms such as gradient descent, thereby improving the classification performance of the model.
[0068] (2) Input the text into the sentiment analysis model. The input layer of the sentiment analysis model converts the text into text word vectors, specifically:
[0069] The text {W = w1, w2, ..., w n-1 ,w n} is input to RoBERTa, and RoBERTa is used to encode the text into word vectors to obtain word vectors and word vector matrices {H∈R L×d} and the last layer output vector v[CLS] containing the semantics of the entire sentence, where L is the number of words in the input text, that is, the text length; d is the word vector dimension, and each row of the word vector matrix represents the vector of a single word mapping.
[0070] In this embodiment, in order to deal with the problem of inconsistent text length, it is necessary to adopt a strategy called "long truncation and short filling" for the text. Specifically, for texts that exceed the preset maximum length limit, the beginning part is truncated to ensure that only the most critical information is retained; and for texts that are insufficient in length, the number 0 is added to the end to extend it to a unified length standard, that is, each text is finally adjusted to a length of 320 characters (denoted as L=320. This method helps to simplify the model input. This strategy not only maintains the main semantic content of the text, but also facilitates the subsequent sentiment analysis process. It also improves the processing efficiency and accuracy of the sentiment analysis model.
[0071] In this embodiment, the batch size of the training batch is set to 16, the Adam optimizer is selected for parameter optimization, the initial learning rate is set to 1e-5, the "early stopping" mechanism is used to prevent overfitting, the word vector dimension obtained after word vector encoding using RoBERTa is 768, the hidden layer size of the network model is 320, and the number of iterations is 10.
[0072] (3) Use the sentiment analysis model to extract features and knowledge from text vectors. Feature extraction includes global semantic feature extraction and contextual semantic feature extraction. Global semantic feature extraction is performed by outputting the last layer of RoBERTa to the self-attention mechanism; contextual semantic feature extraction is performed through the PMSL network model; in the feature fusion layer, the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template are fused to obtain sentiment information features at different levels. Through multiple training iterations, the deep features of the input text sequence can be effectively extracted.
[0073] First, in the global semantic feature extraction, the hidden state corresponding to [CLS] in the output of the last layer of RoBERTa is usually used as the representation of the entire sentence or text. [CLS] is a special semantic feature vector in RoBERTa that can represent the entire sentence text. Therefore, we choose to use this vector combined with the vector generated by the self-attention mechanism as the global semantic vector a n , the structure diagram of the self-attention mechanism is as follows Figure 3 As shown, the calculation formula is:
[0074]
[0075] Among them, Q, K, W V is the weight matrix used for linear transformation, corresponding to the vector sequence of query, key, and value. In the self-attention mechanism, the three come from the same input text, that is, the focus is on the internal dependency of the input and the dependency on other external information is reduced. dk is the dimension of the input vector, and v[CLS] is the output vector of the last layer of the input layer.
[0076] Secondly, in the context semantic feature extraction, the PMSL network model is used. The details are as follows:
[0077] First, the input data x is transformed linearly. t Converted to hidden state, its mathematical expression is:
[0078]
[0079] Among them, W is the weight of the text input.
[0080] Then the text data is input into the bidirectional gated recurrent unit BiGRU for calculation. BiGRU consists of a forget gate and an update gate, where f t is the forget gate, which is used to control the degree of information forgetting, r t It is the update gate, which is used to control the degree of information update. The calculation formula is as follows:
[0081] f t =σ(W f x t +b f ),
[0082] r t =σ(W r x t +b r ),
[0083] Among them, σ is the Sigmoid activation function, the formula is as follows:
[0084]
[0085] W f is the weight of the forget gate input, b f is the bias term. r is the weight of the forget gate input, b r is the bias term.
[0086] Intermediate state during transmission c t The update formula is as follows:
[0087]
[0088] Among them, c t-1 is the state at the moment before time t.
[0089] After calculating the intermediate state c t After that, the final output state s can be obtained. n , the calculation formula is as follows:
[0090] s n =f t ×tanh(c t )+(1-r t )×x t ,
[0091] The obtained output is concatenated and used as input to BiLSTM. The concatenation method is as follows:
[0092]
[0093] Among them, S is the intermediate output obtained by BiGRU, and They are the forward result of the sequence and the reverse result of the sequence respectively.
[0094] Bidirectional long short-term memory network (BiLSTM) consists of two directional long short-term memory networks, one network processes time series data from front to back to obtain positive results Another network processes the time series data from back to front to get the reverse result in, and The calculation formula is as follows:
[0095]
[0096]
[0097] Among them, h t is represented as the output feature, W is represented as the weight matrix, x is the training data, and b is the bias term.
[0098] Furthermore, in the process of extracting knowledge from text vectors using sentiment analysis models, the present invention introduces prompt multi-scale learning to extract local features, capture the hierarchical features of text, and understand the hierarchical and combinatorial nature of text; specifically as follows:
[0099] Design tips learning template, the design tips sentences are as follows:
[0100] 'That is too[MASK].',
[0101] Among them, [MASK] is used as a mask to naturally express the sentiment analysis task as a cloze problem.
[0102] The task objectives are achieved through cloze-style prompts, which can fully utilize the knowledge contained in the pre-trained language model and also add emotional tendencies as explicit knowledge into the sentiment analysis task.
[0103] Preprocess the text and add prompt sentences to the text as prompt multi-scale learning templates.
[0104] Use the sentiment analysis model for iterative training to extract sentiment knowledge from text vectors.
[0105] (4) In the feature fusion layer, the extracted global semantic features, contextual semantic features, and sentiment knowledge in the prompt multi-scale learning template are fused to obtain the final semantic representation vector, which is output using a softmax classifier.
[0106] The output vector a of the last layer of RoBERTa n , the context feature vector m extracted by the PMSL network modeln It is fused with [MASK] in the prompt multi-scale learning template to obtain the emotional information features v at different levels, and its calculation formula is:
[0107] v = Concat(a n ,m n ,[MASK]),
[0108] (5) The present invention verifies the performance of the sentiment analysis model on the IMDB, Amazon_Review and MPQA public datasets, and compares the model using RoBERTa as the pre-training model and the model using the self-attention mechanism in the downstream task as the baseline model. The comparison results are shown in Table 1. The experimental results show that the accuracy of the method of the present invention on the three datasets is 91.63%, 95.02% and 93.43% respectively. The accuracy of the present invention is relatively excellent.
[0109] Table 1: Comparison of the results of the baseline model and the PMSL model proposed in this paper
[0110] IMDB Amazon_Review MPQA Baseline Model 90.39% 93.56% 89.93% The PMSL model proposed in this paper 91.63% 95.02% 93.43%
[0111] Embodiment 2:
[0112] The present invention also provides a text sentiment analysis system based on prompt multi-scale learning. The overall framework diagram of the text sentiment system is shown in FIG. Figure 4 , including a text acquisition module, a model building module and a feature extraction module. The text acquisition module is used to acquire text as the basic input data of the entire system; the model building module is used to build a sentiment analysis model, which includes an input layer, a feature extraction layer, a feature fusion layer and an output, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism; the feature extraction module is used to input text data into the sentiment analysis model, and the input layer of the sentiment analysis model converts the text input into a text word vector; the self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vector, and the PMSL network model focuses on extracting contextual semantic features and sentiment knowledge extraction. The feature fusion layer performs feature fusion on the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features; the output layer sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
[0113] Embodiment 3:
[0114] The computer-readable storage medium of this embodiment stores a computer program thereon, and when the program is executed by a processor, the steps of a text sentiment analysis method and system based on prompt multi-scale learning in embodiment 1 are implemented.
[0115] The computer-readable storage medium of this embodiment may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal; the computer-readable storage medium of this embodiment may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card, a secure digital card, a flash memory card, etc. equipped on the terminal; further, the computer-readable storage medium may also include both an internal storage unit of the terminal and an external storage device.
[0116] The computer-readable storage medium of this embodiment is used to store computer programs and other programs and data required by the terminal. The computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.
[0117] Embodiment 4:
[0118] The computer device of this embodiment includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of a text sentiment analysis method and system based on prompt multi-scale learning in embodiment 1 are implemented.
[0119] In this embodiment, the processor may be a central processing unit, or other general-purpose processors, digital signal processors, application-specific integrated circuits, readily available programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0120] Those skilled in the art will appreciate that the disclosed content of the embodiments may be provided as methods, systems, or computer program products. Therefore, the present solution may adopt the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Moreover, the present solution may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program codes.
[0121] The present solution is described with reference to the method according to the embodiment of the present solution and the flowchart and / or block diagram of the computer program product. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions; these computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 one or more processes and / or methods Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0122] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 one or more processes and / or methods Figure 1 A function specified in one or more boxes.
[0123] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 one or more processes and / or methods Figure 1 The steps for the functions specified in one or more boxes.
[0124] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0125] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A text sentiment analysis method and system based on prompt multi-scale learning, characterized by: The method comprises: Step 1: Obtain text and build a text dataset; Step 2: preprocess the text and add a prompt multi-scale learning template to the text; Step 3: construct a sentiment analysis model, which includes an input layer, a feature extraction layer, a feature fusion layer and an output layer, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism; Step 4: Input the text into the sentiment analysis model. The input layer of the sentiment analysis network model converts the text input into a text word vector. Step 5: The feature extraction layer of the sentiment analysis model is composed of the PMSL network model and the self-attention mechanism. The self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vectors, and the PMSL network model focuses on extracting contextual semantic features and sentiment knowledge. Step 6: The feature fusion layer of the sentiment analysis model performs feature fusion on the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features; Step 7: The output layer of the sentiment analysis model sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
2. A text sentiment analysis method and system based on prompt multi-scale learning as claimed in claim 1, characterized in that: Before inputting the text into the sentiment analysis model in step 4, the sentiment analysis model is trained, which specifically includes the following steps: Get text and build text dataset; Preprocess the text and add prompt multi-scale learning templates to the text; Inputting the text in the text dataset into the sentiment analysis model, and training the sentiment analysis model using a cross entropy loss function; The sentiment analysis model is trained using the cross entropy loss function according to the formula: Optimize model parameters by penalizing the model for samples that are misclassified, so that the model can better distinguish different categories; In the formula, N represents the total number of samples in the text dataset, i represents the index of the sample, and y i represents the true label of the i-th sample, p i It represents the probability that the i-th sample predicted by the model belongs to the first category.
3. A text sentiment analysis method and system based on prompt multi-scale learning as claimed in claim 1, characterized in that: The text word vector in step 4 includes: The text word vector is obtained by encoding the input text by the pre-trained model RoBERTa in the input layer; The text {W = w1, w2, ..., w n-1 ,w n } is input to RoBERTa, and RoBERTa is used to encode the text into word vectors to obtain word vectors and word vector matrices {H∈R L×d } and the last layer output vector v[CLS] containing the semantics of the entire sentence; Among them, L represents the number of words in the input text, that is, the text length; d represents the word vector dimension, and each row of the word vector matrix represents the vector mapped to a single word.
4. A text sentiment analysis method and system based on prompt multi-scale learning as claimed in claim 1, characterized in that: The extraction of contextual semantic features in step 5 includes: Use PMSL network model and self-attention mechanism to process input text word vectors; The PMSL network model has the ability to read input sequences from both forward and backward directions to capture contextual information, and uses its memory units to retain long-term dependency information; The output of the PMSL network model will serve as the refined contextual semantic features.
5. A text sentiment analysis method and system based on prompt multi-scale learning as claimed in claim 1, characterized in that: The emotional knowledge extraction in step 5 includes: Through the knowledge decomposition of entity extraction, sentences with masks are constructed as prompt multi-scale learning templates and added to the text. Through training, the emotions in the text can be mined.
6. A text sentiment analysis system based on prompt multi-scale learning, characterized in that: The system comprises: The text acquisition module is used to acquire text as the basic input data of the entire system; A model building module, used to build a sentiment analysis model, the sentiment analysis model includes an input layer, a feature extraction layer, a feature fusion layer and an output layer, wherein the feature extraction layer is composed of a PMSL network model and a self-attention mechanism; The feature extraction module is used to convert the text input into text word vectors in the text data analysis model. The self-attention mechanism of the feature extraction layer extracts global semantic features from the text word vectors. The PMSL network model focuses on extracting contextual semantic features and sentiment knowledge. The feature fusion layer fuses the extracted global semantic features, contextual semantic features and sentiment knowledge in the prompt multi-scale learning template to obtain multi-level sentiment information features. The output layer sends the sentiment features after feature aggregation to the classifier to obtain the analyzed text sentiment.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of a text sentiment analysis method and system based on prompt multi-scale learning as described in any one of claims 1-6 are implemented.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the steps in the text sentiment analysis method and system based on prompted multi-scale learning are implemented as described in any one of claims 1-6.