Method and apparatus for determining causality, electronic device and storage medium
View Patent ↗Embodiments of the present disclosure provide a method for determining causality, an apparatus for determining causality, an electronic device and a storage medium, and relates to a field of knowledge graph technologies. The method includes: obtaining event words expressing individual events and related words adjacent to the event words in a target text; inputting the event words and the related words into a graph neural network; and determining whether there is a causal relationship between any two events through the graph neural network.
1 . A method for determining causality, comprising:
obtaining event words expressing individual events and related words adjacent to the event words in a target text;
inputting the event words and the related words into a graph neural network, wherein a graph is a data structure composed of two components: a vertex and an edge, the graph is described based on a set of vertices and edges, the edges are directed or undirected, which depends on whether there is a direction dependency between the vertices, and the graph neural network is a neural network directly running on a graph structure; and
determining whether there is a causal relationship between any two events through the graph neural network;
wherein the determining whether there is a causal relationship between any two events through the graph neural network comprises:
inputting the event words and the related words to an input layer of the graph neural network and outputting semantic vectors of the event words and semantic vectors of the related words through the input layer;
inputting the semantic vectors of the event words, the semantic vectors of the related words, and a pre-labeled adjacency matrix representing causal relationships between the event words and the related words to a convolutional layer of the graph neural network, and outputting a vector matrix representing combination relations between the event words and the related words through the convolutional layer, wherein in the pre-labeled adjacency matrix, a value of 1 indicates that there is a causal relationship between an event word and a related word corresponding to the value, and a value of 0 indicates that there is no causal relationship between an event word and a related word corresponding to the value;
inputting the vector matrix to a fully connected layer of the graph neural network, and outputting a probability value indicating whether there is a causal relationship between any two event words through the fully connected layer; and
inputting the probability value indicating whether there is a causal relationship between any two event words into an output layer of the graph neural network, and outputting a result on whether there is a causal relationship between the any two event words through the output layer;
wherein the outputting the vector matrix representing the combination relations between the event words and the related words through the convolutional layer comprises:
determining feature information of each event word and feature information of the related word adjacent to the event word as content of an event node to obtain at least two event nodes;
generating one or more edges between the at least two event nodes through the convolutional layer based on relevancy information between the at least two event nodes to obtain an event graph; and
outputting the vector matrix based on the event graph;
wherein the method further comprises:
identifying, from the event graph stored in memory, one or more nodes connected by a causal edge to a current event node; selecting a subsequent event node having a probability value of causality exceeding a threshold; and outputting the subsequent event as a predicted event.
2 . The method according to claim 1 , wherein the obtaining the event words expressing individual events and the related words adjacent to the event words in the target text comprises:
dividing the target text into a plurality of sentences;
extracting a sentence from the plurality of sentences as a current sentence, and extracting an event word from the current sentence when the current sentence meets an event word extraction condition;
extracting a related word adjacent to the event word from the current sentence when the current sentence meets a related word extraction condition; and
repeating the operation of extracting the event word and the related word for each of the plurality of sentences until the event word and related word adjacent to the event word are extracted from each of the plurality of sentences.
3 . The method according to claim 1 , further comprising:
obtaining training data of the graph neural network; and
training processing parameters of the graph neural network based on the training data to generate the graph neural network.
4 . An electronic device, comprising:
at least one processor; and
a memory communicatively connected to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is caused to:
obtain event words expressing individual events and related words adjacent to the event words in a target text;
input the event words and the related words into a graph neural network, wherein a graph is a data structure composed of two components: a vertex and an edge, the graph is described based on a set of vertices and edges, the edges are directed or undirected, which depends on whether there is a direction dependency between the vertices, and the graph neural network is a neural network directly running on a graph structure; and
determine whether there is a causal relationship between any two events through the graph neural network;
wherein the processor is configured to determine whether there is a causal relationship between any two events through the graph neural network by:
inputting the event words and the related words to an input layer of the graph neural network and outputting semantic vectors of the event words and semantic vectors of the related words through the input layer;
inputting the semantic vectors of the event words, the semantic vectors of the related words, and a pre-labeled adjacency matrix representing causal relationships between the event words and the related words to a convolutional layer of the graph neural network, and outputting a vector matrix representing combination relations between the event words and the related words through the convolutional layer, wherein in the pre-labeled adjacency matrix, a value of 1 indicates that there is a causal relationship between an event word and a related word corresponding to the value, and a value of 0 indicates that there is no causal relationship between an event word and a related word corresponding to the value;
inputting the vector matrix to a fully connected layer of the graph neural network, and outputting a probability value indicating whether there is a causal relationship between any two event words through the fully connected layer; and
inputting the probability value indicating whether there is a causal relationship between any two event words into an output layer of the graph neural network, and outputting a result on whether there is a causal relationship between the any two event words through the output layer;
wherein the outputting the vector matrix representing the combination relations between the event words and the related words through the convolutional layer comprises:
determining feature information of each event word and feature information of the related word adjacent to the event word as content of an event node to obtain at least two event nodes;
generating one or more edges between the at least two event nodes through the convolutional layer based on relevancy information between the at least two event nodes to obtain an event graph; and
outputting the vector matrix based on the event graph;
wherein the processor is configured to identify, from the event graph stored in memory, one or more nodes connected by a causal edge to a current event node;
select a subsequent event node having a probability value of causality exceeding a threshold; and output the subsequent event as a predicted event.
5 . The electronic device according to claim 4 , wherein the processor is configured to obtain the event words expressing individual events and the related words adjacent to the event words in the target text by:
dividing the target text into a plurality of sentences;
extracting a sentence from the plurality of sentences as a current sentence, and extracting an event word from the current sentence when the current sentence meets an event word extraction condition;
extracting a related word adjacent to the event word from the current sentence when the current sentence meets a related word extraction condition; and
repeating the operation of extracting the event word and the related word for each of the plurality of sentences until the event word and related word adjacent to the event word are extracted from each of the plurality of sentences.
6 . The electronic device according to claim 4 , wherein the processor is further configured to:
obtain training data of the graph neural network; and
train processing parameters of the graph neural network based on the training data to generate the graph neural network.
7 . A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to make the computer implement a method for determining causality, comprising:
obtaining event words expressing individual events and related words adjacent to the event words in a target text;
inputting the event words and the related words into a graph neural network, wherein a graph is a data structure composed of two components: a vertex and an edge, the graph is described based on a set of vertices and edges, the edges are directed or undirected, which depends on whether there is a direction dependency between the vertices, and the graph neural network is a neural network directly running on a graph structure; and
determining whether there is a causal relationship between any two events through the graph neural network;
wherein the determining whether there is a causal relationship between any two events through the graph neural network comprises:
inputting the event words and the related words to an input layer of the graph neural network and outputting semantic vectors of the event words and semantic vectors of the related words through the input layer;
inputting the semantic vectors of the event words, the semantic vectors of the related words, and a pre-labeled adjacency matrix representing causal relationships between the event words and the related words to a convolutional layer of the graph neural network, and outputting a vector matrix representing combination relations between the event words and the related words through the convolutional layer, wherein in the pre-labeled adjacency matrix, a value of 1 indicates that there is a causal relationship between an event word and a related word corresponding to the value, and a value of 0 indicates that there is no causal relationship between an event word and a related word corresponding to the value;
inputting the vector matrix to a fully connected layer of the graph neural network, and outputting a probability value indicating whether there is a causal relationship between any two event words through the fully connected layer; and
inputting the probability value indicating whether there is a causal relationship between any two event words into an output layer of the graph neural network, and outputting a result on whether there is a causal relationship between the any two event words through the output layer;
wherein the outputting the vector matrix representing the combination relations between the event words and the related words through the convolutional layer comprises:
determining feature information of each event word and feature information of the related word adjacent to the event word as content of an event node to obtain at least two event nodes;
generating one or more edges between the at least two event nodes through the convolutional layer based on relevancy information between the at least two event nodes to obtain an event graph; and
outputting the vector matrix based on the event graph;
wherein the method further comprises:
identifying, from the event graph stored in memory, one or more nodes connected by a causal edge to a current event node; selecting a subsequent event node having a probability value of causality exceeding a threshold; and outputting the subsequent event as a predicted event.
8 . The non-transitory computer-readable storage medium according to claim 7 , wherein the obtaining the event words expressing individual events and the related words adjacent to the event words in the target text comprises:
dividing the target text into a plurality of sentences;
extracting a sentence from the plurality of sentences as a current sentence, and extracting an event word from the current sentence when the current sentence meets an event word extraction condition;
extracting a related word adjacent to the event word from the current sentence when the current sentence meets a related word extraction condition; and
repeating the operation of extracting the event word and the related word for each of the plurality of sentences until the event word and related word adjacent to the event word are extracted from each of the plurality of sentences.
9 . The non-transitory computer-readable storage medium according to claim 8 , wherein the method further comprises:
obtaining training data of the graph neural network; and
training processing parameters of the graph neural network based on the training data to generate the graph neural network.