Method, apparatus and electronic device for generating a causal relationship

By acquiring sentence information matrix and position matrix, and using causal relationship extraction model to automatically generate causal relationships, the problems of high cost and low applicability of causal relationship generation in existing technologies are solved, and automated and low-cost causal relationship generation is achieved.

CN113821643BActive Publication Date: 2025-12-19JINGDONG TECH HLDG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110237073.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-03
Publication Date
2025-12-19
Estimated Expiration
2041-03-03

AI Technical Summary

Technical Problem

Existing methods for generating causal relationships are costly, have limited applicability, and require manual alignment of causal relationships, making automated generation impossible.

Method used

By acquiring the sentence information matrix, identifying causal conjunctions and generating their position matrix, and using a trained causal relationship extraction model to automatically generate the cause and effect subject words of the causal conjunctions, the graph neural network and multi-head attention mechanism model are used for processing.

Benefits of technology

It enables the automatic generation of causal relationships, has strong applicability, automatically aligns causal relationships, and reduces manual costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113821643B_ABST
    Figure CN113821643B_ABST
Patent Text Reader

Abstract

The application provides a cause-effect relationship generation method, device and electronic equipment. The cause-effect relationship generation method comprises the following steps: obtaining a sentence information matrix corresponding to a to-be-processed sentence; obtaining a cause-effect conjunction in the to-be-processed sentence according to the sentence information matrix; generating a position matrix corresponding to the cause-effect conjunction according to the position of the cause-effect conjunction in the to-be-processed sentence; and inputting the position matrix corresponding to the cause-effect conjunction and the sentence information matrix into a trained cause-effect relationship extraction model to obtain a reason subject word and a result subject word corresponding to the cause-effect conjunction. Thus, the reason subject word and the result subject word corresponding to the cause-effect conjunction can be automatically generated by using the cause-effect relationship extraction model. Compared with the cause-effect relationship generation in the related art, the cause-effect relationship generation method has the advantages of low cost, high applicability, automatic cause-effect relationship alignment and low labor cost.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, in particular to a method and device for generating causal relationship, an electronic device and a storage medium. BACKGROUND

[0002] Causal relationship is the relationship between cause and effect, and is an important relationship type, which is crucial in event prediction, scenario generation, question answering and text entailment. In related technologies, causal relationship is usually generated through randomized controlled trials, observation data, text data and other methods, which has the disadvantages of high cost, low applicability, inability to automatically align causal relationship, and the need for manual alignment of causal relationship. SUMMARY

[0003] The present application aims to at least partially solve one of the technical problems of high cost, low applicability, inability to automatically align causal relationship, and the need for manual alignment of causal relationship in related technologies.

[0004] To this end, the first aspect of the present application provides a method for generating causal relationship, obtaining a sentence information matrix corresponding to a to-be-processed sentence, obtaining a causal conjunction in the to-be-processed sentence according to the sentence information matrix, generating a position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, inputting the position matrix corresponding to the causal conjunction and the sentence information matrix into a trained causal relationship extraction model to obtain a cause subject word and a result subject word corresponding to the causal conjunction. Thus, the cause subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causal relationship extraction model, which can realize automatic generation of causal relationship, has strong applicability, and can automatically align causal relationship with low labor cost, compared with the disadvantages of high cost, low applicability, and the need for manual alignment of causal relationship in related technologies.

[0005] The second aspect of the present application provides a device for generating causal relationship.

[0006] The third aspect of the present application provides an electronic device.

[0007] The fourth aspect of the present application provides a computer-readable storage medium.

[0008] The first aspect of the present application provides a method for generating causal relationship, comprising: obtaining a sentence information matrix corresponding to a to-be-processed sentence; obtaining a causal conjunction in the to-be-processed sentence according to the sentence information matrix; generating a position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence; inputting the position matrix corresponding to the causal conjunction and the sentence information matrix into a trained causal relationship extraction model to obtain a cause subject word and a result subject word corresponding to the causal conjunction.

[0009] According to the method for generating a cause-effect relationship provided in the embodiments of the present application, a sentence information matrix corresponding to a to-be-processed sentence is obtained, a cause-effect conjunction in the to-be-processed sentence is obtained according to the sentence information matrix, a position matrix corresponding to the cause-effect conjunction is generated according to the position of the cause-effect conjunction in the to-be-processed sentence, the position matrix corresponding to the cause-effect conjunction and the sentence information matrix are input into a trained cause-effect relationship extraction model, and a reason subject word and a result subject word corresponding to the cause-effect conjunction are obtained. In this way, the reason subject word and the result subject word corresponding to the cause-effect conjunction can be automatically generated by the cause-effect relationship extraction model, and compared with the high cost, low applicability and the need for manual alignment of the cause-effect relationship in the related art, the automatic generation of the cause-effect relationship can be realized, the applicability is strong, and the cause-effect relationship can be automatically aligned, and the labor cost is low.

[0010] In addition, the method for generating a cause-effect relationship according to the above embodiments of the present application can have the following additional technical features:

[0011] In an embodiment of the present application, the obtaining of the sentence information matrix corresponding to the to-be-processed sentence comprises: obtaining a sentence matrix in word units corresponding to the to-be-processed sentence; and inputting the sentence matrix into a graph neural network to obtain the sentence information matrix.

[0012] In an embodiment of the present application, the obtaining of the sentence matrix in word units corresponding to the to-be-processed sentence comprises: training last three layers of network parameters in a Roberta network according to a plurality of first sample sentences of a cause-effect sentence type to obtain trained network parameters; determining the trained network parameters as parameters of a to-be-trained pre-training model to obtain a trained pre-training model; and inputting the to-be-processed sentence into the trained pre-training model to obtain the sentence matrix.

[0013] In an embodiment of the present application, further comprising: obtaining a syntactic dependency tree in word units; and converting the syntactic dependency tree into a Laplacian matrix to obtain the graph neural network.

[0014] In an embodiment of the present application, the obtaining of the cause-effect conjunction in the to-be-processed sentence according to the sentence information matrix comprises: inputting the sentence information matrix into an attention mechanism network matrix to obtain the cause-effect conjunction.

[0015] In an embodiment of the present application, the cause-effect relationship extraction model is a multi-head attention mechanism model.

[0016] In an embodiment of the present application, the method further comprises: obtaining a sample cause subject word and a corresponding sample result subject word of a second sample sentence manually labeled; obtaining a sample sentence information matrix corresponding to the second sample sentence; obtaining a sample causal conjunction word in the second sample sentence according to the sample sentence information matrix; generating a position matrix corresponding to the sample causal conjunction word according to a position of the sample causal conjunction word in the second sample sentence; and training the causal relation extraction model to be trained according to the position matrix corresponding to the sample causal conjunction word, the sample sentence information matrix, the sample cause subject word, and the sample result subject word, to obtain the trained causal relation extraction model.

[0017] An embodiment of the second aspect of the present application provides a causal relation generation apparatus, comprising: a first obtaining module configured to obtain a sentence information matrix corresponding to a to-be-processed sentence; a second obtaining module configured to obtain a causal conjunction word in the to-be-processed sentence according to the sentence information matrix; a generating module configured to generate a position matrix corresponding to the causal conjunction word according to a position of the causal conjunction word in the to-be-processed sentence; and an inputting module configured to input the position matrix corresponding to the causal conjunction word and the sentence information matrix into a trained causal relation extraction model to obtain a cause subject word and a result subject word corresponding to the causal conjunction word.

[0018] The causal relation generation apparatus of the embodiments of the present application obtains a sentence information matrix corresponding to a to-be-processed sentence, obtains a causal conjunction word in the to-be-processed sentence according to the sentence information matrix, generates a position matrix corresponding to the causal conjunction word according to a position of the causal conjunction word in the to-be-processed sentence, and inputs the position matrix corresponding to the causal conjunction word and the sentence information matrix into a trained causal relation extraction model to obtain a cause subject word and a result subject word corresponding to the causal conjunction word. Thus, the cause subject word and the result subject word corresponding to the causal conjunction word can be automatically generated by the causal relation extraction model, and the disadvantages of high cost, low applicability, and the need for manual alignment of causal relations in the generation of causal relations in the related art can be overcome, the automatic generation of causal relations can be achieved, the applicability is strong, and the causal relations can be automatically aligned, and the labor cost is low.

[0019] In addition, the causal relation generation apparatus according to the above-mentioned embodiments of the present application can have the following additional technical features:

[0020] In an embodiment of the present application, the first obtaining module is specifically configured to: obtain a sentence matrix in units of words corresponding to the to-be-processed sentence; and input the sentence matrix into a graph neural network to obtain the sentence information matrix.

[0021] In an embodiment of the present application, the first obtaining module is specifically configured to: train last three layers of network parameters in the Roberta network according to a plurality of first sample sentences of the cause-effect sentence pattern to obtain trained network parameters; determine the trained network parameters as parameters of a pre-trained model to be trained to obtain a trained pre-trained model; and input the sentence to be processed into the trained pre-trained model to obtain the sentence matrix.

[0022] In an embodiment of the present application, the method further includes: a third obtaining module configured to: obtain a syntax dependency tree in word units; and convert the syntax dependency tree into a Laplacian matrix to obtain the graph neural network.

[0023] In an embodiment of the present application, the second obtaining module is specifically configured to: input the sentence information matrix into an attention mechanism network matrix to obtain the cause-effect conjunction.

[0024] In an embodiment of the present application, the cause-effect relationship extraction model is a multi-head attention mechanism model.

[0025] In an embodiment of the present application, the method further includes: a fourth obtaining module configured to: obtain a sample cause subject word and a corresponding sample result subject word of a second sample sentence that are artificially labeled; obtain a sample sentence information matrix corresponding to the second sample sentence; obtain a sample cause-effect conjunction in the second sample sentence according to the sample sentence information matrix; generate a position matrix corresponding to the sample cause-effect conjunction according to a position of the sample cause-effect conjunction in the second sample sentence; and train a cause-effect relationship extraction model to be trained according to the position matrix corresponding to the sample cause-effect conjunction, the sample sentence information matrix, the sample cause subject word and the sample result subject word to obtain the trained cause-effect relationship extraction model.

[0026] An embodiment of the third aspect of the present application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and when the processor executes the program, the method for generating a cause-effect relationship is implemented as described in the first aspect of the embodiments.

[0027] The electronic device of the embodiment of the application obtains the sentence information matrix corresponding to the to-be-processed sentence by executing the computer program stored on the memory by the processor, obtains the causal conjunction in the to-be-processed sentence according to the sentence information matrix, generates the position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, inputs the position matrix corresponding to the causal conjunction and the sentence information matrix into the trained causal relation extraction model, and obtains the cause subject word and the result subject word corresponding to the causal conjunction. Thus, the cause subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causal relation extraction model, and the automatic generation of the causal relation can be realized, which has strong applicability and low labor cost.

[0028] The fourth aspect embodiment of the application provides a computer readable storage medium, which stores a computer program, and the program is executed by a processor to realize the method for generating a causal relation according to the first aspect embodiment.

[0029] The computer readable storage medium of the embodiment of the application stores a computer program and is executed by a processor to obtain the sentence information matrix corresponding to the to-be-processed sentence, obtain the causal conjunction in the to-be-processed sentence according to the sentence information matrix, generate the position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, input the position matrix corresponding to the causal conjunction and the sentence information matrix into the trained causal relation extraction model, and obtain the cause subject word and the result subject word corresponding to the causal conjunction. Thus, the cause subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causal relation extraction model, and the automatic generation of the causal relation can be realized, which has strong applicability and low labor cost.

[0030] Additional aspects and advantages of the application will be set forth in part in the description which follows, and in part will become apparent to those skilled in the art upon examination of the following and / or by practice of the application. BRIEF DESCRIPTION OF DRAWINGS

[0031] The above and / or additional aspects and advantages of the application will become apparent and be well understood from a review of the following description, taken in conjunction with the drawings, wherein:

[0032] Figure 1 A flowchart of a method for generating a causal relation according to an embodiment of the application;

[0033] Figure 2 A flowchart of obtaining a sentence information matrix corresponding to a to-be-processed sentence in a method for generating a causal relation according to an embodiment of the application;

[0034] Figure 3 A schematic diagram of a syntax dependency tree in word units in a cause-effect relationship generation method according to an embodiment of the present application;

[0035] Figure 4 A schematic diagram of a syntax dependency tree in word units in a cause-effect relationship generation method according to another embodiment of the present application;

[0036] Figure 5 A schematic diagram of a cause-effect relationship generation method according to an embodiment of the present application;

[0037] Figure 6 A structural schematic diagram of a cause-effect relationship generation apparatus according to an embodiment of the present application;

[0038] Figure 7 A structural schematic diagram of a cause-effect relationship generation apparatus according to another embodiment of the present application; and

[0039] Figure 8 A structural schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0040] Embodiments of the present application are described in detail below with reference to the accompanying drawings, in which the same or similar components or components having the same or similar functions are denoted throughout by the same or similar reference numerals and repeated explanations are omitted. The embodiments described below by reference to the accompanying drawings are exemplary and are intended to explain the present application, and cannot be understood as limiting the present application.

[0041] A cause-effect relationship generation method, apparatus, electronic device and storage medium of an embodiment of the present application are described below with reference to the accompanying drawings.

[0042] Figure 1 A flowchart of a cause-effect relationship generation method according to an embodiment of the present application.

[0043] As shown in Figure 1 The cause-effect relationship generation method of an embodiment of the present application includes:

[0044] S101, obtaining a sentence information matrix corresponding to a to-be-processed sentence.

[0045] It should be noted that the execution subject of the causality generation method in the embodiments of the present application can be a causality generation apparatus, and the causality generation apparatus in the embodiments of the present application can be configured in any electronic device, so that the electronic device can execute the causality generation method in the embodiments of the present application. The electronic device can be a personal computer (PC), a cloud device, a mobile device, and the like. The mobile device can be a mobile phone, a tablet computer, a personal digital assistant, a wearable device, a vehicle-mounted device, and the like, which has various operating systems, touch screens, and / or display screens.

[0046] In the embodiments of the present application, a sentence information matrix corresponding to the to-be-processed sentence can be obtained. The sentence information matrix refers to a matrix that can represent the semantic information of the to-be-processed sentence. It can be understood that different to-be-processed sentences can correspond to different sentence information matrices.

[0047] It should be noted that the language and type of the to-be-processed sentence are not limited in the embodiments of the present application. For example, the to-be-processed sentence can be Chinese.

[0048] In S102, a causal conjunction in the to-be-processed sentence is obtained according to the sentence information matrix.

[0049] In the embodiments of the present application, the causal conjunction in the to-be-processed sentence can be obtained according to the sentence information matrix. It can be understood that the sentence information matrix can represent the semantic information of the to-be-processed sentence, and the semantic information includes the causal conjunction, so that the causal conjunction in the to-be-processed sentence can be obtained according to the sentence information matrix.

[0050] It can be understood that different to-be-processed sentences can correspond to different causal conjunctions, and one to-be-processed sentence can correspond to one or more causal conjunctions. For example, the to-be-processed sentence is "currency collapse leads to gold rising", and the causal conjunction corresponding to the to-be-processed sentence is "leads to". Alternatively, the to-be-processed sentence is "currency collapse triggers stock market rise", and the causal conjunction corresponding to the to-be-processed sentence is "triggers". Alternatively, the to-be-processed sentence is "currency collapse leads to gold rising, and triggers stock market rise", and the causal conjunctions corresponding to the to-be-processed sentence are "leads to" and "triggers".

[0051] Optionally, obtaining the causal conjunction in the to-be-processed sentence according to the sentence information matrix can include inputting the sentence information matrix into an attention mechanism network matrix to obtain the causal conjunction. The attention mechanism network matrix can be set according to actual conditions.

[0052] Optionally, the sentence information matrix is input into an attention mechanism network matrix, and the attention mechanism network matrix can obtain a causal conjunction word by using a sequence tagging (SL) algorithm. The sequence tagging algorithm can be set according to actual conditions, for example, can be set as a deep learning (DL) algorithm.

[0053] In S103, a position matrix corresponding to the causal conjunction word is generated according to the position of the causal conjunction word in the sentence to be processed.

[0054] In the embodiments of the present application, the position matrix corresponding to the causal conjunction word can be generated according to the position of the causal conjunction word in the sentence to be processed.

[0055] It can be understood that the position of the causal conjunction word in different sentences to be processed can be different, and the generated position matrix corresponding to the causal conjunction word can be different.

[0056] For example, the sentence to be processed is "currency crash leads to gold rise", and the causal conjunction word corresponding to the sentence to be processed is "leads". The position of the causal conjunction word "leads" in the sentence to be processed can be as shown in Table 1.

[0057] Table 1 Position of causal conjunction word "leads" in sentence to be processed

[0058] Word Currency Crash Caused Gold Up Position Figure 2 Figure 3 Figure 4 Figure 5 Figures 1 to 5 -4 -3 -2 -1 0 0 1 2 3 4

[0059] As shown in Table 1, the position of each word in the sentence to be processed "currency crash leads to gold rise" can be obtained, and the positions of "leads" and "leads" corresponding to the causal conjunction word "leads" in the sentence to be processed can be set to 0. The positions of other words in the sentence to be processed can be obtained according to the positional relationship between the other words and "leads" and "leads" by taking the positions of "leads" and "leads" as references. For example, "yellow" is the first word to the right of "leads", so the position of "yellow" in the sentence to be processed can be obtained as 1. "Gold" is the second word to the right of "leads", so the position of "gold" in the sentence to be processed can be obtained as 2. The method for obtaining the positions of other words in the sentence to be processed is not described here.

[0060] Optionally, the position matrix corresponding to the causal conjunction word can be generated according to the position of the causal conjunction word in the sentence to be processed, which can include inputting the position of the causal conjunction word in the sentence to be processed into a causal conjunction word position parameter matrix to generate the position matrix corresponding to the causal conjunction word. The causal conjunction word position parameter matrix can be set according to actual conditions.

[0061] In S104, the position matrix corresponding to the causal conjunction word and the sentence information matrix are input into the trained causal relationship extraction model to obtain the cause subject word and the result subject word corresponding to the causal conjunction word.

[0062] Causality is the relationship between cause and effect, which is an important relationship type and is crucial in event prediction, scenario generation, question answering, and text entailment. In the related art, causality is often generated through randomized controlled experiments, observational data, and text data, which has the disadvantages of high cost, low applicability, inability to automatically align causality, and the need for manual alignment of causality.

[0063] In the embodiments of the present application, the position matrix and the sentence information matrix corresponding to the causal conjunction can be input into the trained causal relationship extraction model, and the position matrix and the sentence information matrix corresponding to the causal conjunction can be processed by the causal relationship extraction model to obtain the cause subject word and the result subject word corresponding to the causal conjunction. It can be understood that the cause subject word, the result subject word, and the causal conjunction form a causal relationship. That is, in the present application, the cause subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causal relationship extraction model, the automatic generation of the causal relationship can be realized, the applicability is strong, and the causal relationship can be automatically aligned, which has low labor cost.

[0064] It can be understood that different causal conjunctions can correspond to different cause subject words and result subject words. For example, the to-be-processed sentence is "currency collapse leads to gold price rise, and causes stock price rise", the causal conjunction corresponding to the to-be-processed sentence is "leads to" and "causes", wherein the cause subject word corresponding to the causal conjunction "leads to" is "currency collapse", and the result subject word corresponding to the causal conjunction "leads to" is "gold price rise", the cause subject word corresponding to the causal conjunction "causes" is "currency collapse", and the result subject word corresponding to the causal conjunction "causes" is "stock price rise".

[0065] Optionally, the causal relationship extraction model can be set according to actual conditions, for example, it can be a deep learning model, such as a Multi-headed Attention mechanism model. It can be understood that when the causal relationship extraction model is a deep learning model, the generalization ability of the model is stronger.

[0066] Optionally, inputting the position matrix and the sentence information matrix corresponding to the causal conjunction into the trained causal relationship extraction model to obtain the cause subject word and the result subject word corresponding to the causal conjunction can include splicing the position matrix and the sentence information matrix corresponding to the causal conjunction to obtain a spliced target matrix, inputting the target matrix into the causal relationship extraction model, and the causal relationship extraction model can use a sequence labeling algorithm to obtain the cause subject word and the result subject word corresponding to the causal conjunction. Wherein, splicing the position matrix and the sentence information matrix corresponding to the causal conjunction can include horizontally splicing or vertically splicing the position matrix and the sentence information matrix corresponding to the causal conjunction.

[0067] In summary, according to the method for generating a cause-effect relationship provided in the embodiments of the present application, a sentence information matrix corresponding to a to-be-processed sentence is obtained, a cause-effect conjunction in the to-be-processed sentence is obtained according to the sentence information matrix, a position matrix corresponding to the cause-effect conjunction is generated according to the position of the cause-effect conjunction in the to-be-processed sentence, the position matrix corresponding to the cause-effect conjunction and the sentence information matrix are input into a trained cause-effect relationship extraction model, and a reason subject word and a result subject word corresponding to the cause-effect conjunction are obtained. In this way, the reason subject word and the result subject word corresponding to the cause-effect conjunction can be automatically generated by the cause-effect relationship extraction model, and compared with the high cost, low applicability and the need for manual alignment of the cause-effect relationship in the related art, the cause-effect relationship can be automatically generated, has strong applicability, and can automatically align the cause-effect relationship, and has low labor cost.

[0068] In any of the above embodiments, as shown in Figures 1 to 5 The step S101 of obtaining the sentence information matrix corresponding to the to-be-processed sentence can include:

[0069] S201, obtaining a sentence matrix corresponding to the to-be-processed sentence in units of words.

[0070] In the embodiments of the present application, the sentence matrix corresponding to the to-be-processed sentence in units of words can be obtained. It can be understood that the to-be-processed sentence can be composed of multiple words, each word can correspond to a vector representation, and the sentence matrix can be generated from the vector representations of all words corresponding to the to-be-processed sentence.

[0071] Optionally, obtaining the sentence matrix corresponding to the to-be-processed sentence in units of words can include training last three layers of network parameters in a Roberta network according to a plurality of first sample sentences of a cause-effect sentence type, obtaining trained network parameters, determining the trained network parameters as parameters of a pre-trained (Pretrain) model to be trained, obtaining a trained pre-trained model, inputting the to-be-processed sentence into the trained pre-trained model, and obtaining the sentence matrix. In this way, in this method, the last three layers of network parameters in the Roberta network can be trained according to the plurality of first sample sentences of the cause-effect sentence type to determine the parameters of the pre-trained model, and the sentence matrix corresponding to the to-be-processed sentence can be obtained through the pre-trained model.

[0072] The Roberta network can be a multi-layer network structure, for example, a 12-layer network structure.

[0073] The last three layers of the Roberta network are trained according to a plurality of first sample sentences of a cause-effect sentence pattern, and trained network parameters are obtained. The training of the Roberta network can be stopped when the accuracy of the Roberta network reaches a preset accuracy threshold or the number of iterations of the Roberta network reaches a preset number threshold, and the last three layers of the Roberta network obtained by the last training are taken as the trained network parameters.

[0074] S202, input the sentence matrix into the graph neural network to obtain a sentence information matrix.

[0075] In the embodiment of the application, the sentence matrix can be input into a graph neural network (GNN), and the graph neural network is used to process the sentence matrix to obtain a sentence information matrix.

[0076] Optionally, the graph neural network can be set according to actual conditions, for example, it can be set as a graph convolution network (GCN).

[0077] Optionally, the graph neural network can be obtained by obtaining a dependency tree in word units, converting the dependency tree into a Laplacian matrix, and obtaining the graph neural network. The dependency tree refers to a tree graph representing a syntactic dependency relationship, and the Laplacian matrix L=D-A, where D is a degree matrix of the graph, and A is an adjacency matrix of the graph.

[0078] It can be understood that different sentences to be processed can correspond to different dependency trees. For example, when the sentence to be processed is "Deng Jiaxian is a famous physicist", the corresponding dependency tree in word units is as shown in Figure 6 .

[0079] Optionally, converting the dependency tree into a Laplacian matrix can include converting the dependency tree into an adjacency matrix and a degree matrix, and then obtaining the Laplacian matrix according to the adjacency matrix and the degree matrix.

[0080] For example, if the dependency tree is as shown in Figure 6 .

[0081] The corresponding adjacency matrix is

[0082] The corresponding degree matrix is

[0083] The corresponding Laplacian matrix is

[0084] Therefore, the method can obtain a sentence matrix corresponding to the to-be-processed sentence in word units, input the sentence matrix into the graph neural network, and obtain the sentence information matrix, so as to realize acquisition of the sentence information matrix.

[0085] On the basis of any of the above embodiments, the obtaining of the trained causal relation extraction model in step S104 can include obtaining a sample cause subject word and a corresponding sample result subject word in the second sample sentence that are manually annotated, obtaining a sample sentence information matrix corresponding to the second sample sentence, obtaining a sample causal conjunction word in the second sample sentence according to the sample sentence information matrix, generating a position matrix corresponding to the sample causal conjunction word according to the position of the sample causal conjunction word in the second sample sentence, and training the causal relation extraction model to be trained according to the position matrix corresponding to the sample causal conjunction word, the sample sentence information matrix, the sample cause subject word, and the sample result subject word, to obtain the trained causal relation extraction model.

[0086] It should be noted that the related content of obtaining a sample sentence information matrix corresponding to the second sample sentence, obtaining a sample causal conjunction word in the second sample sentence according to the sample sentence information matrix, and generating a position matrix corresponding to the sample causal conjunction word according to the position of the sample causal conjunction word in the second sample sentence can be referred to the above embodiments, which will not be described here.

[0087] Optionally, the training of the causal relation extraction model to be trained according to the position matrix corresponding to the sample causal conjunction word, the sample sentence information matrix, the sample cause subject word, and the sample result subject word to obtain the trained causal relation extraction model can include inputting the position matrix corresponding to the sample causal conjunction word and the sample sentence information matrix into the causal relation extraction model to be trained to obtain a first cause subject word and a first result subject word, adjusting model parameters of the causal relation extraction model to be trained according to a first error between the first cause subject word and the sample cause subject word and a second error between the first result subject word and the sample result subject word, until the accuracy of the causal relation extraction model reaches a preset accuracy threshold or the number of iterations of the causal relation extraction model reaches a preset number threshold, stopping the training of the causal relation extraction model, and taking the causal relation extraction model obtained through the last training as the trained causal relation extraction model.

[0088] Therefore, the method can train the causal relation extraction model to be trained according to the position matrix corresponding to the sample causal conjunction word of the second sample sentence, the sample sentence information matrix, the sample cause subject word, and the sample result subject word, to obtain the trained causal relation extraction model.

[0089] As Figure 7As shown, the sentence matrix corresponding to the to-be-processed sentence in word units can be obtained, the sentence matrix is input into a graph neural network to obtain a sentence information matrix, the sentence information matrix is input into an attention mechanism network matrix to obtain a causal conjunction word in the to-be-processed sentence, a position matrix corresponding to the causal conjunction word is generated according to the position of the causal conjunction word in the to-be-processed sentence, and the position matrix corresponding to the causal conjunction word and the sentence information matrix are input into the trained causal relationship extraction model to obtain a reason subject word and a result subject word corresponding to the causal conjunction word.

[0090] The above Figure 7 The present disclosure also provides a causal relationship generation apparatus corresponding to the causal relationship generation method provided by the embodiments of the present disclosure. Since the causal relationship generation apparatus provided by the embodiments of the present disclosure is the same as the above Figure 8 The embodiments of the causal relationship generation method are also applicable to the causal relationship generation apparatus provided by the embodiments of the present disclosure, and will not be described in detail in the embodiments of the present disclosure.

[0091] ​ FIG. 1 is a structural schematic diagram of a causal relationship generation apparatus according to an embodiment of the present application.

[0092] As ​ shown, the causal relationship generation apparatus 100 of the embodiments of the present application can include a first obtaining module 110, a second obtaining module 120, a generating module 130, and an input module 140.

[0093] The first obtaining module 110 is configured to obtain a sentence information matrix corresponding to a to-be-processed sentence.

[0094] The second obtaining module 120 is configured to obtain a causal conjunction word in the to-be-processed sentence according to the sentence information matrix.

[0095] The generating module 130 is configured to generate a position matrix corresponding to the causal conjunction word according to a position of the causal conjunction word in the to-be-processed sentence.

[0096] The input module 140 is configured to input the position matrix corresponding to the causal conjunction word and the sentence information matrix into a trained causal relationship extraction model to obtain a reason subject word and a result subject word corresponding to the causal conjunction word.

[0097] In an embodiment of the present application, the first obtaining module 110 is specifically configured to: obtain a sentence matrix corresponding to the to-be-processed sentence in word units; and input the sentence matrix into a graph neural network to obtain the sentence information matrix.

[0098] In an embodiment of the present application, the first obtaining module 110 is specifically configured to: train last three layers of network parameters in the Roberta network according to a plurality of first sample sentences of a cause-effect sentence pattern, to obtain trained network parameters; determine the trained network parameters as parameters of a pre-trained model to be trained, to obtain a trained pre-trained model; and input the sentence to be processed into the trained pre-trained model, to obtain the sentence matrix.

[0099] In an embodiment of the present application, as shown in ​ The cause-effect relationship generation apparatus 100 further includes a third obtaining module 150, configured to: obtain a syntax dependency tree in word units; and convert the syntax dependency tree into a Laplacian matrix, to obtain the graph neural network.

[0100] In an embodiment of the present application, the second obtaining module 120 is specifically configured to: input the sentence information matrix into an attention mechanism network matrix, to obtain the cause-effect conjunction.

[0101] In an embodiment of the present application, the cause-effect relationship extraction model is a multi-head attention mechanism model.

[0102] In an embodiment of the present application, as shown in ​ The cause-effect relationship generation apparatus 100 further includes a fourth obtaining module 160, configured to: obtain a sample cause subject word and a corresponding sample result subject word in a second sample sentence that are artificially labeled; obtain a sample sentence information matrix corresponding to the second sample sentence; obtain a sample cause-effect conjunction in the second sample sentence according to the sample sentence information matrix; generate a position matrix corresponding to the sample cause-effect conjunction according to a position of the sample cause-effect conjunction in the second sample sentence; and train a cause-effect relationship extraction model to be trained according to the position matrix corresponding to the sample cause-effect conjunction, the sample sentence information matrix, the sample cause subject word, and the sample result subject word, to obtain the trained cause-effect relationship extraction model.

[0103] The causality generation apparatus of the embodiment of the present application obtains a sentence information matrix corresponding to a to-be-processed sentence, obtains a causal conjunction in the to-be-processed sentence according to the sentence information matrix, generates a position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, inputs the position matrix corresponding to the causal conjunction and the sentence information matrix into a trained causality extraction model, and obtains a reason subject word and a result subject word corresponding to the causal conjunction. Thus, the reason subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causality extraction model, and the causality can be automatically generated, has strong applicability, and can be automatically aligned, thereby reducing the labor cost.

[0104] To implement the above-mentioned embodiments, as shown in ​ The present application also proposes an electronic device 200, which comprises a memory 210, a processor 220, and a computer program stored in the memory 210 and executable on the processor 220. When the processor 220 executes the program, the method for generating a causality as proposed in the foregoing embodiments of the present application is implemented.

[0105] The electronic device of the embodiment of the present application obtains a sentence information matrix corresponding to a to-be-processed sentence by executing a computer program stored in a memory by a processor, obtains a causal conjunction in the to-be-processed sentence according to the sentence information matrix, generates a position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, inputs the position matrix corresponding to the causal conjunction and the sentence information matrix into a trained causality extraction model, and obtains a reason subject word and a result subject word corresponding to the causal conjunction. Thus, the reason subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causality extraction model, and the causality can be automatically generated, has strong applicability, and can be automatically aligned, thereby reducing the labor cost.

[0106] To implement the above-mentioned embodiments, the present application also proposes a computer readable storage medium having a computer program stored thereon. When the program is executed by a processor, the method for generating a causality as proposed in the foregoing embodiments of the present application is implemented.

[0107] The computer readable storage medium of the embodiment of the application, by storing the computer program and being executed by the processor, obtains the sentence information matrix corresponding to the to-be-processed sentence, obtains the causal conjunction in the to-be-processed sentence according to the sentence information matrix, generates the position matrix corresponding to the causal conjunction according to the position of the causal conjunction in the to-be-processed sentence, inputs the position matrix corresponding to the causal conjunction and the sentence information matrix into the trained causal relationship extraction model, and obtains the cause subject word and the result subject word corresponding to the causal conjunction. Therefore, the cause subject word and the result subject word corresponding to the causal conjunction can be automatically generated by the causal relationship extraction model, compared with the high cost, low applicability and the need for manual alignment of the causal relationship in the generation of the causal relationship in the related art, the automatic generation of the causal relationship can be realized, the applicability is strong, and the causal relationship can be automatically aligned, and the labor cost is low.

[0108] In the description of the present specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the present specification and the features of the different embodiments or examples without contradiction.

[0109] In addition, the terms "first", "second" are only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present application, the meaning of "multiple" is at least two, for example, two, three, etc., unless otherwise explicitly specified.

[0110] Any process or method descriptions in flow charts or otherwise described herein, represent embodiments of examples that can be implemented as code (for example, instructions for execution by a processor or a computer) for implementation by a machine and thus, can be included in machine readable medium and executed by a machine processor that can be specifically constructed for the purposes or be employed by a machine or a device or other apparatus that is specially constructed for the purposes, or combinations thereof. As such, the present application is not limited by the process or method described in the flow charts, and it should be understood that the process or method can include some other processes or methods not present in the flow charts.

[0111] The logic and / or steps represented in the flowcharts and / or described herein, for example, can be considered as a sequence of executable instructions stored in a computer readable medium, which can be executed by an instruction execution system, apparatus or device, such as a computer-based system, a processor-based system, or other system that can fetch the instructions from the instruction execution system, apparatus or device and execute the instructions, or a combination thereof. For the purposes of this specification, a "computer readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus or device. The computer readable medium can specifically be, but is not limited to, the following: an electronic connection (electronic apparatus) having one or more wires, a portable computer diskette (magnetic apparatus), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, and a portable compact disk read-only memory (CDROM). In addition, the computer readable medium can even be paper or other suitable medium upon which the program can be printed, because the program can be electronically obtained, for example, by optically scanning the paper or other medium, then

[0112] It should be understood that portions of the application can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. As such, if implemented in hardware, and in another embodiment, any of the following technologies, known in the art, or a combination thereof, can be used: discrete logic circuitry having logic gates for implementing logic functions on data signals, application specific integrated circuits having appropriate combinational logic gates, programmable gate arrays (PGA), field programmable gate arrays (FPGA), and the like.

[0113] Those of ordinary skill in the art can understand that all or part of the steps carried out by the above-mentioned embodiment methods can be completed by programs instructing relevant hardware, and the programs can be stored in a computer readable storage medium. When the programs are executed, they include one of the steps of the method embodiments or a combination thereof.

[0114] In addition, each of the functional units in the various embodiments of the present application can be integrated in one processing module, or each of the units can be physically present separately, or two or more units can be integrated in one module. The integrated module can be implemented in the form of hardware or in the form of a software functional module. When the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer readable storage medium.

[0115] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it should be understood that the above embodiments are exemplary and should not be construed as limiting the present application, and those skilled in the art can make changes, modifications, replacements and variations to the above embodiments within the scope of the present application.

Claims

1. A method of generating a cause-and-effect relationship, characterized by, The method comprises the following steps: obtaining a to-be-processed sentence, inputting the to-be-processed sentence into a trained pre-training model to obtain a corresponding sentence matrix in word units, inputting the sentence matrix into a graph neural network to obtain a sentence information matrix corresponding to the to-be-processed sentence, wherein the sentence information matrix refers to a matrix representing semantic information of the to-be-processed sentence; inputting the sentence information matrix into an attention mechanism network matrix, and obtaining a causal conjunction word in the to-be-processed sentence by using a sequence labeling algorithm; generating a position matrix corresponding to the causal conjunction word according to the position of the causal conjunction word in the to-be-processed sentence; inputting the position matrix corresponding to the causal conjunction word and the sentence information matrix into a trained causal relationship extraction model to automatically output a cause subject word and a result subject word corresponding to the causal conjunction word.

2. The generation method of claim 1, wherein, The method for determining the trained pre-training model comprises the following steps: training last three layers of network parameters in a Roberta network according to a plurality of first sample sentences of a causal sentence type to obtain trained network parameters; determining the trained network parameters as parameters of a to-be-trained pre-training model to obtain a trained pre-training model.

3. The generation method of claim 1, wherein, The method for determining the graph neural network comprises the following steps: obtaining a syntax dependency tree in word units; converting the syntax dependency tree into a Laplacian matrix to obtain the graph neural network.

4. The generation method of claim 1, wherein, The causal relationship extraction model is a multi-head attention mechanism model.

5. The generation method of claim 1, wherein, The method for determining the trained causal relationship extraction model comprises the following steps: obtaining a sample cause subject word and a corresponding sample result subject word manually labeled in a second sample sentence; obtaining a sample sentence information matrix corresponding to the second sample sentence; obtaining a sample causal conjunction word in the second sample sentence according to the sample sentence information matrix; generating a position matrix corresponding to the sample causal conjunction word according to the position of the sample causal conjunction word in the second sample sentence; training a to-be-trained causal relationship extraction model according to the position matrix corresponding to the sample causal conjunction word, the sample sentence information matrix, the sample cause subject word and the sample result subject word to obtain the trained causal relationship extraction model.

6. A cause-effect relationship generating apparatus characterized by comprising: The method comprises the following steps: a first obtaining module is configured to obtain a to-be-processed sentence, input the to-be-processed sentence into a trained pre-training model to obtain a corresponding sentence matrix in word units, input the sentence matrix into a graph neural network to obtain a sentence information matrix corresponding to the to-be-processed sentence, wherein the sentence information matrix refers to a matrix representing semantic information of the to-be-processed sentence; a second obtaining module is configured to input the sentence information matrix into an attention mechanism network matrix to obtain a causal conjunction word in the to-be-processed sentence; a generating module is configured to generate a position matrix corresponding to the causal conjunction word according to the position of the causal conjunction word in the to-be-processed sentence; an inputting module is configured to input the position matrix corresponding to the causal conjunction word and the sentence information matrix into a trained causal relationship extraction model to automatically output a cause subject word and a result subject word corresponding to the causal conjunction word.

7. The generating device of claim 6, wherein, A manner of determining the trained pre-training model comprises: According to a plurality of first sample sentences of a cause-effect sentence pattern, training last three layers of network parameters in a Roberta network to obtain trained network parameters; The trained network parameters are determined as parameters of a pre-training model to be trained to obtain a trained pre-training model.

8. The generating device of claim 6, wherein, Further comprising: A third obtaining module is configured to determine the graph neural network, wherein a manner of determining the graph neural network comprises: Obtaining a syntax dependency tree in units of words; Converting the syntax dependency tree into a Laplacian matrix to obtain the graph neural network.

9. The generating device of claim 6, wherein, The cause-effect relationship extraction model is a multi-head attention mechanism model.

10. The generating device of claim 6, wherein, Further comprising: A fourth obtaining module is configured to determine the trained cause-effect relationship extraction model, wherein a manner of determining the trained cause-effect relationship extraction model comprises: Obtaining a sample cause subject word and a corresponding sample result subject word in a second sample sentence manually annotated; Obtaining a sample sentence information matrix corresponding to the second sample sentence; Obtaining a sample cause conjunction in the second sample sentence according to the sample sentence information matrix; Generating a position matrix corresponding to the sample cause conjunction according to a position of the sample cause conjunction in the second sample sentence; Training a cause-effect relationship extraction model to be trained according to the position matrix corresponding to the sample cause conjunction, the sample sentence information matrix, the sample cause subject word and the sample result subject word to obtain the trained cause-effect relationship extraction model.

11. An electronic device, comprising: A computer program stored in the memory and executable on the processor, when the processor executes the program, implements the cause-effect relationship generation method in any one of claims 1-4.

12. A computer readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the cause-effect relationship generation method in any one of claims 1-4.