Sample stance detection method and device based on hierarchical contrastive learning
Through the hierarchical comparison learning method, a sample position detection model is constructed, which solves the problem of position detection of unknown target text, and realizes efficient position prediction in the case of data imbalance, improving the cross-objective migration ability and detection accuracy of the model.
Patent Information
- Application Number
- CN202310191175.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-02
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2043-03-02
AI Technical Summary
The prior art is difficult to effectively detect the text position of unknown targets, especially in the case of unbalanced data distribution, and obtaining high-quality labels is expensive, and there are challenges in adapting to sample position detection of unknown targets.
Using a method based on hierarchical contrast learning, a data set is constructed through social network text data, a sample position detection model is established, and a global semantic feature extraction, aspect-level and attribute-level feature extraction, and multidimensional semantic feature fusion are used. Combining the comparison learning loss between groups and within groups, the position detection model is trained, and the position probability of the comment text on the topic text is output.
It is realized that the probability of the comment text on the subject text is accurately predicted in the case of unbalanced distribution of position target data, improves the detection ability of unknown target domains, and improves the generalization ability and detection accuracy of the model.
Smart Images

Figure CN116414979B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data mining and analysis, and in particular to a sample stance detection method and device based on hierarchical contrastive learning. Background Art
[0002] Text stance detection, also known as stance classification or recognition, involves automatically determining a user's stance on a given target from their posted text. Along with sentiment analysis, stance detection and sentiment analysis are important research areas in the field of text opinion mining. Unlike sentiment analysis, stance detection requires discerning the more complex "support, opposition, or neutral" stance, rather than the positive or negative sentiment polarity toward a specific target.
[0003] In recent years, stance detection research has garnered widespread attention from both academia and industry, finding applications in a wide range of fields, including business intelligence and public opinion analysis. Furthermore, it serves as a supporting tool for many areas of research, with its findings applicable to dialogue systems, personalized recommendations, social perception, and other research fields, possessing significant academic and application value.
[0004] Traditional target-specific stance detection primarily focuses on single-target stance detection. Given a single text (a tweet, Weibo post, news article, debate text, etc.) and a target, the goal is to determine whether the text supports, opposes, or is neutral toward the target. This assumes that data on the same target exists in both the training and test sets. However, in practice, collecting data on all target topics for training is not feasible. A large amount of data on unseen targets is always available, and obtaining high-quality labels for a new target topic is often expensive. Therefore, research on adaptive stance detection for samples with unknown targets is crucial. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a sample stance detection method and device based on hierarchical contrastive learning, which collects social network text data to obtain the probability of the stance held by the comment text on the subject text.
[0006] The technical solution adopted by the present invention to solve the above technical problems is: a sample stance detection method based on hierarchical contrastive learning, comprising the following steps:
[0007] 1) Data collection: In social network media, social network text data is collected. Social network text data includes the topic text of the discussion and the user's comment text on the topic.
[0008] 2) Construct a dataset based on the collected data. The source topic target dataset with known stance labels is used as the training set; the target topic target dataset without stance labels is used as the test set.
[0009] 3) Establish a sample stance detection model to output the predicted probability of the stance of the comment text with respect to the topic text;
[0010] 4) Train the sample stance detection model using the training set until the sample stance detection model converges to obtain the stance prediction model;
[0011] 5) Input the topic text and comment text to be predicted into the trained stance prediction model, and output the probability of the stance held by the comment text on the topic text.
[0012] Preferably, in step 2, each topic text, comment text, and stance label constitutes a training sample, and each topic text and comment text that does not overlap with the training sample topic text constitutes a test sample. All texts are organized in this way to construct the training set and the test set.
[0013] Preferably, the source topic target data set with known stance labels is , that is, the training set; the target data set of the purpose topic without stance label , that is, the test set; Is the source topic target There are stance labels for labeled examples in and The number of samples of source topic target data and destination topic target data respectively; using the source topic target data set About source topic target Every sentence Train the sample stance detection model so that it can be generalized to the target topic data set On the target topic, predict Sentences The position of the comment text is then outputted as the predicted probability of the position held by the topic text.
[0014] Preferably, in step 3, the sample stance detection model includes: a text global semantic feature extraction module, an aspect-level feature extraction module, an attribute-level feature extraction module, a multi-dimensional semantic feature fusion module, and a stance detection module;
[0015] Text global semantic feature extraction module: The topic text and comment text are spliced as input, and the global semantic features of the comment text for a specific topic are output;
[0016] Aspect-level feature extraction module: takes the obtained global semantic features as input and outputs multiple aspect-level features that constitute the text semantics;
[0017] Attribute-level feature extraction module: takes the obtained aspect-level features as input and outputs the corresponding attribute-level features within the aspect-level features;
[0018] Multi-dimensional semantic feature fusion module: It takes multiple aspect-level features obtained and concatenates them as input, and outputs fusion features of global semantic feature distribution;
[0019] Stance detection module: takes the obtained fusion features as input and outputs the predicted probability of the user comment text's stance on a specific topic text.
[0020] Preferably, in the text global semantic feature extraction module, each sample is constructed into the format of "[CLS]t[SEP]r[SEP]" and input to the encoder module to obtain the hidden layer of the [CLS] tag. dimensional vector As the feature representation of sentence r for a specific target t, and the feature matrix of all words in sentence r in the last hidden layer :
[0021]
[0022] In a training batch, the feature representation of all samples can be defined as , is the size of the training batch.
[0023] Preferably, the aspect-level feature extraction module is used to extract the global semantic features The semantic expression features of different aspect levels are extracted, and each aspect is regarded as a feature group; the aspect-level feature extraction module is composed of K feature experts, each of which is defined as a dimensional input channels and The one-dimensional convolution of the dimensional output channel has a convolution kernel size of ; then the kth expert outputs a vector .
[0024] Preferably, the aspect-level feature extraction module adopts supervised inter-group contrastive learning, and any two pairs of samples from the same group are regarded as positive examples, and samples from different groups are regarded as negative examples. The inter-group contrastive loss of each data batch in the aspect-level feature extraction module is defined as:
[0025]
[0026] A projection head is used to project aspect-level features Mapped to , used to calculate contrast loss; is the inter-group loss corresponding to the i-th aspect-level example; is an indicator function if and only if When is 1; Represents the temperature parameter of the between-group contrast loss, which is used to control the penalty strength for difficult samples in contrastive learning.
[0027] Preferably, in the attribute-level feature extraction module, attribute-level feature learning is formulated as a self-supervised representation learning problem;
[0028] Through expert feature mapping function The sample The global semantic features are mapped to the corresponding aspect-level feature space to obtain the positive sample pairs , while the other samples in the kth group are negative samples;
[0029] The intra-group contrast loss for each data batch in the attribute-level feature extraction module is defined as:
[0030]
[0031] in, is the contrast loss of the i-th aspect-level example, represents the temperature parameter within the group, is an indicator function if and only if When is 1.
[0032] Preferably, in the multi-dimensional semantic feature fusion module, the fusion feature is represented as:
[0033]
[0034] in, For splicing operations, is the fusion feature of sample i after splicing K aspects of features, is a feedforward neural network, is the feature after multi-dimensional semantic fusion, and are learnable parameters.
[0035] Furthermore, the distribution consistency between the original global semantic features and the fused semantic features is maintained by optimizing the KL divergence between the two.
[0036]
[0037] Preferably, in the stance detection module, a fully connected layer with softmax normalization is used to predict the probability distribution of stance prediction:
[0038]
[0039] in, For input example The predicted probability distribution of positions, is the dimension of the stance label, and are learnable parameters.
[0040] Preferably, in step 4, the supervised stance classification loss , self-supervised inter-group contrastive learning loss , self-supervised intra-group contrastive learning loss and global semantic preservation loss To train the model; the overall goal It can be formulated as the sum of four losses:
[0041]
[0042] in, is an adjustable hyperparameter, Represents all trainable parameters in the model, represents the L2 regularization coefficient.
[0043] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the above-mentioned sample stance detection method based on hierarchical contrastive learning is implemented.
[0044] A computer-readable storage medium having a program stored thereon, characterized in that when the program is executed by a processor, the above-mentioned sample stance detection method based on hierarchical contrastive learning is implemented.
[0045] The beneficial effects of the present invention are as follows: the sample stance detection method based on hierarchical contrastive learning of the present invention collects data from social network media, constructs a data set based on the collected data, establishes a sample stance detection model, outputs the predicted probability of the stance held by the comment text to the subject text, and trains the sample stance detection model through the training set until the sample stance detection model converges to obtain a stance prediction model; the subject text and comment text to be predicted are input into the trained stance prediction model, and the probability of the stance held by the comment text to the subject text is output, so that stance detection can be performed even when the stance target data is unbalanced. The sample stance detection method based on hierarchical contrastive learning provided by the present invention can be used for online public opinion event analysis and data mining fields, and can especially be used for monitoring user stance analysis and supervision with relatively concentrated semantics. It can also be used for enterprise network information supervision, predicting product feedback that enterprises are concerned about, and improving product lines and related services. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 Schematic diagram of the steps of a sample stance detection method based on hierarchical contrastive learning in one embodiment of the present invention;
[0047] Figure 2Schematic diagram of the flow of a sample stance detection method based on hierarchical contrastive learning in one embodiment of the present invention;
[0048] Figure 3 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0049] The following describes the embodiments of the present invention in detail with reference to the accompanying drawings and examples, so that the present invention can fully understand how to apply technical means to solve technical problems and achieve technical effects, and thus implement the invention accordingly. It should be noted that, as long as no conflict exists, the various embodiments of the present invention and the various features of the embodiments can be combined with each other, and the resulting technical solutions are all within the scope of protection of the present invention.
[0050] Additionally, the steps shown in the flowcharts of the accompanying drawings may be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowcharts, in some cases the steps shown or described may be performed in an order different from that shown.
[0051] See Figure 1 、 Figure 2 The present invention provides a sample stance detection method based on hierarchical contrastive learning, comprising the following steps:
[0052] 1) Data collection: In social network media, social network text data is collected. Social network text data includes the topic text of the discussion and the user's comment text on the topic.
[0053] 2) Construct a dataset based on the collected data. The source topic target dataset with known stance labels is used as the training set; the target topic target dataset without stance labels is used as the test set.
[0054] 3) Establish a sample stance detection model to output the predicted probability of the stance of the comment text with respect to the topic text;
[0055] 4) Train the sample stance detection model using the training set until the sample stance detection model converges to obtain the stance prediction model;
[0056] 5) Input the topic text and comment text to be predicted into the trained stance prediction model, and output the probability of the stance held by the comment text on the topic text.
[0057] Specifically, in one embodiment of the present invention, in step 2, each topic text, comment text, and stance label constitutes a training sample, and each topic text and comment text that does not overlap with the training sample topic text constitutes a test sample. All texts are organized in this way to construct training sets and test sets.
[0058] Specifically, in one embodiment of the present invention, the source topic target data set with known stance labels is , that is, the training set; the target data set of the purpose topic without stance label , that is, the test set; Is the source topic target There are stance labels for labeled examples in and The number of samples of source topic target data and destination topic target data respectively; using the source topic target data set About source topic target Every sentence Train the sample stance detection model so that it can be generalized to the target topic data set On the target topic, predict Sentences The position of the comment text is then outputted as the predicted probability of the position held by the topic text.
[0059] Specifically, in one embodiment of the present invention, in step 3, the sample stance detection model includes: a text global semantic feature extraction module, an aspect-level feature extraction module, an attribute-level feature extraction module, a multi-dimensional semantic feature fusion module, and a stance detection module;
[0060] Text global semantic feature extraction module: The topic text and comment text are spliced as input, and the global semantic features of the comment text for a specific topic are output;
[0061] Aspect-level feature extraction module: takes the obtained global semantic features as input and outputs multiple aspect-level features that constitute the text semantics;
[0062] Attribute-level feature extraction module: takes the obtained aspect-level features as input and outputs the corresponding attribute-level features within the aspect-level features;
[0063] Multi-dimensional semantic feature fusion module: It takes multiple aspect-level features obtained and concatenates them as input, and outputs fusion features of global semantic feature distribution;
[0064] Stance detection module: takes the obtained fusion features as input and outputs the predicted probability of the user comment text's stance on a specific topic text.
[0065] Specifically, in one embodiment of the present invention, the text global semantic feature extraction module is mainly composed of a Bert layer, the topic text and the comment text are spliced and input into the global semantic feature extraction module, and the global semantic features of the comment text for a specific topic are output.
[0066] This part focuses on the high-level semantics of the text and learns to form sentences with n words. Targeting specific topics Each sample is constructed as "[CLS]t[SEP]r[SEP]" format and input to the encoder module to obtain the [CLS] tag hidden layer dimensional vector As the feature representation of sentence r for a specific target t, and the feature matrix of all words in sentence r in the last hidden layer :
[0067]
[0068] In a training batch, the feature representation of all samples can be defined as , is the size of the training batch. In this embodiment, Set to 32, Set to 768.
[0069] Specifically, in one embodiment of the present invention, the aspect-level feature extraction module maps global semantic features to different feature distribution spaces to achieve the separation of multiple aspect-level features. Here, K nonlinear feature embedding functions are learned. Projecting global semantic features onto different dimensional latent space.
[0070] The aspect-level feature extraction module extracts global semantic features from The semantic expression features of different aspect levels are extracted from the module, and each aspect is regarded as a feature group. The aspect-level feature extraction module is composed of K feature experts, each of which is defined as a feature group with dimensional input channels and The one-dimensional convolution of the dimensional output channel has a convolution kernel size of . Then the kth expert outputs a vector . Given a training batch of input data ,After processing by the aspect level feature extraction module, the global semantic features of each sample are separated into K groups, each group has Aspect-level examples, namely ,in is the i-th sample in the k-th group, Aspect-level examples The label of (here, the group number is used as the label, i.e. ), so K groups common In this embodiment, K is set to 4. Set to 3, Set to 283.
[0071] Secondly, to decouple different aspect-level features as much as possible, supervised inter-group contrastive learning is used to achieve high cohesion within a group and low coupling between groups. Here, any two pairs of examples from the same group are considered positive examples, and examples from different groups are considered negative examples. Therefore, the inter-group contrastive loss for each data batch in the aspect-level feature extraction module is defined as:
[0072]
[0073]
[0074] Among them, a projection head (i.e., a layer of MLP) is used to transform the aspect-level features Mapped to , used to calculate contrast loss; is the inter-group loss corresponding to the i-th aspect-level example; is an indicator function if and only if When is 1; represents the temperature parameter of the inter-group contrast loss, which is used to control the penalty intensity for difficult samples in contrastive learning. In this embodiment, Set to 0.5.
[0075] Specifically, in one embodiment of the present invention, the attribute-level feature extraction module mainly focuses on the various attribute features that may be contained in a certain aspect. Different attribute features express different positions and attitudes towards the target, and the attribute-level feature learning is expressed as a self-supervised representation learning problem.
[0076] Dropout is used as the data enhancement for the minimum form of the representation vector, which forms a positive sample pair with the original semantic sample. Definition is an encoder with dropout mask m, which converts the sample Use different dropout masks m to input the encoder twice to obtain two feature representations representing global semantics . Further, through the expert feature mapping function The sample The global semantic features are mapped to the corresponding aspect-level feature space to obtain the positive sample pairs , while the other samples in the kth group are negative samples. The data batch for contrastive learning after data enhancement is represented as , whose size is Therefore, the intra-group contrast loss for each data batch in the attribute-level feature extraction module is defined as:
[0077]
[0078] in, is the contrast loss of the i-th aspect-level example, represents the temperature parameter within the group, is an indicator function if and only if When is 1. In this embodiment, Set to 0.5, Set to 32.
[0079] Specifically, in one embodiment of the present invention, the multi-dimensional semantic feature fusion module focuses on the effectiveness of learning multi-faceted features. The multi-faceted features are spliced together and fused and dimensionally reduced through a feedforward neural network. Finally, the multi-faceted fused features are expressed as:
[0080]
[0081] in, For splicing operation, is the fusion feature of sample i after splicing K aspects of features, is a feedforward neural network, is the feature after multi-dimensional semantic fusion, and are learnable parameters.
[0082] Furthermore, the distribution consistency between the original global semantic features and the fused semantic features is maintained by optimizing the KL divergence between the two.
[0083]
[0084] Specifically, in one embodiment of the present invention, the stance detection module inputs the obtained multi-faceted fusion features into the stance detection module, and outputs the predicted probability of the stance held by the user comment text on the specific topic text.
[0085] A fully connected layer with softmax normalization is used to predict the probability distribution of stance prediction:
[0086]
[0087] in, For input example The predicted probability distribution of positions, is the dimension of the stance label, and is a learnable parameter. In this embodiment, The value is 3, indicating that the positions are divided into three types: support, neutral and opposition.
[0088] Finally, by predicting the label of the sample and the true label The cross entropy loss is used to train the classifier:
[0089]
[0090] Specifically, in one embodiment of the present invention, step 4: training the stance detection model using the training set until the stance detection model converges to obtain a trained stance detection prediction model.
[0091] Specifically, in one embodiment of the present invention, the predicted probability output by the stance prediction model is compared with the true label, and the log-likelihood loss function is optimized using the gradient descent method, and the supervised stance classification loss is jointly optimized. , self-supervised inter-group contrastive learning loss , self-supervised intra-group contrastive learning loss and global semantic preservation loss To train the model. The overall goal It can be formulated as the sum of four losses:
[0092]
[0093] in, is an adjustable hyperparameter, Represents all trainable parameters in the model, Represents the L2 regularization coefficient. The back propagation algorithm is used to train the model parameters of the stance detection. The stance detection model is trained iteratively through the training set until the model converges to obtain a trained stance detection model. In this embodiment, Set to 0.2, Set to 0.3, Set to 0.1, Set to 1e-5.
[0094] Specifically, in one embodiment of the present invention, step 5: after the topic text and user comment text to be predicted are formed into a sample, they are input into a trained stance detection model to output the probability of the stance held by the user comment text on the relevant topic; in this embodiment, the aspect with the highest probability is finally selected as the stance attitude of the user comment text on the relevant topic.
[0095] For the task of sample stance detection, some existing methods attempt to generalize models to unknown targets through attention mechanisms and the incorporation of external knowledge. However, this direct transfer from known to unknown topics often has limited predictive effectiveness due to the potential presence of topic-specific features. Adversarial learning methods, which use a discriminator to guide the model to learn target-independent features, can lead to reduced prediction performance when the stance target data distribution is imbalanced. However, these methods primarily focus on learning "coarse-grained," high-level features based on the global feature space of the text, often ignoring the many "detailed processes" that influence stance expression. This approach introduces significant noise and compromises the transferability of the model to unknown target domains. Therefore, modeling the distribution of multiple fundamental low-level features within the semantic representation of text facilitates fine-grained alignment from known to unknown target domains, making it suitable for sample stance detection. Based on this, we propose a stance detection model that utilizes hierarchical contrastive learning for multidimensional semantic feature representation. This model learns fine-grained, multi-faceted, underlying features within the semantic representation of text to improve the accuracy of stance classification for unknown samples. Specifically, first, multiple experts are introduced as coarse-grained feature extractors, and inter-group supervised contrastive learning is used to capture multidimensional aspect-level features in text semantic expression; second, an intra-group self-supervised contrastive learning algorithm is designed to learn multiple distinguishable attribute-level features within the group; finally, the original global semantic features are enhanced through fine-grained multi-aspect features to achieve the model's cross-domain stance classification capability.
[0096] This architecture has two advantages:
[0097] (1) More efficient knowledge transfer capability. This paper designs a new hierarchical contrastive learning scheme. Through inter-group contrastive learning and intra-group contrastive learning, it mines the features of text stance expression and then compares them with the unknown target domain features, thus serving as a bridge for cross-target knowledge transfer. Experiments on public datasets show that compared with the latest cross-target stance detection method PT-HCL, the proposed method has a 4.3% improvement. Table 1 shows the experimental results of the sample stance detection task comparing the present invention with other methods. MSFR represents the present invention. The bold values in each row of Table 1 represent the best experimental results, and the underlined values represent the second best results.
[0098] Table 1:
[0099]
[0100] (2) More accurate modeling of user stance features. Feature enhancement based on multi-faceted features takes into account the "detailed process" of text stance expression, improves the quality of feature representation, and enables the model to better handle prediction tasks such as zero-shot and cross-target. Through ablation experiments on real data, it was verified that there was a +4.5% performance difference between the results of no feature enhancement and the results of fusing two features in this embodiment, verifying that the multi-faceted feature enhancement in this embodiment achieves stronger feature representation capabilities. Table 2 shows the ablation experiment analysis results comparing the present invention with other methods. MSFR refers to the present invention, and w / o indicates that a certain loss function is not used.
[0101] Table 2:
[0102]
[0103] This embodiment is equivalent to the prior art and has the following advantages:
[0104] 1. This invention models multiple fundamental underlying features of text semantic expression, learning knowledge features that are transferable and shared across different topics. This invention extends traditional deep learning approaches for stance detection by analyzing the underlying structure of text semantics to capture common underlying features of social network text.
[0105] 2. Aiming at the expression of text stance, the present invention designs a global semantic preservation mechanism to ensure the effectiveness of the learned multi-faceted underlying features, and uses the multi-faceted features to enhance the global semantic features, thereby predicting the stance of the user comment text.
[0106] This embodiment utilizes the underlying features of text semantic expression and has more reliable prediction performance for sample stance detection problems. Therefore, for different Internet topics, more general deep learning model basic parameters can be obtained through training, which can better solve problems within the semantic scope, such as social issues and online public opinion issues.
[0107] The method provided in this embodiment can be used for online public opinion event analysis and data mining, and can especially be used for monitoring user positions with relatively concentrated semantics, and can also be used for corporate network information supervision, predicting product feedback that companies are concerned about, and improving product lines and related services.
[0108] In an embodiment of the present invention, a computer device is further provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the sample stance detection method based on hierarchical contrastive learning as described above is implemented.
[0109] The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 3As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a zero-sample position detection method based on hierarchical contrast learning is implemented. The display screen of the computer device can be a liquid crystal display or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse.
[0110] The memory may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), and electrically erasable programmable read-only memory (EEPROM). The memory is used to store programs, and the processor executes the programs after receiving execution instructions.
[0111] The processor can be an integrated circuit chip with signal processing capabilities. The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc. The processor can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The various methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0112] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0113] In an embodiment of the present invention, a computer-readable storage medium is further provided, on which a program is stored, wherein when the program is executed by a processor, the sample stance detection method based on hierarchical contrastive learning as described above is implemented.
[0114] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, computer devices, or computer program products. Thus, embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0115] The embodiments of the present invention are described with reference to flowcharts and / or block diagrams of methods, computer devices, or computer program products according to the embodiments of the present invention. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, such that execution of the instructions by the processor of the computer or other programmable data processing terminal device produces means for implementing the functions specified in the flowcharts and / or block diagrams.
[0116] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in the flowchart.
[0117] The above is a detailed introduction to the application of the zero-sample stance detection method based on hierarchical contrastive learning, the computer device, and the computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A sample stance detection method based on hierarchical contrastive learning, characterized by: The following steps are involved: 1) Data collection: In social network media, social network text data is collected. Social network text data includes the text of the discussion topic and the text of users' comments on the topic; 2) Construct a dataset based on the collected data. The source topic target dataset with known stance labels is used as the training set; the target topic target dataset without stance labels is used as the test set. 3) Establish a sample stance detection model to output the predicted probability of the stance of the comment text with respect to the topic text; 4) Train the sample stance detection model using the training set until the sample stance detection model converges to obtain the stance prediction model; 5) Input the topic text and comment text to be predicted into the trained stance prediction model, and output the probability of the stance held by the comment text with respect to the topic text; In step 3, the sample stance detection model includes: a text global semantic feature extraction module, an aspect-level feature extraction module, an attribute-level feature extraction module, a multi-dimensional semantic feature fusion module, and a stance detection module; Text global semantic feature extraction module: The topic text and comment text are spliced as input, and the global semantic features of the comment text for a specific topic are output; Aspect-level feature extraction module: takes the obtained global semantic features as input and outputs multiple aspect-level features that constitute the text semantics; Attribute-level feature extraction module: takes the obtained aspect-level features as input and outputs the corresponding attribute-level features within the aspect-level features; Multi-dimensional semantic feature fusion module: It takes multiple aspect-level features obtained and concatenates them as input, and outputs fused features of global semantic feature distribution; Stance Detection Module: This module takes the obtained fusion features as input and outputs the predicted probability of the stance held by the user's comment text on a specific topic text. The aspect-level feature extraction module adopts supervised inter-group contrastive learning, where any two pairs of samples from the same group are considered positive examples, and samples from different groups are considered negative examples. The inter-group contrastive loss of each data batch in the aspect-level feature extraction module is defined as: ; A projection head is used to project aspect-level features Mapped to , used to calculate contrast loss; is the inter-group loss corresponding to the i-th aspect-level example; is an indicator function if and only if When is 1; Represents the temperature parameter of the between-group contrast loss, which is used to control the penalty strength for difficult samples in contrastive learning.
2. The sample stance detection method based on hierarchical contrastive learning according to claim 1, characterized in that: In step 2, each topic text, comment text, and stance label constitutes a training sample, and each topic text and comment text that does not overlap with the training sample topic text constitutes a test sample. All texts are organized in this way to construct the training set and test set.
3. The sample stance detection method based on hierarchical contrastive learning according to claim 1, characterized in that: The source topic target data set with known stance labels is , that is, the training set; the target data set of the purpose topic without stance label , that is, the test set; Is the source topic target There are stance labels for labeled examples in and are the number of samples of source topic target data and destination topic target data respectively; Use source topic target data set About source topic target Every sentence Train the sample stance detection model so that it can be generalized to the target topic data set On the target topic, predict Sentences The position of the comment text is then outputted as the predicted probability of the position held by the topic text.
4. The method for sample stance detection based on hierarchical contrastive learning according to claim 3, characterized in that: In the text global semantic feature extraction module, each sample is constructed into the format of "[CLS]t[SEP]r[SEP]" and input into the encoder module to obtain the hidden layer of the [CLS] tag. dimensional vector As the feature representation of sentence r for a specific target t, and the feature matrix of all words in sentence r in the last hidden layer : ; In a training batch, the feature representation of all samples can be defined as , is the size of the training batch.
5. The method for sample stance detection based on hierarchical contrastive learning according to claim 1, characterized in that: The aspect-level feature extraction module extracts global semantic features from The semantic expression features of different aspect levels are extracted, and each aspect is regarded as a feature group; the aspect-level feature extraction module is composed of K feature experts, each of which is defined as a dimensional input channels and The one-dimensional convolution of the dimensional output channel has a convolution kernel size of ; then the kth expert outputs a vector .
6. The method for sample stance detection based on hierarchical contrastive learning according to claim 1, characterized in that: In the attribute-level feature extraction module, attribute-level feature learning is formulated as a self-supervised representation learning problem; Through expert feature mapping function The sample The global semantic features are mapped to the corresponding aspect-level feature space to obtain the positive sample pairs , while the other samples in the kth group are negative samples; The intra-group contrast loss for each data batch in the attribute-level feature extraction module is defined as: ; in, is the contrast loss of the i-th aspect-level example, represents the temperature parameter within the group, is an indicator function if and only if When is 1.
7. The method for sample stance detection based on hierarchical contrastive learning according to claim 1, characterized in that: In the multi-dimensional semantic feature fusion module, the fusion feature is expressed as: ; in, For splicing operations, is the fusion feature of sample i after splicing K aspects of features, is a feedforward neural network, is the feature after multi-dimensional semantic fusion, and is a learnable parameter; Furthermore, the distribution consistency between the original global semantic features and the fused semantic features is maintained by optimizing the KL divergence between the two. ; 。 8. The method for sample stance detection based on hierarchical contrastive learning according to claim 1, characterized in that: In the stance detection module, a fully connected layer with softmax normalization is used to predict the probability distribution of stance prediction: ; in, For input example The predicted probability distribution of positions, is the dimension of the stance label, and are learnable parameters.
9. The method for sample stance detection based on hierarchical contrastive learning according to claim 1, characterized in that: In step 4, supervised stance classification loss , self-supervised inter-group contrastive learning loss , self-supervised intra-group contrastive learning loss and global semantic preservation loss To train the model; the overall goal It can be formulated as the sum of four losses: ; in, is an adjustable hyperparameter, Represents all trainable parameters in the model, represents the L2 regularization coefficient.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the sample stance detection method based on hierarchical contrastive learning according to any one of claims 1 to 9 when executing the computer program.
11. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the sample stance detection method based on hierarchical contrastive learning as claimed in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Chinese aspect level sentiment classification method based on pre-training sentiment embedding
CN114065848A
Fine-granularity sentiment analysis method supporting cross-language transfer
WO2021109671A1