CN114357164A - Emotion-reason pair extraction method, device and equipment and readable storage medium - Google Patents

Emotion-reason pair extraction method, device and equipment and readable storage medium Download PDF

Info

Publication number
CN114357164A
CN114357164A CN202111639867.8A CN202111639867A CN114357164A CN 114357164 A CN114357164 A CN 114357164A CN 202111639867 A CN202111639867 A CN 202111639867A CN 114357164 A CN114357164 A CN 114357164A
Authority
CN
China
Prior art keywords
clause
emotion
reason
representation
pair
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111639867.8A
Other languages
Chinese (zh)
Inventor
何发智
谭鸿昊
赵坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan University WHU
Original Assignee
Wuhan University WHU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan University WHU filed Critical Wuhan University WHU
Priority to CN202111639867.8A priority Critical patent/CN114357164A/en
Publication of CN114357164A publication Critical patent/CN114357164A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides an emotion-reason pair extraction method, device and equipment and a readable storage medium, wherein the emotion-reason pair extraction method comprises the following steps: after a document to be predicted of a natural language text is obtained, semantic representation of clauses in the document is obtained by utilizing a pre-trained language model, and emotion-reason pair extraction models which are trained are used for extracting and obtaining emotion-reason pairs in the document. Wherein, the emotion-reason pair extraction model comprises a plurality of layers of attention modules fused with Gaussian priors. And in the emotion-reason pair extraction model training process, calculating to obtain a joint loss value when performing clause type prediction and emotion-reason pair prediction, updating parameters of the emotion-reason pair extraction model by using the joint loss value gradient until the joint loss value converges, finishing training, and obtaining the trained emotion-reason pair extraction model. The method fully captures the relative position information among clauses in the document, and can automatically extract and obtain potential emotion-reason pairs in the document.

Description

Emotion-reason pair extraction method, device and equipment and readable storage medium
Technical Field
The invention relates to the field of natural language processing, in particular to an emotion-reason pair extraction method, device and equipment and a readable storage medium.
Background
Emotion-reason pair extraction is a task in the field of natural language processing, and aims to automatically extract emotion clauses and corresponding reason clauses from documents at the chapter level. Where a document is made up of several clauses, a clause is defined as a short sentence separated by a symbol such as a comma, as opposed to a whole sentence separated by a period. The emotion-reason pair extraction application scenarios are wide and comprise social media mining, product comment analysis and the like. In view of their importance, more and more researchers are beginning to focus on emotion-cause pair extraction.
In one document, the emotion clauses and the reason clauses corresponding to the emotion clauses contain a large amount of voice information, and the method has high research value. At present, the emotion-reason pair extraction algorithm does not fully consider the importance of the relative position between the emotion clause and the reason clause, or only uses simple position embedding to capture position information.
Disclosure of Invention
The invention mainly aims to provide an emotion-reason pair extraction method, device and equipment and a readable storage medium, and aims to solve the technical problems that in the prior art, a large number of text features need to be artificially constructed in a chapter-level emotion-reason pair extraction method, and the emotion-reason pair capturing capability is poor due to insufficient utilization of relative position information among clauses.
In a first aspect, the present invention provides an emotion-cause pair extraction method, including the steps of:
inputting a document to be predicted into a language model to obtain vectorization representation of each clause in the document to be predicted;
inputting the vectorization representation of each clause into a trained emotion-reason pair extraction model, and obtaining emotion-reason pairs in the document to be predicted based on the trained emotion-reason pair extraction model;
the step of obtaining the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model comprises the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
a cross attention module based on fusion Gaussian prior obtains a second directional quantitative representation of each clause in the emotion clause set and the reason clause set;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
and predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
Optionally, the step of obtaining the first vector quantization representation of each clause based on the first fusion gaussian prior self-attention module includes:
inputting the vectorization representation of each clause into a first Gaussian prior fusion self-attention module to obtain a first vectorization representation of each clause, wherein the formula of the first Gaussian prior fusion self-attention module is as follows:
Figure BDA0003443138190000021
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure BDA0003443138190000022
is Gaussian priors and varies1And b1Are training parameters.
Optionally, the step of predicting the type of each clause based on the first vector quantization representation of each clause includes:
inputting the first vector quantized representation of each clause into a first prediction formula, the first prediction formula being:
Figure BDA0003443138190000023
wherein the content of the first and second substances,
Figure BDA0003443138190000024
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
Optionally, the step of obtaining a second quantitative representation of each clause in the emotion clause set and the reason clause set by the cross attention module based on the fusion gaussian prior includes:
inputting the first vector quantitative representation of each clause in the emotion clause set and the reason clause set into a Gaussian prior fused cross attention module to obtain a second vector quantitative representation of each clause in the emotion clause set and the reason clause set, wherein the formula of the Gaussian prior fused cross attention module is as follows:
Figure BDA0003443138190000031
Figure BDA0003443138190000032
wherein the content of the first and second substances,
Figure BDA0003443138190000033
for the second quantized representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000034
for the first vector representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000035
for the second quantized representation of clause j in the reason clause set,
Figure BDA0003443138190000036
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure BDA0003443138190000037
And
Figure BDA0003443138190000038
the distance of (a) to (b),
Figure BDA0003443138190000039
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
Optionally, the step of obtaining a new vectorized representation of each candidate clause pair by the self-attention module based on the second fusion gaussian prior includes:
inputting the vectorization representation of each candidate clause pair into a second Gaussian-prior-fused self-attention module to obtain a new vectorization representation of each candidate clause pair, wherein the formula of the second Gaussian-prior-fused self-attention module is expressed as:
Figure BDA00034431381900000310
wherein the content of the first and second substances,
Figure BDA00034431381900000311
for a new vectorized representation of candidate clause pairs, hi,jVectorized representation of candidate clause pairs made up of sentiment clause i and reason clause jN is the number of clauses in the document to be predicted, hi,mVectorized representation of candidate clause pairs consisting of an emotion clause i and any clause in the set of reason clauses, dj,mFor the distance between the reason clause j and any clause in the set of reason clauses,
Figure BDA00034431381900000312
is Gaussian priors and varies4And b4Are training parameters.
Optionally, the step of predicting an emotion-cause pair according to the new vectorized representation of each candidate clause pair includes:
inputting the new vectorized representation of the candidate clause pair into a second prediction formula, the second prediction formula being:
Figure BDA00034431381900000313
wherein the content of the first and second substances,
Figure BDA0003443138190000041
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure BDA0003443138190000042
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
Optionally, the emotion-reason pair extraction method further includes:
inputting a training document into a language model to obtain vectorization representation of each clause in the training document;
inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining joint loss based on the emotion-reason pair extraction model;
updating training parameters of the emotion-cause pair extraction model according to the combined loss gradient;
detecting whether the joint loss converges;
if the joint loss is not converged, taking a new training document as the training document, and returning to execute the step of inputting the training document into a language model to obtain vectorization representation of each clause in the training document;
if the joint loss is converged, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training;
the step of deriving a joint loss based on the emotion-cause pair extraction model comprises:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure BDA0003443138190000043
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure BDA0003443138190000044
for the emotion clause type tag value of clause i,
Figure BDA0003443138190000045
for the emotion clause type predictor for clause i,
Figure BDA0003443138190000046
for the reason clause type tag value of clause i,
Figure BDA0003443138190000047
a reason clause type prediction value of the clause i;
obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
predicting emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs;
inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure BDA0003443138190000051
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure BDA0003443138190000052
tag value, u, of emotion-reason pair for candidate clause pairi,jA predictor of emotion-cause pairs for candidate clause pairs;
combining the first loss and the second loss results in a combined loss.
In a second aspect, the present invention also provides an emotion-reason pair extraction device, including:
the clause vectorization representation module is used for inputting the document to be predicted into the language model to obtain vectorization representation of each clause in the document to be predicted;
the emotion-reason pair prediction module is used for inputting the vectorized representation of each clause into a trained emotion-reason pair extraction model and obtaining emotion-reason pairs in the document to be predicted based on the trained emotion-reason pair extraction model;
the step of obtaining the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model comprises the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
a cross attention module based on fusion Gaussian prior obtains a second directional quantitative representation of each clause in the emotion clause set and the reason clause set;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
and predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
Optionally, the emotion-cause pair prediction module is specifically configured to:
inputting the vectorization representation of each clause into a first Gaussian prior fusion self-attention module to obtain a first vectorization representation of each clause, wherein the formula of the first Gaussian prior fusion self-attention module is as follows:
Figure BDA0003443138190000061
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure BDA0003443138190000062
is Gaussian priors and varies1And b1Are training parameters.
Optionally, the emotion-cause pair prediction module is specifically configured to:
inputting the first vector quantized representation of each clause into a first prediction formula, the first prediction formula being:
Figure BDA0003443138190000063
wherein the content of the first and second substances,
Figure BDA0003443138190000064
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
Optionally, the emotion-cause pair prediction module is specifically configured to:
inputting the first vector quantitative representation of each clause in the emotion clause set and the reason clause set into a Gaussian prior fused cross attention module to obtain a second vector quantitative representation of each clause in the emotion clause set and the reason clause set, wherein the formula of the Gaussian prior fused cross attention module is as follows:
Figure BDA0003443138190000065
Figure BDA0003443138190000066
wherein the content of the first and second substances,
Figure BDA0003443138190000067
for the second quantized representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000068
for the first vector representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000069
for the second quantized representation of clause j in the reason clause set,
Figure BDA00034431381900000610
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure BDA00034431381900000611
And
Figure BDA00034431381900000612
the distance of (a) to (b),
Figure BDA0003443138190000071
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
Optionally, the emotion-cause pair prediction module is specifically configured to:
inputting the vectorization representation of each candidate clause pair into a second Gaussian-prior-fused self-attention module to obtain a new vectorization representation of each candidate clause pair, wherein the formula of the second Gaussian-prior-fused self-attention module is expressed as:
Figure BDA0003443138190000072
wherein the content of the first and second substances,
Figure BDA0003443138190000073
for a new vectorized representation of candidate clause pairs, hi,jIs vectorized representation of candidate clause pairs formed by emotion clause i and reason clause j, n is the number of clauses in the document to be predicted, hi,mVectorized representation of candidate clause pairs consisting of an emotion clause i and any clause in the set of reason clauses, dj,mFor the distance between the reason clause j and any clause in the set of reason clauses,
Figure BDA0003443138190000074
is Gaussian priors and varies4And b4Are training parameters.
Optionally, the emotion-cause pair prediction module is specifically configured to:
inputting the new vectorized representation of the candidate clause pair into a second prediction formula, the second prediction formula being:
Figure BDA0003443138190000075
wherein the content of the first and second substances,
Figure BDA0003443138190000076
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure BDA0003443138190000077
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
Optionally, the emotion-cause pair extraction apparatus further includes a training module, specifically configured to:
inputting a training document into a language model to obtain vectorization representation of each clause in the training document;
inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining joint loss based on the emotion-reason pair extraction model;
updating training parameters of the emotion-cause pair extraction model according to the combined loss gradient;
detecting whether the joint loss converges;
if the joint loss is not converged, taking a new training document as the training document, and returning to execute the step of inputting the training document into a language model to obtain vectorization representation of each clause in the training document;
if the joint loss is converged, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training;
the step of deriving a joint loss based on the emotion-cause pair extraction model comprises:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure BDA0003443138190000081
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure BDA0003443138190000082
for the emotion clause type tag value of clause i,
Figure BDA0003443138190000083
for the emotion clause type predictor for clause i,
Figure BDA0003443138190000084
for the reason clause type tag value of clause i,
Figure BDA0003443138190000085
a reason clause type prediction value of the clause i;
obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
predicting emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs;
inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure BDA0003443138190000086
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure BDA0003443138190000087
tag value, u, of emotion-reason pair for candidate clause pairi,jA predictor of emotion-cause pairs for candidate clause pairs;
combining the first loss and the second loss results in a combined loss.
In a third aspect, the present invention further provides an emotion-reason pair extraction device, which includes a processor, a memory, and an emotion-reason pair extraction program stored on the memory and executable by the processor, wherein when the emotion-reason pair extraction program is executed by the processor, the steps of the emotion-reason pair extraction method as described above are implemented.
In a fourth aspect, the present invention further provides a readable storage medium, in which an emotion-reason pair extraction program is stored, where the emotion-reason pair extraction program, when executed by a processor, implements the steps of the emotion-reason pair extraction method as described above.
In the invention, after a document to be predicted of a natural language text is acquired, semantic representation of clauses in the document is acquired by utilizing a pre-trained language model, and emotion-reason pair extraction models which are trained are used for extracting and obtaining emotion-reason pairs in the document. Wherein, the emotion-reason pair extraction model comprises a plurality of layers of attention modules fused with Gaussian priors. And in the emotion-reason pair extraction model training process, calculating to obtain a joint loss value when performing clause type prediction and emotion-reason pair prediction, updating parameters of the emotion-reason pair extraction model by using the joint loss value gradient until the joint loss value converges, and finishing training to obtain the trained emotion-reason pair extraction model. The method fully captures the relative position information among clauses in the document, and can automatically extract and obtain potential emotion-reason pairs in the document.
Drawings
FIG. 1 is a diagram of a hardware structure of an emotion-reason pair extraction device according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating an embodiment of a sentiment-reason pair extraction method according to the present invention;
FIG. 3 is a flow chart illustrating a method for emotion-reason pair extraction according to another embodiment of the present invention;
FIG. 4 is a flow chart illustrating a method for emotion-reason pair extraction according to yet another embodiment of the present invention;
FIG. 5 is a functional block diagram of an embodiment of an emotion-reason pair extraction apparatus according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In a first aspect, an embodiment of the present invention provides an emotion-reason pair extraction device.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware structure of an emotion-reason pair extraction device according to an embodiment of the present invention. In an embodiment of the present invention, the emotion-reason pair extraction device may include a processor 1001 (e.g., a Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used for realizing connection communication among the components; the user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard); the network interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., a WI-FI interface, WI-FI interface); the memory 1005 may be a Random Access Memory (RAM) or a non-volatile memory (non-volatile memory), such as a magnetic disk memory, and the memory 1005 may optionally be a storage device independent of the processor 1001. Those skilled in the art will appreciate that the hardware configuration depicted in FIG. 1 is not intended to be limiting of the present invention, and may include more or less components than those shown, or some components in combination, or a different arrangement of components.
With continued reference to FIG. 1, the memory 1005 of FIG. 1, which is one type of computer storage medium, may include an operating system, a network communication module, a user interface module, and an emotion-cause pair extraction program. The processor 1001 may call an emotion-reason pair extraction program stored in the memory 1005, and execute an emotion-reason pair extraction method provided by an embodiment of the present invention.
In a second aspect, embodiments of the present invention provide an emotion-reason pair extraction method.
Referring to fig. 2, fig. 2 is a flowchart illustrating an embodiment of an emotion-reason pair extraction method according to the present invention.
In an embodiment of the emotion-reason pair extraction method of the present invention, the emotion-reason pair extraction method includes:
step S10, inputting the document to be predicted into a language model to obtain vectorization representation of each clause in the document to be predicted;
in this embodiment, the public data set contributed by the ECPE task presenter is selected, the chapter document and each clause are parsed from the text format file, and the text format file in the public data set is divided into a training set, a verification set and a test set by taking a chapter as a unit. Before inputting into the corresponding language model, the natural language text in the documents of the training set, the verification set and the test set is constructed into the input format required by the language model, the [ CLS ] mark is added to the sub-sentence head in the text, and the [ SEP ] mark is added to the sub-sentence tail in the text. Instantiating a BERT language model, and loading model parameters pre-trained in advance by using a large scale to obtain the BERT language model finished by pre-training. And segmenting the clauses by using a word splitter of the pre-trained BERT language model to obtain vectorization of each word of the clauses in the document to be predicted, and inputting the vectorization of each word of the clauses in the document to be predicted, which is verified to be centralized, into the pre-trained BERT language model to obtain vectorization representation of each clause in the document to be predicted.
Step S20, inputting the vectorization representation of each clause into a trained emotion-reason pair extraction model, and obtaining emotion-reason pairs in the document to be predicted based on the trained emotion-reason pair extraction model;
specifically, the obtaining of the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model is realized by the following steps:
step S201, obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
in this embodiment, referring to fig. 3, fig. 3 is a flowchart illustrating an emotion-reason pair extraction method according to another embodiment of the present invention. And inputting the vectorized representation of each clause in the to-be-predicted document obtained in the step S10 into the emotion-reason pair extraction model after training, wherein the self-attention module fusing gaussian priors with the first in the emotion-reason pair extraction model enables each clause to fuse information of other clauses in the document, and performs self-attention calculation inside the clause to obtain a first updated vectorized representation of the clause, namely a first vectorized representation of each clause.
Further, in an embodiment, the step S201 includes:
inputting the vectorization representation of each clause into a first Gaussian prior fusion self-attention module to obtain a first vectorization representation of each clause, wherein the formula of the first Gaussian prior fusion self-attention module is as follows:
Figure BDA0003443138190000111
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure BDA0003443138190000112
is Gaussian priors and varies1And b1Are training parameters.
In this embodiment, the vectorized representation of each clause is input into a first gaussian prior-fused self-attention module to obtain a first vectorized representation of each clause, where a formula of the first gaussian prior-fused self-attention module is expressed as:
Figure BDA0003443138190000113
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure BDA0003443138190000114
is Gaussian priors and varies1And b1Are training parameters.
Step S202, predicting the type of each clause based on the first vector quantization expression of each clause, and dividing to obtain an emotion clause set and a reason clause set based on a type predicted value;
in this embodiment, the first vector quantization expression obtained in step S201 is obtained, and the type of each clause is predicted based on the obtained first vector quantization expression of each clause, where the clause type includes a reason clause and an emotion clause. And based on the obtained type prediction value, dividing clauses in the document to be predicted to obtain a plurality of emotion clauses and a plurality of reason clauses, wherein the emotion clauses form an emotion clause set, and the reason clauses form a reason clause set.
Further, in an embodiment, the step of predicting the type of each clause based on the first vector quantization representation of each clause includes:
inputting the first vector quantized representation of each clause into a first prediction formula, the first prediction formula being:
Figure BDA0003443138190000121
wherein the content of the first and second substances,
Figure BDA0003443138190000122
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
In this embodiment, the type of each clause is predicted based on the first vector quantization representation of each clause, and the type prediction value may be calculated by inputting the first vector quantization representation of each clause into a first prediction formula, where the first prediction formula is:
Figure BDA0003443138190000123
wherein the content of the first and second substances,
Figure BDA0003443138190000124
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
Step S203, obtaining a second directional quantitative representation of each clause in the emotion clause set and the reason clause set based on a cross attention module fused with Gaussian priors;
in this embodiment, based on step S202, an emotion clause set and a reason clause set in a document to be predicted can be obtained, based on a cross attention module fused with gaussian priors, each emotion clause in the emotion clause set is obtained, distance information between the emotion clause and the reason clause is captured, the emotion clause in the emotion clause set is fused with clause information of each reason clause in the reason clause set, and a second-directional quantized representation of each clause in the emotion clause set is obtained. And acquiring each reason clause in the reason clause set by a Gaussian prior fusion-based cross attention module, capturing distance information between the reason clauses and the emotion clauses, fusing the clause information of each emotion clause in the emotion clause set by the reason clauses in the reason clause set, and obtaining second-direction quantitative representation of each clause in the reason clause set.
Further, in an embodiment, the step S203 includes:
inputting the first vector quantitative representation of each clause in the emotion clause set and the reason clause set into a Gaussian prior fused cross attention module to obtain a second vector quantitative representation of each clause in the emotion clause set and the reason clause set, wherein the formula of the Gaussian prior fused cross attention module is as follows:
Figure BDA0003443138190000131
Figure BDA0003443138190000132
wherein the content of the first and second substances,
Figure BDA0003443138190000133
for the second quantized representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000134
for the first vector representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000135
for the second quantized representation of clause j in the reason clause set,
Figure BDA0003443138190000136
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure BDA0003443138190000137
And
Figure BDA0003443138190000138
the distance of (a) to (b),
Figure BDA0003443138190000139
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
In this embodiment, a first vector quantization representation of each clause in the emotion clause set and the reason clause set is input to the gaussian prior fused cross attention module to obtain a second vector quantization representation of each clause in the emotion clause set and the reason clause set, where a formula of the gaussian prior fused cross attention module for the emotion clauses is expressed as:
Figure BDA00034431381900001310
the formula of the cross attention module for the fusion gaussian priors for the cause clause is expressed as:
Figure BDA00034431381900001311
Figure BDA00034431381900001312
wherein the content of the first and second substances,
Figure BDA00034431381900001313
second-direction quantized representation of clause i in set of emotion clauses,
Figure BDA00034431381900001314
For the first vector representation of clause i in the set of emotion clauses,
Figure BDA00034431381900001315
for the second quantized representation of clause j in the reason clause set,
Figure BDA00034431381900001316
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure BDA00034431381900001317
And
Figure BDA00034431381900001318
the distance of (a) to (b),
Figure BDA00034431381900001319
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
Step S204, applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second directional quantized representation of each clause in the emotion clause set and the second directional quantized representation of each clause in the reason clause set to obtain the vectorized representation of each candidate clause pair;
in this embodiment, the second updated vectorized representation of each clause in the emotion clause set and the reason clause set obtained in step S203 is obtained, a cartesian product is applied to the emotion clause set and the reason clause set, and the second vectorized representation of each clause in the emotion clause set and the second vectorized representation of each clause in the reason clause set are subjected to one-to-one concatenation operation, so as to obtain the vectorized representation of each candidate clause pair. Wherein, the calculation formula of the Cartesian product is as follows:
Figure BDA00034431381900001320
wherein h isi,jTo proceed toA vectorized representation of the candidate clause pairs resulting from a one-to-one stitching operation,
Figure BDA00034431381900001321
for a second quantized representation of each clause in the set of emotion clauses,
Figure BDA00034431381900001322
a second quantized representation of each clause in the set of clauses for the reason.
Step S205, obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
in this embodiment, the vectorization representation of each candidate clause pair obtained in step S205 is obtained, and based on the second gaussian-prior-fused self-attention module, the information of each candidate clause pair on other candidate clause pairs in the fused document is obtained, and self-attention calculation is performed on the inside of the candidate clause pair, so as to obtain a new vectorization representation of each candidate clause pair.
Further, in an embodiment, the step S205 includes:
inputting the vectorization representation of each candidate clause pair into a second Gaussian-prior-fused self-attention module to obtain a new vectorization representation of each candidate clause pair, wherein the formula of the second Gaussian-prior-fused self-attention module is expressed as:
Figure BDA0003443138190000141
wherein the content of the first and second substances,
Figure BDA0003443138190000142
for a new vectorized representation of candidate clause pairs, hi,jIs vectorized representation of candidate clause pairs formed by emotion clause i and reason clause j, n is the number of clauses in the document to be predicted, hi,mVectorized representation of candidate clause pairs consisting of an emotion clause i and any clause in the set of reason clauses, dj,mDistance between reason clause j and any clause in reason clause set,
Figure BDA0003443138190000143
Is Gaussian priors and varies4And b4Are training parameters.
In this embodiment, the vectorization representation of each candidate clause pair is input to the second gaussian prior fused self-attention module to obtain a new vectorization representation of each candidate clause pair, where the formula of the second gaussian prior fused self-attention module is expressed as:
Figure BDA0003443138190000144
Figure BDA0003443138190000145
wherein the content of the first and second substances,
Figure BDA0003443138190000146
for a new vectorized representation of candidate clause pairs, hi,jIs vectorized representation of candidate clause pairs formed by emotion clause i and reason clause j, n is the number of clauses in the document to be predicted, hi,mVectorized representation of candidate clause pairs consisting of an emotion clause i and any clause in the set of reason clauses, dj,mFor the distance between the reason clause j and any clause in the set of reason clauses,
Figure BDA0003443138190000147
is Gaussian priors and varies4And b4Are training parameters.
And step S206, predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
In this embodiment, the new vectorized representation of the candidate clause pair obtained in step S205 is obtained, and the emotion-cause pair prediction is performed according to the new vectorized representation of each candidate clause pair, where the types of the candidate clause pairs include emotion-cause pairs and non-emotion-cause pairs. And extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
Further, in an embodiment, the step of predicting emotion-cause pairs according to the new vectorized representation of each candidate clause pair includes:
inputting the new vectorized representation of the candidate clause pair into a second prediction formula, the second prediction formula being:
Figure BDA0003443138190000151
wherein the content of the first and second substances,
Figure BDA0003443138190000152
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure BDA0003443138190000153
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
In this embodiment, the new vectorized representation of the candidate clause pair is input to a second prediction formula, which is:
Figure BDA0003443138190000154
wherein the content of the first and second substances,
Figure BDA0003443138190000155
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure BDA0003443138190000156
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
Further, in an embodiment, the emotion-reason pair extraction method further includes:
step S1, inputting a training document into a language model to obtain vectorization representation of each clause in the training document;
step S2, inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining combined loss based on the emotion-reason pair extraction model;
step S3, updating the training parameters of the emotion-reason pair extraction model according to the combined loss gradient;
step S4, detecting whether the joint loss is converged;
if the joint loss does not converge, using the new training document as the training document, and returning to execute the step S1;
step S5, if the combined loss is converged, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training;
specifically, the obtaining of the joint loss based on the emotion-cause pair extraction model is realized by the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure BDA0003443138190000161
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure BDA0003443138190000162
for the emotion clause type tag value of clause i,
Figure BDA0003443138190000163
for the emotion clause type predictor for clause i,
Figure BDA0003443138190000164
for the reason clause type tag value of clause i,
Figure BDA0003443138190000165
a reason clause type prediction value of the clause i;
obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
predicting emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs;
inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure BDA0003443138190000166
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure BDA0003443138190000167
tag value, u, of emotion-reason pair for candidate clause pairi,jA predictor of emotion-cause pairs for candidate clause pairs;
combining the first loss and the second loss results in a combined loss.
In this embodiment, referring to fig. 4, fig. 4 is a flowchart illustrating an emotion-reason pair extraction method according to still another embodiment of the present invention. And inputting the training document into a language model to obtain vectorization representation of each clause in the training document. And inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining the joint loss based on the emotion-reason pair extraction model. Specifically, the obtaining of the joint loss based on the emotion-cause pair extraction model is realized by the following steps:
a first vector quantization representation of each clause is obtained based on a first fused gaussian prior self-attention module. And predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set. Inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure BDA0003443138190000171
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure BDA0003443138190000172
for the emotion clause type tag value of clause i,
Figure BDA0003443138190000173
for the emotion clause type predictor for clause i,
Figure BDA0003443138190000174
for the reason clause type tag value of clause i,
Figure BDA0003443138190000175
a reason clause type predictor for clause i.
And obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors. Applying Cartesian product to the set of emotion clauses and the set of reason clauses to represent the second vector of each clause in the set of emotion clauses and the sum of the vectorsAnd performing one-to-one splicing operation on the second vectorization representation of each clause in the reason clause set to obtain the vectorization representation of each candidate clause pair. A new vectorized representation of each candidate clause pair is obtained based on a second fused gaussian prior self-attention module. And predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs. Inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure BDA0003443138190000176
Figure BDA0003443138190000177
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure BDA0003443138190000178
tag value, u, of emotion-reason pair for candidate clause pairi,jIs the predicted value of the emotion-reason pair of the candidate clause pair. Combining the first loss and the second loss results in a combined loss.
And updating the training parameters of the emotion-reason pair extraction model according to the combined loss gradient. Wherein the training parameters include training parameters of a first self-attention module with Gaussian prior fused: is a direct change1And b1And fusing the training parameters of the cross attention module with Gaussian prior: is a direct change2And b2、∝3And b3The second Gaussian mixture prior varies from the attention module4And b4And training parameters for clause type prediction are as follows: wsAnd bsPerforming emotion-cause pair predicted training parameters: whAnd bh. And detecting whether the joint loss converges. If the joint loss is not converged, taking a new training document as the training document, and returning to execute the step of inputting the training document into the language model to obtain the trainingVectorizing representation of each clause in the document; and if the joint loss converges, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training.
In this embodiment, after a to-be-predicted document of a natural language text is acquired, a pre-trained language model is used to acquire semantic representations of clauses in the document, and an emotion-reason pair extraction model after training is used to extract and obtain emotion-reason pairs in the document. Wherein, the emotion-reason pair extraction model comprises a plurality of layers of attention modules fused with Gaussian priors. And in the emotion-reason pair extraction model training process, calculating to obtain a joint loss value when performing clause type prediction and emotion-reason pair prediction, updating parameters of the emotion-reason pair extraction model by using the joint loss value gradient until the joint loss value converges, and finishing training to obtain the trained emotion-reason pair extraction model. The method fully captures the relative position information among clauses in the document, and can automatically extract and obtain potential emotion-reason pairs in the document. Compared with the prior art, the method is an end-to-end model instead of a step-by-step model, so that the problems of error propagation and the like are avoided, and emotion-reason pairs hidden in text documents at chapter level can be extracted, so that the method is closer to actual application scenes and has higher practical value.
In a third aspect, an embodiment of the present invention further provides an emotion-reason pair extraction device.
Referring to fig. 5, a functional block diagram of an embodiment of an emotion-reason pair extraction apparatus is shown.
In this embodiment, the emotion-cause pair extraction device includes:
a clause vectorization representation module 10, configured to input a to-be-predicted document into a language model, so as to obtain vectorization representation of each clause in the to-be-predicted document;
the emotion-reason pair prediction module 20 is configured to input the vectorized representation of each clause into a trained emotion-reason pair extraction model, and obtain an emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model;
the step of obtaining the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model comprises the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
a cross attention module based on fusion Gaussian prior obtains a second directional quantitative representation of each clause in the emotion clause set and the reason clause set;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
and predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
Further, in an embodiment, the emotion-cause pair prediction module 20 is specifically configured to:
inputting the vectorization representation of each clause into a first Gaussian prior fusion self-attention module to obtain a first vectorization representation of each clause, wherein the formula of the first Gaussian prior fusion self-attention module is as follows:
Figure BDA0003443138190000191
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure BDA0003443138190000192
is Gaussian priors and varies1And b1Are training parameters.
Further, in an embodiment, the emotion-cause pair prediction module 20 is specifically configured to:
inputting the first vector quantized representation of each clause into a first prediction formula, the first prediction formula being:
Figure BDA0003443138190000193
wherein the content of the first and second substances,
Figure BDA0003443138190000194
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
Further, in an embodiment, the emotion-cause pair prediction module 20 is specifically configured to:
inputting the first vector quantitative representation of each clause in the emotion clause set and the reason clause set into a Gaussian prior fused cross attention module to obtain a second vector quantitative representation of each clause in the emotion clause set and the reason clause set, wherein the formula of the Gaussian prior fused cross attention module is as follows:
Figure BDA0003443138190000195
Figure BDA0003443138190000196
wherein the content of the first and second substances,
Figure BDA0003443138190000197
for the second quantized representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000198
for the first vector representation of clause i in the set of emotion clauses,
Figure BDA0003443138190000199
for the second quantized representation of clause j in the reason clause set,
Figure BDA00034431381900001910
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure BDA00034431381900001911
And
Figure BDA00034431381900001912
the distance of (a) to (b),
Figure BDA00034431381900001913
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
Further, in an embodiment, the emotion-cause pair prediction module 20 is specifically configured to:
inputting the vectorization representation of each candidate clause pair into a second Gaussian-prior-fused self-attention module to obtain a new vectorization representation of each candidate clause pair, wherein the formula of the second Gaussian-prior-fused self-attention module is expressed as:
Figure BDA0003443138190000201
wherein the content of the first and second substances,
Figure BDA0003443138190000202
for a new vectorized representation of candidate clause pairs, hi,jIs vectorized representation of candidate clause pairs formed by emotion clause i and reason clause j, n is the number of clauses in the document to be predicted, hi,mFor emotional clause i and reasonVectorized representation of candidate clause pairs consisting of any clause in the set of clauses, dj,mFor the distance between the reason clause j and any clause in the set of reason clauses,
Figure BDA0003443138190000203
is Gaussian priors and varies4And b4Are training parameters.
Further, in an embodiment, the emotion-cause pair prediction module 20 is specifically configured to:
inputting the new vectorized representation of the candidate clause pair into a second prediction formula, the second prediction formula being:
Figure BDA0003443138190000204
wherein the content of the first and second substances,
Figure BDA0003443138190000205
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure BDA0003443138190000206
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
Further, in an embodiment, the emotion-cause pair extraction apparatus further includes a training module, specifically configured to:
inputting a training document into a language model to obtain vectorization representation of each clause in the training document;
inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining joint loss based on the emotion-reason pair extraction model;
updating training parameters of the emotion-cause pair extraction model according to the combined loss gradient;
detecting whether the joint loss converges;
if the joint loss is not converged, taking a new training document as the training document, and returning to execute the step of inputting the training document into a language model to obtain vectorization representation of each clause in the training document;
if the joint loss is converged, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training;
the step of deriving a joint loss based on the emotion-cause pair extraction model comprises:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure BDA0003443138190000211
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure BDA0003443138190000212
for the emotion clause type tag value of clause i,
Figure BDA0003443138190000213
for the emotion clause type predictor for clause i,
Figure BDA0003443138190000214
for the reason clause type tag value of clause i,
Figure BDA0003443138190000215
a reason clause type prediction value of the clause i;
obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
predicting emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs;
inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure BDA0003443138190000216
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure BDA0003443138190000217
tag value, u, of emotion-reason pair for candidate clause pairi,jA predictor of emotion-cause pairs for candidate clause pairs;
combining the first loss and the second loss results in a combined loss.
The function implementation of each module in the emotion-reason pair extraction device corresponds to each step in the embodiment of the emotion-reason pair extraction method, and the function and implementation process are not described in detail here.
In a fourth aspect, the embodiment of the present invention further provides a readable storage medium.
The readable storage medium of the invention stores the emotion-reason pair extraction program, wherein the emotion-reason pair extraction program realizes the steps of the emotion-reason pair extraction method when being executed by a processor.
The method implemented when the emotion-reason pair extraction program is executed may refer to various embodiments of the emotion-reason pair extraction method of the present invention, and details thereof are not repeated herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for causing a terminal device to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. An emotion-cause pair extraction method, characterized in that the emotion-cause pair extraction method comprises:
inputting a document to be predicted into a language model to obtain vectorization representation of each clause in the document to be predicted;
inputting the vectorization representation of each clause into a trained emotion-reason pair extraction model, and obtaining emotion-reason pairs in the document to be predicted based on the trained emotion-reason pair extraction model;
the step of obtaining the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model comprises the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
a cross attention module based on fusion Gaussian prior obtains a second directional quantitative representation of each clause in the emotion clause set and the reason clause set;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
and predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
2. An emotion-cause pair extraction method as recited in claim 1, wherein the step of obtaining the first vector quantized representation of each clause based on the first fused Gaussian prior self-attention module comprises:
inputting the vectorization representation of each clause into a first Gaussian prior fusion self-attention module to obtain a first vectorization representation of each clause, wherein the formula of the first Gaussian prior fusion self-attention module is as follows:
Figure FDA0003443138180000021
wherein s isiIs a first vector quantized representation of clause i, ciFor vectorized representation of clause i, cjFor vectorized representation of any clause other than clause i in the document to be predicted, di,jIs ciAnd cjThe distance of (a) to (b),
Figure FDA0003443138180000022
is Gaussian priors and varies1And b1Are training parameters.
3. An emotion-cause pair extraction method as recited in claim 1, wherein said step of predicting the type of each clause based on said first vector quantized representation of each clause comprises:
inputting the first vector quantized representation of each clause into a first prediction formula, the first prediction formula being:
Figure FDA0003443138180000023
wherein the content of the first and second substances,
Figure FDA0003443138180000024
type prediction value, s, for clause iiIs a first vector quantized representation of clause i, WsAnd bsAre training parameters.
4. The emotion-cause pair extraction method of claim 1, wherein the step of obtaining a second quantized representation of each clause in the set of emotion clauses and the set of reason clauses based on a cross attention module fused with gaussian priors comprises:
inputting the first vector quantitative representation of each clause in the emotion clause set and the reason clause set into a Gaussian prior fused cross attention module to obtain a second vector quantitative representation of each clause in the emotion clause set and the reason clause set, wherein the formula of the Gaussian prior fused cross attention module is as follows:
Figure FDA0003443138180000025
Figure FDA0003443138180000026
wherein the content of the first and second substances,
Figure FDA0003443138180000027
for the second quantized representation of clause i in the set of emotion clauses,
Figure FDA0003443138180000028
for the first vector representation of clause i in the set of emotion clauses,
Figure FDA0003443138180000029
for the second quantized representation of clause j in the reason clause set,
Figure FDA00034431381800000210
first vector quantized representation of clause j in the set of reason clauses, di,j、dj,iIs composed of
Figure FDA00034431381800000211
And
Figure FDA00034431381800000212
the distance of (a) to (b),
Figure FDA00034431381800000213
is Gaussian priors and varies2And b2、∝3And b3Are training parameters.
5. An emotion-cause pair extraction method as recited in claim 1, wherein said step of deriving a new vectorized representation of each candidate clause pair based on a second fused Gaussian prior self-attention model comprises:
inputting the vectorization representation of each candidate clause pair into a second Gaussian-prior-fused self-attention module to obtain a new vectorization representation of each candidate clause pair, wherein the formula of the second Gaussian-prior-fused self-attention module is expressed as:
Figure FDA0003443138180000031
wherein the content of the first and second substances,
Figure FDA0003443138180000032
for a new vectorized representation of candidate clause pairs, hi,jIs vectorized representation of candidate clause pairs formed by emotion clause i and reason clause j, n is the number of clauses in the document to be predicted, hi,mVectorized representation of candidate clause pairs consisting of an emotion clause i and any clause in the set of reason clauses, dj,mFor the distance between the reason clause j and any clause in the set of reason clauses,
Figure FDA0003443138180000033
is Gaussian priors and varies4And b4Are training parameters.
6. The emotion-cause pair extraction method of claim 1, wherein the step of performing emotion-cause pair prediction from the new vectorized representation of each candidate clause pair comprises:
inputting the new vectorized representation of the candidate clause pair into a second prediction formula, the second prediction formula being:
Figure FDA0003443138180000034
wherein the content of the first and second substances,
Figure FDA0003443138180000035
the predictor of the new vectorized representation for the candidate clause pair consisting of clause i and clause j,
Figure FDA0003443138180000036
for a new vectorized representation of candidate clause pairs, WhAnd bhAre training parameters.
7. The emotion-cause pair extraction method as recited in claim 1, wherein the emotion-cause pair extraction method further comprises:
inputting a training document into a language model to obtain vectorization representation of each clause in the training document;
inputting the vectorization representation of each clause into an emotion-reason pair extraction model, and obtaining joint loss based on the emotion-reason pair extraction model;
updating training parameters of the emotion-cause pair extraction model according to the combined loss gradient;
detecting whether the joint loss converges;
if the joint loss is not converged, taking a new training document as the training document, and returning to execute the step of inputting the training document into a language model to obtain vectorization representation of each clause in the training document;
if the joint loss is converged, taking the latest emotion-reason pair extraction model as the emotion-reason pair extraction model after training;
the step of deriving a joint loss based on the emotion-cause pair extraction model comprises:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
inputting the type predicted value and the type label value of each clause into a first loss function formula to obtain a first loss, wherein the first loss function formula is as follows:
Figure FDA0003443138180000041
wherein L isclauseFor the first loss, n is the number of clauses in the training document,
Figure FDA0003443138180000042
for the emotion clause type tag value of clause i,
Figure FDA0003443138180000043
for the emotion clause type predictor for clause i,
Figure FDA0003443138180000044
for the reason clause type tag value of clause i,
Figure FDA0003443138180000045
a reason clause type prediction value of the clause i;
obtaining a second-direction quantitative representation of each clause in the updated emotion clause set and reason clause set based on a cross attention module fused with Gaussian priors;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
predicting emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the training document based on the predicted values of the emotion-reason pairs;
inputting the predicted value of the emotion-reason pair and the tag value of the emotion-reason pair of each candidate clause pair into a second loss function formula to obtain a second loss, wherein the second loss function formula is as follows:
Figure FDA0003443138180000046
wherein L ispairFor the second loss, n is the number of clauses in the training document,
Figure FDA0003443138180000047
tag value, u, of emotion-reason pair for candidate clause pairi,jA predictor of emotion-cause pairs for candidate clause pairs;
combining the first loss and the second loss results in a combined loss.
8. An emotion-cause pair extraction apparatus, characterized in that the emotion-cause pair extraction apparatus comprises:
the clause vectorization representation module is used for inputting the document to be predicted into the language model to obtain vectorization representation of each clause in the document to be predicted;
the emotion-reason pair prediction module is used for inputting the vectorized representation of each clause into a trained emotion-reason pair extraction model and obtaining emotion-reason pairs in the document to be predicted based on the trained emotion-reason pair extraction model;
the step of obtaining the emotion-reason pair in the document to be predicted based on the trained emotion-reason pair extraction model comprises the following steps:
obtaining a first vector quantization representation of each clause based on a first fusion Gaussian prior self-attention module;
predicting the type of each clause based on the first vector quantization expression of each clause, and dividing based on a type predicted value to obtain an emotion clause set and a reason clause set;
a cross attention module based on fusion Gaussian prior obtains a second directional quantitative representation of each clause in the emotion clause set and the reason clause set;
applying Cartesian product to the emotion clause set and the reason clause set, and performing one-to-one splicing operation on the second vector quantitative representation of each clause in the emotion clause set and the second vector quantitative representation of each clause in the reason clause set to obtain the vector representation of each candidate clause pair;
obtaining a new vectorization representation of each candidate clause pair based on a second fusion Gaussian prior self-attention module;
and predicting the emotion-reason pairs according to the new vectorization representation of each candidate clause pair, and extracting and obtaining the emotion-reason pairs in the document to be predicted based on the predicted values of the emotion-reason pairs.
9. An emotion-cause pair extraction apparatus comprising a processor, a memory, and an emotion-cause pair extraction program stored on the memory and executable by the processor, wherein the emotion-cause pair extraction program when executed by the processor implements the steps of the emotion-cause pair extraction method according to any one of claims 1 to 7.
10. A readable storage medium, characterized in that the readable storage medium has stored thereon an emotion-reason pair extraction program, wherein the emotion-reason pair extraction program, when executed by a processor, implements the steps of the emotion-reason pair extraction method according to any one of claims 1 to 7.
CN202111639867.8A 2021-12-29 2021-12-29 Emotion-reason pair extraction method, device and equipment and readable storage medium Pending CN114357164A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111639867.8A CN114357164A (en) 2021-12-29 2021-12-29 Emotion-reason pair extraction method, device and equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111639867.8A CN114357164A (en) 2021-12-29 2021-12-29 Emotion-reason pair extraction method, device and equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN114357164A true CN114357164A (en) 2022-04-15

Family

ID=81103624

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111639867.8A Pending CN114357164A (en) 2021-12-29 2021-12-29 Emotion-reason pair extraction method, device and equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN114357164A (en)

Similar Documents

Publication Publication Date Title
CN112685565B (en) Text classification method based on multi-mode information fusion and related equipment thereof
US10657969B2 (en) Identity verification method and apparatus based on voiceprint
CN113011186B (en) Named entity recognition method, named entity recognition device, named entity recognition equipment and computer readable storage medium
EP3872652B1 (en) Method and apparatus for processing video, electronic device, medium and product
CN111223476B (en) Method and device for extracting voice feature vector, computer equipment and storage medium
CN111581966A (en) Context feature fusion aspect level emotion classification method and device
CN114330966A (en) Risk prediction method, device, equipment and readable storage medium
CN111159358A (en) Multi-intention recognition training and using method and device
CN113836303A (en) Text type identification method and device, computer equipment and medium
CN114004231A (en) Chinese special word extraction method, system, electronic equipment and storage medium
CN115438149A (en) End-to-end model training method and device, computer equipment and storage medium
CN113723077A (en) Sentence vector generation method and device based on bidirectional characterization model and computer equipment
CN111368066A (en) Method, device and computer readable storage medium for acquiring dialogue abstract
CN113722436A (en) Text information extraction method and device, computer equipment and storage medium
US11036996B2 (en) Method and apparatus for determining (raw) video materials for news
CN112380861A (en) Model training method and device and intention identification method and device
CN111241843B (en) Semantic relation inference system and method based on composite neural network
CN114528851B (en) Reply sentence determination method, reply sentence determination device, electronic equipment and storage medium
CN113408287B (en) Entity identification method and device, electronic equipment and storage medium
CN116127060A (en) Text classification method and system based on prompt words
CN114357164A (en) Emotion-reason pair extraction method, device and equipment and readable storage medium
CN113268588A (en) Text abstract extraction method, device, equipment, storage medium and program product
CN112199954A (en) Disease entity matching method and device based on voice semantics and computer equipment
CN116522905B (en) Text error correction method, apparatus, device, readable storage medium, and program product
CN116975298B (en) NLP-based modernized society governance scheduling system and method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination