Statement parsing, training method, device, equipment and storage medium of matching model
By obtaining the matching degree between the overall structure of the query statement and the candidate graph structure, and using the knowledge graph and matching model for entity recognition and graph structure matching, the problem of limitations in the existing technology is solved, and accurate analysis and efficient response of complex query statements are achieved.
Patent Information
- Application Number
- CN202210578199.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-05-25
AI Technical Summary
The prior art is only applicable to simple query statements that include one entity and one attribute when parsing statements, and the scope of application is relatively limited.
By obtaining the matching degree between the overall structure of the query statement and the candidate graph structure, determining the analysis results of the query statement, using the knowledge graph and matching model for entity recognition and graph structure matching, expanding the scope of application to complex query statements with multiple entities and multiple attributes.
It realizes wide applicability analysis of query statements, improving the accuracy of analysis results and the accuracy of response results.
Smart Images

Figure CN115130456B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and particularly to a method, device, equipment and storage medium for training a sentence parsing and matching model. Background Art
[0002] With the development of artificial intelligence technology, there are more and more application scenarios for parsing query sentences. By parsing the query sentences, the parsing results of the query sentences can be obtained, and the parsing results are used to query the answer results in the knowledge graph.
[0003] In related technologies, when parsing a sentence, an entity in the query sentence and an attribute of the entity are first identified, and then the result formed by the identified entity and attribute is used as the parsing result of the query sentence. This kind of sentence parsing method is only applicable to simple query sentences including one entity and one attribute, and the applicable range is relatively limited. Summary of the Invention
[0004] The embodiments of the present application provide a method, device, equipment and storage medium for training a sentence parsing and matching model, which can be used to improve the applicable range of the sentence parsing method. The technical solutions are as follows:
[0005] On the one hand, the embodiments of the present application provide a sentence parsing method, and the method includes:
[0006] Obtain a query sentence to be parsed and the knowledge graph corresponding to the query sentence;
[0007] Perform entity recognition on the query sentence to obtain at least one query entity;
[0008] Based on the at least one query entity and the knowledge graph, obtain at least one candidate graph structure;
[0009] Obtain the matching degree between the overall structure of the query sentence and the at least one candidate graph structure, and determine the parsing result of the query sentence based on the candidate graph structure whose matching degree meets the selection condition.
[0010] The present application also provides a method for training a matching model, and the method includes:
[0011] Obtain a sample sentence and the positive example graph structure and negative example graph structure corresponding to the sample sentence, where the positive example graph structure is the graph structure corresponding to the overall structure of the sample sentence, and the negative example graph structure is a graph structure different from the positive example graph structure;
[0012] Call the initial matching model to obtain the first matching degree between the overall structure of the sample sentence and the positive example graph structure, and the second matching degree between the overall structure of the sample sentence and the negative example graph structure;
[0013] Obtain a target loss based on a first difference between the first matching degree and the second matching degree, where the target loss has a negative correlation with the first difference;
[0014] Update model parameters of the initial matching model by using the target loss to obtain a target matching model.
[0015] On the other hand, a statement parsing device is provided, and the device includes:
[0016] A first obtaining unit, configured to obtain a query statement to be parsed and a knowledge graph corresponding to the query statement;
[0017] An identification unit, configured to perform entity identification on the query statement to obtain at least one query entity;
[0018] A second obtaining unit, configured to obtain at least one candidate graph structure based on the at least one query entity and the knowledge graph;
[0019] A third obtaining unit, configured to obtain a matching degree between an overall structure of the query statement and the at least one candidate graph structure, and determine a parsing result of the query statement based on a candidate graph structure whose matching degree meets a selection condition.
[0020] In a possible implementation manner, the second obtaining unit is configured to determine a target graph structure template, where the target graph structure template is used to constrain a form of a graph structure including a first number of entity nodes, and the first number is the number of the at least one query entity; obtain candidate entities respectively corresponding to each query entity based on the knowledge graph; query at least one set of filling data matching the target graph structure template from the knowledge graph based on the candidate entities respectively corresponding to each query entity, and fill the target graph structure template with the at least one set of filling data to obtain the at least one candidate graph structure.
[0021] In a possible implementation manner, the identification unit is configured to extract features of each character in the query statement to obtain character features respectively corresponding to the each character; obtain annotation results respectively corresponding to the each character based on the character features respectively corresponding to the each character, where an annotation result corresponding to any character is used to indicate a matching probability between the any character and each candidate character type, and the each candidate character type includes an entity type and a non-entity type; determine a highest matching probability among the matching probabilities indicated by the annotation result corresponding to any character, use the candidate character type corresponding to the highest matching probability as a target character type of the any character, and obtain the at least one query entity based on the target character types of the each character.
[0022] In a possible implementation manner, the third obtaining unit is configured to call a target matching model to obtain the matching degree between the overall structure of the query statement and the at least one candidate graph structure.
[0023] In a possible implementation manner, the apparatus further includes:
[0024] A query unit, configured to query an answer result matching the parsing result from the knowledge graph.
[0025] There is also provided a training apparatus for a matching model, the apparatus including:
[0026] A fourth obtaining unit, configured to obtain a sample statement, a positive example graph structure and a negative example graph structure corresponding to the sample statement, where the positive example graph structure is a graph structure corresponding to the overall structure of the sample statement, and the negative example graph structure is a graph structure different from the positive example graph structure;
[0027] A fifth obtaining unit, configured to call an initial matching model to obtain a first matching degree between the overall structure of the sample statement and the positive example graph structure, and a second matching degree between the overall structure of the sample statement and the negative example graph structure;
[0028] A sixth obtaining unit, configured to obtain a target loss based on a first difference between the first matching degree and the second matching degree, where the target loss has a negative correlation with the first difference;
[0029] An updating unit, configured to update model parameters of the initial matching model by using the target loss to obtain a target matching model.
[0030] In a possible implementation manner, the initial matching model includes a first feature extraction model, a second feature extraction model and a similarity calculation model. The fifth obtaining unit is configured to call the first feature extraction model to perform feature extraction on the sample statement to obtain first features; call the second feature extraction model to perform feature extraction on the positive example graph structure to obtain second features; call the similarity calculation model to calculate the similarity between the first features and the second features, and use the similarity as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
[0031] In a possible implementation manner, the fifth obtaining unit is configured to obtain each triple corresponding to the positive example graph structure, where any triple is obtained based on two adjacent nodes in the positive example graph structure and an edge between the two adjacent nodes; call the second feature extraction model to perform feature extraction on each of the triples respectively to obtain sub-features corresponding to each of the triples respectively; and obtain the second features based on the sub-features corresponding to each of the triples respectively.
[0032] In a possible implementation manner, the fifth obtaining unit is configured to convert the sub-features respectively corresponding to the respective triples into scores respectively corresponding to the respective triples; use the ratio of the score corresponding to any one triple to the total score as the weight corresponding to any one triple, where the total score is the sum of the scores respectively corresponding to the respective triples; and perform weighted summation on the sub-features respectively corresponding to the respective triples based on the weights respectively corresponding to the respective triples to obtain the second feature.
[0033] In a possible implementation manner, both the first matching degree and the second matching degree are values not greater than a first value and not less than a second value. The sixth obtaining unit is configured to subtract the second difference from the first difference to obtain a third difference, where the second difference is the difference between the second value and the first value; and use the maximum value between the third difference and a reference value as the target loss, where the reference value is a value used to ensure a negative correlation between the target loss and the first difference.
[0034] On the other hand, a computer device is provided. The computer device includes a processor and a memory. At least one computer program is stored in the memory, and the at least one computer program is loaded and executed by the processor so that the computer device implements the statement parsing method or the matching model training method described in any one of the above.
[0035] On the other hand, a computer-readable storage medium is further provided. At least one computer program is stored in the computer-readable storage medium, and the at least one computer program is loaded and executed by a processor so that a computer implements the statement parsing method or the matching model training method described in any one of the above.
[0036] On the other hand, a computer program product is further provided. The computer program product includes a computer program or computer instructions, and the computer program or the computer instructions are loaded and executed by a processor so that a computer implements the statement parsing method or the matching model training method described in any one of the above.
[0037] The technical solutions provided in the embodiments of the present application at least bring the following beneficial effects:
[0038] The technical solution provided by the embodiment of the present application determines the parsing result of the query statement based on the candidate graph structure whose matching degree with the overall structure of the query statement meets the selection condition. That is to say, the query statement is parsed by considering the overall structure of the query statement. On the basis of considering the overall structure of the query statement, regardless of the number of entities and attributes included in the query statement, the parsing of the query statement can be realized, and the applicable range of this statement parsing method is relatively wide. In addition, the candidate graph structure whose matching degree with the overall structure of the query statement can accurately represent the overall structure of the query statement. Determining the parsing result of the query statement based on this graph structure can ensure the accuracy of the parsing result, and further improve the accuracy of the response result obtained according to the parsing result. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained according to these drawings.
[0040] Figure 1 is a schematic diagram of an implementation environment provided by the embodiment of the present application;
[0041] Figure 2 is a flowchart of a statement parsing method provided by the embodiment of the present application;
[0042] Figure 3 is a schematic diagram of the process of obtaining the annotation results corresponding to each character provided by the embodiment of the present application;
[0043] Figure 4 is a schematic diagram of a plurality of candidate graph structure templates provided by the embodiment of the present application;
[0044] Figure 5 is a schematic diagram of an exemplary graph structure corresponding to a candidate graph structure template provided by the embodiment of the present application;
[0045] Figure 6 is a schematic diagram of a candidate path provided by the embodiment of the present application;
[0046] Figure 7 is a flowchart of a training method for a matching model provided by the embodiment of the present application;
[0047] Figure 8 is a schematic diagram of the process of obtaining a second feature provided by the embodiment of the present application;
[0048] Figure 9It is a schematic diagram of a process for obtaining the first matching degree between the overall structure of a sample statement and the positive example diagram structure by invoking an initial matching model provided by an embodiment of the present application;
[0049] Figure 10 It is a schematic diagram of a statement parsing device provided by an embodiment of the present application;
[0050] Figure 11 It is a schematic diagram of a training device for a matching model provided by an embodiment of the present application;
[0051] Figure 12 It is a schematic diagram of the structure of a server provided by an embodiment of the present application;
[0052] Figure 13 It is a schematic diagram of the structure of a terminal provided by an embodiment of the present application. Detailed implementation manners
[0053] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.
[0054] It should be noted that the terms "first", "second", etc. in the present application are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0055] In an exemplary embodiment, the statement parsing method and the training method for the matching model provided by the embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, intelligent transportation, assisted driving, etc.
[0056] Artificial Intelligence (AI) is to use a digital computer or a machine controlled by a digital computer to simulate, extend, and expand human intelligence, a theory, method, technology, and application system that perceives the environment, acquires knowledge, and uses knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology of computer science. Artificial intelligence attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a way similar to human intelligence. Artificial intelligence also studies the design principles and implementation methods of various intelligent machines to enable the machines to have the functions of perception, reasoning, and decision-making.
[0057] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation / interaction systems, and mechatronics. The software technologies of artificial intelligence mainly include several major directions such as computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning, autonomous driving, and intelligent transportation.
[0058] The solution provided in the embodiments of this application relates to the natural language processing technology of artificial intelligence. Natural Language Processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between humans and computers in natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, the research in this field will involve natural language, that is, the language people use in daily life, so it has a close connection with the research of linguistics. Natural language processing technologies usually include text processing, semantic understanding, machine translation, robot question answering, knowledge graphs, sentence parsing, and other technologies.
[0059] The solution provided in the embodiments of this application also relates to the machine learning technology of artificial intelligence. Machine Learning (ML) is an interdisciplinary field that involves multiple disciplines such as probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize the existing knowledge structure to continuously improve their own performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent, and its applications cover all fields of artificial intelligence. Machine learning and deep learning usually include technologies such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning from demonstration.
[0060] With the research and progress of artificial intelligence technology, artificial intelligence technology is being studied and applied in multiple fields. For example, common ones include smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, driverless, autonomous driving, drones, robots, intelligent healthcare, intelligent customer service, vehicle networking, autonomous driving, and intelligent transportation. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0061] Figure 1 The figure shows a schematic diagram of an implementation environment provided in the embodiments of this application. The implementation environment may include: a terminal 11 and a server 12.
[0062] Exemplarily, the terminal 11 is installed with an application or a web page having a query (or search) function, and the server 12 can provide background services for the application or the web page installed on the terminal.
[0063] The statement parsing method provided by the embodiments of the present application can be executed by the terminal 11, or can be executed by the server 12, or can be jointly executed by the terminal 11 and the server 12. The embodiments of the present application do not limit this. For the case where the statement parsing method provided by the embodiments of the present application is jointly executed by the terminal 11 and the server 12, the server 12 undertakes the main computing work, and the terminal 11 undertakes the secondary computing work; or, the server 12 undertakes the secondary computing work, and the terminal 11 undertakes the main computing work; or, the server 12 and the terminal 11 adopt a distributed computing architecture for collaborative computing.
[0064] The training method of the matching model provided by the embodiments of the present application can be executed by the terminal 11, or can be executed by the server 12, or can be jointly executed by the terminal 11 and the server 12. The embodiments of the present application do not limit this. For the case where the training method of the matching model provided by the embodiments of the present application is jointly executed by the terminal 11 and the server 12, the server 12 undertakes the main computing work, and the terminal 11 undertakes the secondary computing work; or, the server 12 undertakes the secondary computing work, and the terminal 11 undertakes the main computing work; or, the server 12 and the terminal 11 adopt a distributed computing architecture for collaborative computing.
[0065] It should be noted that the execution device of the statement parsing method and the execution device of the training method of the matching model may be the same or different. The embodiments of the present application do not limit this.
[0066] Optionally, the terminal 11 can be any kind of electronic product that can perform human-computer interaction with the user through one or more ways such as a keyboard, a touchpad, a touch screen, a remote control, voice interaction, or a handwriting device. For example, a PC (Personal Computer), a mobile phone, a smart phone, a PDA (Personal Digital Assistant), a wearable device, a PPC (Pocket PC), a tablet computer, a smart car machine, a smart TV, a smart speaker, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, a VR (Virtual Reality) device, an AR (Augmented Reality) device, etc. The server 12 can be a single server, or a server cluster composed of multiple servers, or a cloud computing service center. The terminal 11 and the server 12 establish a communication connection through a wired or wireless network.
[0067] Those skilled in the art should understand that the above-mentioned terminal 11 and server 12 are only examples. Other existing or future terminals or servers that can be applied to this application should also be included within the protection scope of this application and are hereby incorporated herein by reference.
[0068] Based on the above Figure 1 shown implementation environment, an embodiment of this application provides a statement parsing method, which is executed by a computer device. The computer device can be the terminal 11 or the server 12. The embodiment of this application does not limit this. For example Figure 2 shown, the statement parsing method provided by the embodiment of this application may include the following steps 201 to 204.
[0069] In step 201, obtain the query statement to be parsed and the knowledge graph corresponding to the query statement.
[0070] A query statement refers to any statement that needs to be parsed to query the response result according to the parsing result. The query statement can be a statement input by the interaction object, or a statement imported by the interaction object, or a statement obtained by recognizing the picture input by the interaction object, etc. The embodiment of this application does not limit this. Exemplarily, if the computer device is a terminal, the terminal can obtain the query statement by detecting the interaction operation of the interaction object; if the computer device is a server, the server can obtain the query statement by communicating with the terminal.
[0071] The knowledge graph corresponding to the query statement is the knowledge graph based on which the response result is queried according to the query statement. The number of knowledge graphs corresponding to the query statement can be one or multiple. The embodiment of this application does not limit this. A knowledge graph is a relational network obtained by connecting different types of information. A knowledge graph consists of nodes and edges.
[0072] In an exemplary embodiment, all the knowledge graphs obtained when obtaining the query statement are used as the knowledge graph corresponding to the query statement. In an exemplary embodiment, the knowledge graphs that meet the first condition among all the knowledge graphs obtained when obtaining the query statement are used as the knowledge graph corresponding to the query statement. The first condition is set according to experience or flexibly adjusted according to the application scenario. The embodiment of this application does not limit this.
[0073] Exemplarily, the knowledge graph that meets the first condition can be a knowledge graph whose time gap between the creation time and the time of obtaining the query statement is not greater than the time gap threshold. The time gap threshold is set according to experience or flexibly adjusted according to the application scenario. The embodiment of this application does not limit this. Of course, the knowledge graph that meets the first condition can also be other types of knowledge graphs, which will not be elaborated here one by one.
[0074] In an exemplary embodiment, all the knowledge graphs obtained when acquiring a query statement are pre-stored in a computer device. The computer device can directly extract all the knowledge graphs obtained when acquiring the query statement from the storage, and then acquire the knowledge graph corresponding to the query statement. In an exemplary embodiment, all the knowledge graphs obtained when acquiring a query statement are stored in a server. If the computer device is a terminal, the computer device communicates with the server to obtain all the knowledge graphs obtained when acquiring the query statement, and then acquire the knowledge graph corresponding to the query statement.
[0075] In step 202, entity recognition is performed on the query statement to obtain at least one query entity.
[0076] The at least one query entity is an entity recognized from the query statement. An entity is an objectively existing and distinguishable thing. For example, entities include, but are not limited to, cats, dogs, star 1, movie 1, etc. An entity is the basic unit of a knowledge graph and an important unit for carrying information in the knowledge graph. The number of the at least one query entity in the embodiments of the present application is not limited, which is related to the specific situation of the query statement.
[0077] In a possible implementation manner, the process of performing entity recognition on the query statement to obtain at least one query entity includes the following steps A to C.
[0078] Step A: Characteristic extraction is performed on each character in the query statement to obtain the character characteristics respectively corresponding to the characters.
[0079] The character characteristic corresponding to any character is used to represent the any character. The character characteristics corresponding to each character in the query statement are obtained by performing characteristic extraction on each character in the query statement. Exemplarily, the form of the character characteristic corresponding to any character can be a matrix or a vector, etc.
[0080] In an exemplary embodiment, a character feature extraction model is called to extract features for each character in the query statement, and character features corresponding to each character are obtained. The character feature extraction model is a model for extracting character features. Exemplarily, the model structure of the character feature extraction model can be a BERT (Bidirectional Encoder Representation from Transformers) model, a CNN (Convolutional Neural Networks) model, an LSTM (Long Short Term Memory) model, a bidirectional LSTM model, a GRU (Gated Recurrent Unit) model, etc., and the embodiments of the present application do not limit this.
[0081] In an exemplary embodiment, the process of calling the character feature extraction model to extract features for each character in the query statement and obtaining character features corresponding to each character is as follows: The character sequence corresponding to the query statement is input into the character feature extraction model. The character sequence corresponding to the query statement includes a start flag character, each character in the query statement, and an end flag character. The character feature extraction model is called to extract features from the character sequence, and character features corresponding to each character in the query statement are output. Exemplarily, in addition to outputting character features corresponding to each character in the query statement, the character feature extraction model can also output the character feature corresponding to the start flag character and the character feature corresponding to the end flag character. Exemplarily, the start flag character can be [CLS], and the end flag character can be [SEP].
[0082] Step B: Based on the character features corresponding to each character, obtain the annotation results corresponding to each character. The annotation result corresponding to any character is used to indicate the matching probability between any character and each candidate character type.
[0083] Among them, each candidate character type includes an entity type and a non-entity type. The number of entity types may be one or multiple; the number of non-entity types may be one or multiple, and the embodiments of the present application do not limit this.
[0084] Exemplarily, the number of entity types is multiple, including entity start character type, entity middle character type, entity end character type, and single-character entity type respectively; the number of non-entity types is one. In this case, each candidate character type includes entity start character type, entity middle character type, entity end character type, single-character entity type, and non-entity type. Exemplarily, entity start character type, entity middle character type, entity end character type, single-character entity type, and non-entity type can be represented by B, I, E, S, and O respectively.
[0085] Each candidate character type is preset according to experience. In some embodiments, each candidate character type may further include other character types, which are not limited in the embodiments of the present application.
[0086] The annotation result corresponding to any character is used to indicate the matching probability between any character and each candidate character type. Exemplarily, the higher the matching probability between any character and any candidate character type, the more likely the type of the any character is the any candidate character type. The embodiments of the present application do not limit the representation form of the annotation result corresponding to any character, as long as it can indicate the matching probability between any character and each candidate character type. Exemplarily, the form of the annotation result corresponding to any character is a matrix of the target dimension, or a vector of the target dimension, etc. The target dimension is the number of each candidate character type. Exemplarily, the annotation result corresponding to any character can also be called the probability distribution corresponding to any character.
[0087] In an exemplary embodiment, the annotation model is called to obtain the annotation result corresponding to each character based on the character features corresponding to each character respectively. The annotation model is a model that can obtain the annotation result of a character according to the character features of the character. Exemplarily, the annotation model can be a classification model.
[0088] Exemplarily, the process of calling the annotation model to obtain the annotation result corresponding to each character based on the character features corresponding to each character respectively includes: calling the annotation model to convert the character features corresponding to each character into the logical (logit) score features corresponding to each character respectively; activating the logical score features corresponding to each character through an activation function to obtain the annotation result corresponding to each character respectively. The dimension of the logical score feature corresponding to any character is the target dimension, corresponding to each candidate character type (such as B, I, E, S, and O) respectively. The embodiments of the present application do not limit the type of the activation function. Exemplarily, the activation function can be softmax (a kind of activation function).
[0089] Exemplarily, the annotation result corresponding to any character can be calculated based on the following formula 1:
[0090]
[0091] Among them, logits i represents the logical score feature corresponding to the i-th character, where i is an integer not less than 1 and not greater than the number of each character in the query statement; P and Q represent the model parameters of the annotation model, which are updated along with the training process of the annotation model; T i represents the character feature corresponding to the i-th character. The process of obtaining the logical score feature corresponding to the character based on the first formula in Formula 1 can be regarded as the process of linearly transforming the character feature corresponding to the character to obtain the logical score feature corresponding to the character. Prob i represents the annotation result corresponding to the i-th character, and softmax() represents activation through softmax.
[0092] Exemplarily, the process of obtaining the annotation results corresponding to each character is as Figure 3 shown. Input the character sequence corresponding to the query statement ([CLS]Who is the uncle of the wife of Star 1[SEP]) into the character feature extraction model (BERT model) to obtain the character features corresponding to each character respectively; call the annotation model to convert the character features corresponding to each character into the logical score features corresponding to each character respectively; activate the logical score features corresponding to each character through the activation function (softmax) to obtain the annotation results corresponding to each character respectively.
[0093] Step C: Determine the highest matching probability among the matching probabilities indicated by the annotation results corresponding to any character, use the candidate character type corresponding to the highest matching probability as the target character type of any character, and obtain at least one query entity based on the target character types of each character.
[0094] The candidate character type corresponding to the highest matching probability refers to the candidate character type that is most likely to be the type of any character among each candidate character type. Use the candidate character type corresponding to the highest matching probability as the target character type of any character, and the target character type of any character refers to the character type of any character determined through entity recognition.
[0095] Referring to the method of obtaining the target character type of any character, the target character types of each character can be obtained, and then at least one query entity can be obtained based on the target character types of each character.
[0096] In an exemplary embodiment, if each candidate character type includes an entity start character type, an entity middle character type, an entity end character type, a single-character entity type, and a non-entity type, the process of obtaining at least one query entity based on the target character type of each character may include: regarding each character with a target character type of a single-entity character type as a query entity; regarding an entity formed by multiple characters that meet the target condition as a query entity, and taking all the obtained query entities as the at least one query entity.
[0097] Exemplarily, multiple characters that meet the target condition refer to multiple characters that simultaneously meet the following three conditions: 1. Adjacent; 2. The target character type of the first character is the entity start character type, and the target character type of the last character is the entity end character type; 3. There are no other characters between the first character and the last character, or the target character types of the characters existing between the first character and the last character are all entity middle character types.
[0098] Exemplarily, if the number of entity types and non-entity types is both one, the process of obtaining at least one query entity based on the target character type of each character may include: regarding each entity formed by a group of adjacent characters with a target character type of an entity type as a query entity, thereby obtaining at least one query entity. The number of characters in any group of adjacent characters with a target character type of an entity type may be one or multiple.
[0099] In an exemplary embodiment, the above character feature extraction model and annotation model may be two models in a target annotation result acquisition model, and the target annotation result acquisition model is obtained by training an initial annotation result acquisition model. The initial annotation result acquisition model includes an initial character feature extraction model and an initial annotation model. Before calling the character feature extraction model to implement step A above and calling the annotation model to implement step B above, it is necessary to first train the target annotation result acquisition model.
[0100] In an exemplary embodiment, the process of training the target annotation result acquisition model includes: obtaining each training character and the standard character type corresponding to each training character; calling the initial annotation result acquisition model to obtain the predicted annotation result corresponding to each training character; obtaining a training loss based on the predicted annotation result corresponding to each training character and the standard character type corresponding to each training character; using the training loss to update the parameters of the initial annotation result acquisition model to obtain the target annotation result acquisition model.
[0101] Among them, the predicted annotation result corresponding to any training character is used to indicate the matching probability between any training character and each candidate character type. The standard character type corresponding to any training character is one character type among each candidate character type.
[0102] In an exemplary embodiment, the process of obtaining a training loss based on the predicted annotation results respectively corresponding to each training character and the standard character types respectively corresponding to each training character includes: based on the predicted annotation result corresponding to any one training character, determining the matching probability between the any one training character and the standard character type corresponding to the any one training character, and using the matching probability as the target probability corresponding to the any one training character; and obtaining the training loss based on the target probabilities respectively corresponding to each training character.
[0103] Exemplarily, the process of obtaining a training loss based on the target probabilities respectively corresponding to each training character is implemented based on the following formula 2:
[0104]
[0105] where Loss’ represents the training loss; m (m is an integer not less than 1) represents the number of each training character; Prob k (standard) represents the target probability corresponding to the kth (k is an integer not less than 1 and not greater than m) training character determined based on the predicted annotation result corresponding to the kth training character and the standard character type corresponding to the kth training character.
[0106] In an exemplary embodiment, the process of entity recognition for a query statement can be regarded as the process of entity Mention recognition for the query statement.
[0107] In step 203, at least one candidate graph structure is obtained based on at least one query entity and a knowledge graph.
[0108] In the embodiment of the present application, at least one candidate graph structure is first obtained, and then a candidate graph structure that can more accurately represent the overall structure of the query statement is selected according to the matching degree between the overall structure of the query statement and the candidate graph structure to determine the parsing result of the query statement, so as to ensure the accuracy of the parsing result. This way of obtaining the parsing result is applicable not only to simple query statements including one entity and one attribute, but also to complex query statements including multiple entities and / or multiple attributes, thereby expanding the applicable scenarios of the statement parsing method.
[0109] The overall structure of a query statement can represent the essence of the query statement. For example, what entities does the query statement include, what attributes do the entities included in the query statement have, and what is the association relationship between multiple entities included in the query statement, etc. The overall structure of the query statement can be conveniently represented by a graph structure including nodes and edges. When using the graph structure to represent the overall structure of the query statement, since the graph structure is extensible, no matter how many entities and attributes the query statement includes, the graph structure can be used to represent the overall structure of the query statement. At least one candidate graph structure can be regarded as a predicted graph structure for representing the overall structure of the query statement.
[0110] In one possible implementation manner, the process of obtaining at least one candidate graph structure based on at least one query entity and a knowledge graph includes the following steps 2031 to 2033.
[0111] Step 2031: Determine a target graph structure template, where the target graph structure template is used to constrain the form of a graph structure including a first number of entity nodes, and the first number is the number of at least one query entity.
[0112] In an exemplary embodiment, multiple candidate graph structure templates are stored in a computer device, and each candidate graph structure template is used to constrain the form of a graph structure. Exemplarily, the multiple candidate graph structure templates can be set by a technician. The technician can set the multiple candidate graph structure templates by analyzing common forms of query statements to ensure that the candidate graph structure templates are templates applicable to most scenarios.
[0113] Exemplarily, the multiple candidate graph structure templates include candidate graph structure templates corresponding to multiple candidate numbers respectively, and the candidate graph structure template corresponding to each candidate number includes a template corresponding to one or more transformation relationships (or called jump relationships). The candidate graph structure template corresponding to each candidate number is used to constrain the form of a graph structure including the candidate number of entity nodes. It should be noted that in a graph structure, in addition to including entity nodes, it also includes response result nodes and attribute edges. In some embodiments, the graph structure also includes intermediate transformation result nodes.
[0114] Exemplarily, the candidate numbers include 1, 2, and 3, the transformation relationships include single-hop and double-hop, and the multiple candidate graph structure templates can be as Figure 4 shown. In the Figure 4 shown candidate graph structure template, E represents an entity node, P represents an attribute (or called a relationship) edge, A represents a response result node, and V represents an intermediate transformation result node. In the Figure 4Among them, the candidate graph structure template in the column where a single entity is located is the candidate graph structure template corresponding to the candidate quantity 1, and the candidate graph structure template corresponding to the candidate quantity 1 is used to constrain the form of the graph structure including 1 entity node (E); the candidate graph structure template in the column where two entities are located is the candidate graph structure template corresponding to the candidate quantity 2, and the candidate graph structure template corresponding to the candidate quantity 2 is used to constrain the form of the graph structure including 2 entity nodes (E1 and E2); the candidate graph structure template in the column where three entities are located is the candidate graph structure template corresponding to the candidate quantity 3, and the candidate graph structure template corresponding to the candidate quantity 3 is used to constrain the form of the graph structure including 3 entity nodes (E1, E2, and E3). In some embodiments, the case of two entities can also be referred to as the case of a single entity with a qualifier, and the case of three entities can also be referred to as the case of two entities with a qualifier.
[0115] Exemplarily, based on each candidate graph structure template, a corresponding graph structure can be obtained. The exemplary graph structures corresponding to the candidate graph structure templates can be as Figure 5 shown by the dashed boxes in. Among them, the two graph structures corresponding to the candidate graph structure template in the column where a single entity is located respectively represent the statements "Who is the wife of Star 1" and "What is the nationality of the wife of Star 1", and the statements represented by the other graph structures can be inferred by analogy.
[0116] Take the candidate graph structure template corresponding to the first quantity among multiple candidate graph structure templates as the target graph structure template, and the target graph structure template is used to constrain the form of the graph structure including the first quantity of entity nodes. Among them, the first quantity is the quantity of each query entity identified from the query statement.
[0117] Step 2032: Obtain the candidate entities corresponding to each query entity based on the knowledge graph.
[0118] The candidate entity corresponding to any query entity may refer to the entity with the same name as this any query entity existing in the knowledge graph. The quantity of the candidate entity corresponding to any query entity may be one or multiple, which is related to any query entity and the actual situation of the knowledge graph.
[0119] Exemplarily, taking any query entity as Zhang San, the candidate entities corresponding to this any query entity may include Zhang San, the actor, singer, producer, and lyricist, Zhang San, the assistant to the director of XX Bureau, Zhang San, the professor at X University, Zhang San, the martyr in City A, Zhang San, the deputy director of Bureau B, and Zhang San, the book published by XXX Publishing House, etc.
[0120] Step 2033: Based on the candidate entities corresponding to each query entity respectively, query at least one set of filling data that matches the target graph structure template from the knowledge graph, and use the at least one set of filling data to fill the target graph structure template to obtain at least one candidate graph structure.
[0121] Any set of filled data matches a target graph structure template. The any set of filled data includes a candidate entity corresponding to each query entity and attributes that the candidate entity corresponding to each query entity has in the form of the graph structure constrained by the one target graph structure template. The any set of filled data is queried from the knowledge graph.
[0122] It should be noted that the number of target graph structure templates may be one or multiple. For the case where the number of target graph structure templates is multiple, at least one set of filled data that matches the target graph structure templates may include filled data that respectively matches each target graph structure template, or may only include filled data that matches some of the target graph structure templates, which is related to the candidate entities corresponding to each query entity and the actual situation of the knowledge graph. The filled data that matches any one target graph structure template may be one set or multiple sets, which is also related to the candidate entities corresponding to each query entity and the actual situation of the knowledge graph.
[0123] After obtaining at least one set of filled data that matches the target graph structure template, use the at least one set of filled data to fill the target graph structure template, and use the graph structure obtained after filling as at least one candidate graph structure. It should be noted that using the at least one set of filled data to fill the target graph structure template means using any set of filled data to fill a target graph structure template that matches the any set of filled data.
[0124] Exemplarily, in the process of using any set of filled data to fill a target graph structure template that matches the any set of filled data, use the candidate entities in the any set of filled data to fill the entity nodes (E) in a target graph structure template that matches the any set of filled data, use the attributes in the any set of filled data to fill the attribute edges (P) in a target graph structure template that matches the any set of filled data, and the response result nodes (A) and intermediate conversion result nodes (V) in a target graph structure template that matches the any set of filled data may not be filled.
[0125] Exemplarily, a candidate path can be obtained according to each candidate graph structure, and a candidate path is used to represent a statement. After obtaining at least one candidate graph structure, candidate paths corresponding to each candidate graph structure can also be obtained. Exemplarily, the candidate paths can be as Figure 6 shown Figure 6 The 4 candidate paths in represent the statements "What is the nationality of Star 1", "Who is the director of Movie 1 starred by Star 1", "What is the foreign name of the wife of Star 1", and "What is the nationality of the wife of Star 1", respectively.
[0126] Exemplarily, the process of obtaining at least one candidate graph structure can be referred to as a graph structure recall process.
[0127] In step 204, the matching degree between the overall structure of the query statement and at least one candidate graph structure is obtained, and based on the candidate graph structures whose matching degrees meet the selection conditions, the parsing result of the query statement is determined.
[0128] Among them, the matching degree between the overall structure of the query statement and any candidate graph structure is used to measure the representation accuracy of any candidate graph structure for the overall structure of the query statement. Exemplarily, the matching degree between the overall structure of the query statement and any candidate graph structure is positively correlated with the representation accuracy of any candidate graph structure for the overall structure of the query statement. That is, the higher the matching degree between the overall structure of the query statement and any candidate graph structure, the higher the representation accuracy of any candidate graph structure for the overall structure of the query statement; the lower the matching degree between the overall structure of the query statement and any candidate graph structure, the lower the representation accuracy of any candidate graph structure for the overall structure of the query statement.
[0129] The process of obtaining the matching degree between the overall structure of the query statement and at least one candidate graph structure can be implemented by running a pre-written program or by calling a target matching model. In this embodiment of the application, the process of calling the target matching model to obtain the matching degree between the overall structure of the query statement and at least one candidate graph structure is taken as an example for illustration.
[0130] The target matching model is a model with relatively accurate prediction of the matching degree between the overall structure of the statement and the graph structure. The target matching model is obtained by training an initial matching model. The process of training the target matching model will be described in detail in the Figure 7 illustrated embodiment and will not be elaborated here for the time being.
[0131] The principle of calling the target matching model to obtain the matching degree between the overall structure of the query statement and each candidate graph structure is the same. In this embodiment of the application, the process of calling the target matching model to obtain the matching degree between the overall structure of the query statement and any candidate graph structure is taken as an example for illustration.
[0132] In a possible implementation manner, the target matching model includes a first target feature extraction model, a second target feature extraction model, and a target similarity calculation model. The process of calling the target matching model to obtain the matching degree between the overall structure of the query statement and any candidate graph structure includes: calling the first target feature extraction model to extract features from the query statement to obtain first target features; calling the second target feature extraction model to extract features from any candidate graph structure to obtain second target features; calling the target similarity calculation model to calculate the similarity between the first target features and the second target features, and taking the similarity between the first target features and the second target features as the matching degree between the overall structure of the query statement and any candidate graph structure.
[0133] In an exemplary embodiment, the implementation process of extracting the second target feature by invoking the second target feature extraction model for any candidate graph structure includes: obtaining each target triple corresponding to any candidate graph structure, where any target triple is obtained based on two adjacent nodes in any candidate graph structure and the edge between the two adjacent nodes; invoking the second target feature extraction model to extract features from each target triple respectively to obtain sub-features corresponding to each target triple respectively; and obtaining the second target feature based on the sub-features corresponding to each target triple respectively.
[0134] In an exemplary embodiment, the implementation process of obtaining the second target feature based on the sub-features corresponding to each target triple respectively includes: converting the sub-features corresponding to each target triple respectively into scores corresponding to each target triple respectively; taking the ratio of the score corresponding to any target triple to the total target score as the weight corresponding to any target triple, where the total target score is the sum of the scores corresponding to each target triple respectively; and performing weighted summation on the sub-features corresponding to each target triple respectively based on the weights corresponding to each target triple respectively to obtain the second target feature.
[0135] For the implementation manner of the above process of invoking the target matching model to obtain the matching degree between the overall structure of the query statement and any candidate graph structure, refer to Figure 7 the process of invoking the initial matching model to obtain the matching degree between the overall structure of the sample statement and the positive example graph structure in the embodiment shown, which will not be elaborated here.
[0136] Referring to the process of obtaining the matching degree between the overall structure of the query statement and any candidate graph structure, the matching degree between the overall structure of the query statement and at least one candidate graph structure can be obtained. In an exemplary embodiment, the process of obtaining the matching degree between the overall structure of the query statement and each candidate graph structure can be regarded as a process of sorting each candidate graph structure, and the target matching model can also be called the target sorting model.
[0137] After obtaining the matching degree between the overall structure of the query statement and at least one candidate graph structure, determine the candidate graph structure whose matching degree meets the selection condition, and then determine the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition. The parsing result of the query statement is used to query the answer result from the knowledge graph. The candidate graph structure whose matching degree meets the selection condition is a candidate graph structure that can represent the overall structure of the query statement more accurately. Determining the parsing result based on such a candidate graph structure is beneficial to ensuring the accuracy of the parsing result and improving the accuracy of the answer result queried from the knowledge graph using the parsing result.
[0138] The matching degree meeting the selection condition is set according to experience or flexibly adjusted according to the application scenario, which is not limited in the embodiments of the present application. In an exemplary embodiment, that the matching degree meets the selection condition means that the matching degree is the highest matching degree among the matching degrees of the overall structure of the query statement and each candidate graph structure. In an exemplary embodiment, that the matching degree meets the selection condition means that the matching degree is not less than the matching degree threshold, and the matching degree threshold is set according to experience or flexibly adjusted according to the application scenario.
[0139] The number of candidate graph structures whose matching degree meets the selection condition may be one or multiple. For the case where the number of candidate graph structures whose matching degree meets the selection condition is one, the process of determining the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition may be: using the one candidate graph structure whose matching degree meets the selection condition as the parsing result of the query statement. Exemplarily, if that the matching degree meets the selection condition means that the matching degree is the highest matching degree among the matching degrees of the overall structure of the query statement and each candidate graph structure, then use the candidate graph structure corresponding to the highest matching degree as the parsing result of the query statement.
[0140] For the case where the number of candidate graph structures whose matching degree meets the selection condition is multiple, the process of determining the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition may be: randomly selecting one candidate graph structure from the multiple candidate graph structures whose matching degree meets the selection condition, and using the selected candidate graph structure as the parsing result of the query statement. The process of determining the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition may also be: combining the multiple candidate graph structures whose matching degree meets the selection condition, and using the obtained graph structure after combination as the parsing result of the query statement.
[0141] In an exemplary embodiment, after determining the parsing result of the query statement, it further includes: querying the response result matching the parsing result from the knowledge graph. Exemplarily, the parsing result is a graph structure including the response result node (referred to as the target graph structure), and the process of querying the response result matching the parsing result from the knowledge graph may be: under the constraint of the form of the target graph structure, querying the information for filling the response result node in the target graph structure from the knowledge graph, and using this information as the response result. Exemplarily, the process of querying the response result matching the target graph structure from the knowledge graph may also be: mapping the target graph structure to the knowledge graph, and using the mapping result corresponding to the response result node in the target graph structure as the response result.
[0142] Exemplarily, if the computer device is a terminal, then after obtaining the response result, the terminal can display the response result on the display interface; if the computer device is a server, then after obtaining the response result, the server can send the response result to the terminal so that the terminal can display the response result on the display interface.
[0143] An embodiment of the present application proposes a complex statement parsing method based on graph representation and graph matching. The embodiment of the present application parses the entire query statement into a graph representation structure, which can represent not only simple query statements but also complex query statements. Moreover, this graph structure is extensible, and more types of nodes and edges can be added in the future to facilitate function expansion. In addition, the embodiment of the present application adopts a graph-based matching model, which can better encode the graph structure. Practice shows that the method provided by the embodiment of the present application can significantly improve the effect of parsing complex query statements. In some embodiments, statement parsing can also be referred to as semantic parsing.
[0144] Exemplarily, the embodiment of the present application can be applied to the search (or query) function in an application or a web page, and can serve the knowledge graph-based question-and-answer scenario in accurate question-and-answer in the search (or query) function to answer complex knowledge-based query statements (queries) of users.
[0145] The statement parsing method provided by the embodiment of the present application determines the parsing result of the query statement based on a candidate graph structure whose matching degree with the overall structure of the query statement meets the selection condition. That is to say, the query statement is parsed by considering the overall structure of the query statement. On the basis of considering the overall structure of the query statement, the query statement can be parsed regardless of the number of entities and attributes included in the query statement. The applicable scope of this statement parsing method is relatively wide. In addition, the candidate graph structure whose matching degree with the overall structure of the query statement meets the selection condition can accurately represent the overall structure of the query statement. Determining the parsing result of the query statement based on such a graph structure can ensure the accuracy of the parsing result, and thus improve the accuracy of the response result obtained according to the parsing result.
[0146] Based on the above Figure 1 shown implementation environment, the embodiment of the present application provides a training method for a matching model. The training method for the matching model is executed by a computer device, which can be the terminal 11 or the server 12. The embodiment of the present application does not limit this. As Figure 7 shown, the training method for the matching model provided by the embodiment of the present application includes the following steps 701 to step 704.
[0147] In step 701, a sample statement and positive and negative example graph structures corresponding to the sample statement are obtained.
[0148] Among them, the positive example graph structure is the graph structure corresponding to the overall structure of the sample statement, and the negative example graph structure is a graph structure different from the positive example graph structure.
[0149] The sample statement is any statement with a known positive example graph structure. The positive example graph structure corresponding to the sample statement is the graph structure corresponding to the overall structure of the sample statement, and can also be considered as the standard parsing result represented by the graph structure corresponding to the sample statement. Exemplarily, the positive example graph structure corresponding to the sample statement can also be referred to as the standard graph structure corresponding to the sample statement. The positive example graph structure corresponding to the sample statement can be obtained by a technician representing the sample statement in graph structure. Exemplarily, the number of positive example graph structures corresponding to the sample statement is one.
[0150] Exemplarily, the positive example graph structure corresponding to the sample statement includes nodes corresponding to entities in the sample statement (i.e., entity nodes), edges corresponding to attributes in the sample statement (i.e., attribute edges), and response result nodes of unknown meaning. Exemplarily, if it is necessary to go through multiple conversions (or called jumps) to reach the response result node, the positive example graph structure corresponding to the sample statement also includes intermediate conversion result nodes of unknown meaning. It should be noted that the number of intermediate conversion result nodes is the same as the reference number, and the reference number is the difference between the number of conversions to be passed through and 1.
[0151] Exemplarily, if the sample statement is "Who is the director of movie 1 starring star 2", the positive example graph structure corresponding to the sample statement can be as shown in 501 in Figure 5 ; if the sample statement is "What movies does star 1 star in", the positive example graph structure corresponding to the sample statement can be as shown in 502 in Figure 5 ; if the sample statement is "What works did the person 4 written by star 1 and star 4 star in", the positive example graph structure corresponding to the sample statement can be as shown in 503 in Figure 5 .
[0152] The negative example graph structure corresponding to the sample statement is a graph structure different from the positive example graph structure corresponding to the sample statement. Exemplarily, the number of negative example graph structures corresponding to the sample statement may be one or may be multiple. Exemplarily, the negative example graph structure corresponding to the sample statement can be a graph structure with a relatively high similarity to the positive example graph structure obtained by a technician to improve the training effect of the matching model. Exemplarily, the negative example graph structure corresponding to the sample statement can be selected from existing graph structures different from the positive example graph structure. Exemplarily, the negative example graph structure corresponding to the sample statement can also be randomly generated by a computer device.
[0153] In an exemplary embodiment, the sample statement, the positive example graph structure corresponding to the sample statement, and the negative example graph structure corresponding to the sample statement are stored in the database correspondingly, so that the sample statement, the positive example graph structure corresponding to the sample statement, and the negative example graph structure corresponding to the sample statement can be extracted from the database.
[0154] In an exemplary embodiment, the sample statement and the positive example graph structure corresponding to the sample statement are stored in a database correspondingly, so that the sample statement and the positive example graph structure corresponding to the sample statement can be extracted from the database, and then a graph structure different from the positive example graph structure is randomly generated as the negative example graph structure corresponding to the sample statement.
[0155] Of course, the manner of obtaining the sample statement, the positive example graph structure, and the negative example graph structure corresponding to the sample statement may also be other manners, which are not elaborated one by one in the embodiments of the present application.
[0156] In step 702, the initial matching model is called to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure, and the second matching degree between the overall structure of the sample statement and the negative example graph structure.
[0157] The first matching degree is the matching degree between the overall structure of the sample statement and the positive example graph structure. Exemplarily, the number of positive example graph structures is one, so the number of first matching degrees is also one. The second matching degree is the matching degree between the overall structure of the sample statement and the negative example graph structure. The number of second matching degrees is the same as the number of negative example graph structures. That is to say, the matching degree between the overall structure of the sample statement and each negative example graph structure is one second matching degree.
[0158] The first matching degree between the overall structure of the sample statement and the positive example graph structure and the second matching degree between the overall structure of the sample statement and the negative example graph structure are both obtained by calling the initial matching model. The initial matching model is a matching model to be trained. The matching model is a model that can obtain the matching degree between the overall structure of a statement and a graph structure. The embodiments of the present application do not limit the model structure of the initial matching model, as long as it can obtain the matching degree between the overall structure of a statement and a graph structure. Exemplarily, the initial matching model is a two-tower model, which first processes the statement and the graph structure respectively, and then calculates the matching degree between the two.
[0159] The implementation principle of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure is the same as that of calling the initial matching model to obtain the second matching degree between the overall structure of the sample statement and each negative example graph structure. The embodiments of the present application take the process of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure as an example for illustration.
[0160] In a possible implementation manner, the model structure of the initial matching model is: the initial matching model includes a first feature extraction model, a second feature extraction model, and a similarity calculation model. In this case, the process of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure may include the following steps 7021 to step 7023.
[0161] Step 7021: Invoke the first feature extraction model to extract features from the sample statement, obtaining the first feature.
[0162] The first feature extraction model is a model to be trained for extracting features of statements. The embodiment of the present application does not limit the model structure of the first feature extraction model, and it can be flexibly selected according to actual needs. Exemplarily, the model structure of the first feature extraction model can be a BERT model, a CNN model, an LSTM model, a bidirectional LSTM model, or a GRU model, etc.
[0163] The first feature is used to represent the sample statement. In an exemplary embodiment, the process of invoking the first feature extraction model to extract features from the sample statement and obtaining the first feature includes: inputting the character sequence corresponding to the sample statement into the first feature extraction model, where the character sequence corresponding to the sample statement includes a start flag character, each sample character in the sample statement, and an end flag character; invoking the first feature extraction model to extract features from the character sequence, outputting the features corresponding to each character in the character sequence respectively, and taking the feature corresponding to the start flag character as the first feature. Exemplarily, the start flag character can be [CLS], and the end flag character can be [SEP].
[0164] Exemplarily, the feature corresponding to a character (token) in the character sequence can be in the form of a vector, and can also be referred to as the representation vector of the character in the character sequence. The representation vector of the start flag character can be regarded as the representation vector of the entire sample statement. Therefore, the feature corresponding to the start flag character can be used as the first feature for representing the sample statement.
[0165] In some embodiments, the concatenated feature of the features corresponding to each sample character respectively can also be used as the first feature, etc.
[0166] Step 7022: Invoke the second feature extraction model to extract features from the positive example graph structure, obtaining the second feature.
[0167] The second feature extraction model is a model to be trained for extracting features of graph structures. The embodiment of the present application does not limit the model structure of this second feature model. Exemplarily, the second feature model can be an encoder, and the encoder can include a feature extraction unit and a feature fusion unit. Among them, the feature extraction unit is used to extract the sub-features corresponding to each triple obtained from the graph structure respectively, and the feature fusion unit is used to fuse the sub-features corresponding to each triple obtained from the graph structure respectively to obtain the feature for representing the graph structure.
[0168] In a possible implementation manner, the implementation process of invoking the second feature extraction model to extract features from the positive example graph structure and obtaining the second feature includes the following steps 1 to 3.
[0169] Step 1: Obtain each triple corresponding to the positive example graph structure. Any triple is obtained based on two adjacent nodes in the positive example graph structure and the edge between the two adjacent nodes.
[0170] The positive example graph structure includes nodes corresponding to entities in the sample statement, edges corresponding to attributes in the sample statement, and response result nodes with unknown meanings. Exemplarily, the positive example graph structure further includes intermediate conversion result nodes with unknown meanings. There is an edge between every two adjacent nodes, and each triple is determined based on every two adjacent nodes in the positive example graph structure and the edge between the two adjacent nodes, thereby obtaining each triple corresponding to the positive example graph structure.
[0171] It should be noted that every two adjacent nodes may both be nodes with known meanings (such as nodes corresponding to entities in the sample statement), may both be nodes with unknown meanings (such as response result nodes, intermediate conversion result nodes), or may also include a node with a known meaning and a node with an unknown meaning. The edge between every two adjacent nodes is an edge corresponding to an attribute in the sample statement. The edge between every two adjacent nodes is a directed edge, pointing from the node targeted by the attribute to another node.
[0172] Exemplarily, the process of obtaining any triple based on two adjacent nodes in the positive example graph structure and the edge between the two adjacent nodes includes: using the meaning representation result of the first node among the two adjacent nodes and the meaning representation result of the second node as the first element and the third element respectively, and using the meaning representation result of the edge between the two adjacent nodes as the second element, and forming a triple from the first element, the second element, and the third element. The first node refers to the node where the directed edge starts, and the second node refers to the node where the directed edge points.
[0173] It should be noted that if the meaning of any node is known, then use the meaning of the any node as the meaning representation result of the any node; if the meaning of any node is unknown, then use the identification symbol corresponding to the any node as the meaning representation result of the any node, and the identification character corresponding to any node is used to identify the meaning type of the unknown meaning of the any node (such as intermediate conversion result type, response result type, etc.). Since the meanings of the edges are all known, the meanings of the edges can be used as the meaning representation results of the edges.
[0174] Exemplarily, taking the positive example graph structure as Figure 8Taking the example shown in 801, the node where A is located in 801 represents the response result node with an unknown meaning, and the node where V is located in 801 represents the intermediate conversion result node with an unknown meaning. According to the positive example graph structure shown in 801, two triples can be obtained, and the two triples are respectively (Star 1, wife, V) and (V, nationality, A), where V is an identification character used to identify the type of intermediate conversion result, and A is an identification character used to identify the type of response result. "Star 1" is the meaning of the node corresponding to the entity of Star 1, "wife" is the meaning of the edge corresponding to the attribute of wife, and "nationality" is the meaning of the edge corresponding to the attribute of nationality.
[0175] Step 2: Call the second feature extraction model to extract features from each triple respectively, and obtain the sub-features corresponding to each triple respectively.
[0176] The second feature extraction model may include a feature extraction unit for extracting sub-features corresponding to triples. Invoking the feature extraction unit in the second feature extraction model can extract features from each triple respectively to obtain the sub-features corresponding to each triple respectively.
[0177] In an exemplary embodiment, the feature extraction unit may include a feature extraction layer and a pooling layer. After any triple is input into the second feature extraction model, it can first undergo feature extraction by the feature extraction layer in the feature extraction unit to obtain initial features, and then undergo pooling by the pooling layer to obtain the sub-feature corresponding to the triple. Exemplarily, the pooling layer may be an average pooling layer or a max pooling layer, etc., and the embodiments of the present application do not limit this. Exemplarily, the feature extraction layer may refer to a bidirectional LSTM layer or a GRU layer, etc., and the embodiments of the present application do not limit this.
[0178] Step 3: Based on the sub-features corresponding to each triple respectively, obtain the second feature.
[0179] The second feature is used to characterize the positive example graph structure, and the second feature is obtained based on the sub-features corresponding to each triple respectively. Exemplarily, the second feature extraction model may include a feature fusion unit, and this feature fusion unit can fuse the sub-features corresponding to each triple respectively to obtain the second feature.
[0180] In a possible implementation manner, the process of obtaining the second feature based on the sub-features corresponding to each triple respectively includes: obtaining the weights corresponding to each triple respectively, and based on the weights corresponding to each triple respectively, performing weighted summation on the sub-features corresponding to each triple respectively to obtain the second feature.
[0181] In an exemplary embodiment, the weights corresponding to each triple are obtained based on the sub-features corresponding to each triple. In this case, the second feature can be regarded as a feature obtained based on the self-attention mechanism. Exemplarily, the implementation process of obtaining the weights corresponding to each triple based on the sub-features corresponding to each triple may include: converting the sub-features corresponding to each triple into scores corresponding to each triple; taking the ratio of the score corresponding to any triple to the total score as the weight corresponding to any triple, where the total score is the sum of the scores corresponding to each triple. According to the method of obtaining the weight corresponding to any triple, the weights corresponding to each triple are obtained.
[0182] Exemplarily, converting the sub-features corresponding to each triple into scores corresponding to each triple can be achieved through a conversion layer, and the parameters in this conversion layer determine the conversion method. Exemplarily, the score corresponding to any triple can be calculated based on Equation 3:
[0183] S i = M T tanh(WV i + B) (Equation 3)
[0184] where S i represents the score corresponding to the i-th (i is an integer not less than 1 and not greater than the number of all triples) triple; V i represents the sub-feature corresponding to the i-th triple; M, W, and B are all parameters of the conversion layer, used to convert the sub-feature corresponding to the triple into the score corresponding to the triple.
[0185] After obtaining the scores corresponding to each triple, the sum of the scores corresponding to each triple is taken as the total score, and the ratio of the score corresponding to any triple to the total score is taken as the weight corresponding to any triple. Exemplarily, the weight corresponding to any triple can be obtained based on Equation 4:
[0186]
[0187] where a i represents the weight corresponding to the i-th (i is an integer not less than 1 and not greater than n) triple; S i represents the score corresponding to the i-th triple; S1 + S2 + … + S n represents the total score; n (n is an integer not less than 1) is the number of all triples. Equation 4 can be considered as converting the score corresponding to the triple into a probability distribution through the softmax operation.
[0188] It should be noted that the above-described method for obtaining the weights corresponding to each triple is only an exemplary example, and the embodiments of the present application are not limited thereto. Exemplarily, the weights corresponding to each triple can also be set according to experience. Exemplarily, the weights corresponding to each triple can be set to 1. In this case, the second feature is the sum feature of the sub-features corresponding to each triple. Exemplarily, the weights corresponding to each triple can also be set to 1 / n, where n (n is an integer not less than 1) is the number of each triple. In this case, the second feature is the average feature of the sub-features corresponding to each triple.
[0189] Exemplarily, the second feature can be obtained based on Formula 5:
[0190] V graph = a1V1 + a2V2 + … + a n V n (Formula 5)
[0191] Wherein, V graph represents the second feature; a i represents the weight corresponding to the i-th (i = 1, 2,..., n) triple; V i represents the sub-feature corresponding to the i-th triple.
[0192] Exemplarily, the process of obtaining the second feature can be as Figure 8 shown, obtaining Figure 8 the two triples corresponding to the positive example graph structure shown in 801 in, which are (Star 1, wife, V) and (V, nationality, A); processing the triple (Star 1, wife, V) through a bidirectional LSTM layer and a pooling layer to obtain the sub-feature corresponding to the triple (Star 1, wife, V); processing the triple (V, nationality, A) through a bidirectional LSTM layer and a pooling layer to obtain the sub-feature corresponding to the triple (V, nationality, A); fusing the sub-feature corresponding to the triple (Star 1, wife, V) and the sub-feature corresponding to the triple (V, nationality, A) through a self-attention mechanism to obtain the second feature for characterizing the positive example graph structure.
[0193] Step 7023: Invoke the similarity calculation model to calculate the similarity between the first feature and the second feature, and use the similarity as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
[0194] After obtaining the first feature and the second feature, the similarity calculation model can be invoked to calculate the similarity between the first feature and the second feature, and then the similarity is used as the matching degree between the overall structure of the sample statement and the positive example graph structure.
[0195] Exemplarily, if the dimensions of the first feature and the second feature are the same and both are vectors of the reference dimension, the similarity between the first feature and the second feature may refer to the inner product between the first feature and the second feature. Exemplarily, the similarity between the first feature and the second feature can be calculated based on the following formula 6:
[0196] Score = dot(V query , V graph ) (Formula 6)
[0197] where Score represents the similarity between the first feature and the second feature; dot() represents the inner product calculation; V query represents the first feature; V graph represents the second feature.
[0198] Exemplarily, the process of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure is as Figure 9 shown. Input the character sequence corresponding to the sample statement ([CLS] What is the nationality of the wife of Star 1 [SEP]) into the first feature extraction model to obtain the first feature output by the first feature extraction model for characterizing the sample statement; input the positive example graph structure into the second feature extraction model to obtain the second feature output by the second feature extraction model for characterizing the positive example graph structure; call the similarity calculation model to calculate the similarity between the first feature and the second feature by calculating the inner product of the first feature and the second feature; use the similarity between the first feature and the second feature as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
[0199] It should be noted that the process of implementing the call to the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure based on the above steps 7021 to 7023 is only an exemplary example, and the embodiments of the present application are not limited thereto.
[0200] In some embodiments, the model structure of the initial matching model can also be: the initial matching model includes a graph structure conversion model and a matching degree calculation model, where the graph structure conversion model is used to convert the graph structure into a statement, and the statement matching degree calculation model is used to calculate the matching degree between two statements. In this case, the process of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure can include: calling the graph structure conversion model to convert the positive example graph structure to obtain a reference statement; calling the statement matching degree calculation model to calculate the matching degree between the sample statement and the reference statement, and using the matching degree between the sample statement and the reference statement as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
[0201] Referring to the manner of obtaining the first matching degree between the overall structure of the sample statement and the positive example graph structure by invoking the initial matching model, the process of obtaining the second matching degree between the overall structure of the sample statement and the negative example graph structure can be realized. It should be noted that for the case where the number of negative example graph structures is multiple, it is necessary to invoke the initial matching model to obtain the second matching degree between the sample statement and each negative example graph structure respectively. That is to say, the number of second matching degrees is the same as the number of negative example graph structures.
[0202] In step 703, based on the first difference between the first matching degree and the second matching degree, a target loss is obtained, and the target loss has a negative correlation with the first difference.
[0203] The first matching degree is the matching degree between the overall structure of the sample statement and the positive example graph structure, and the second matching degree is the matching degree between the overall structure of the sample statement and the negative example graph structure. The larger the first difference between the first matching degree and the second matching degree, the more accurately the matching model can distinguish the matching degree between the overall structure of the sample statement and the positive example graph structure, and the matching degree between the overall structure of the sample statement and the negative example graph structure. That is to say, the better the matching degree prediction performance of the matching model. Therefore, obtaining the target loss that has a negative correlation with the first difference can, under the constraint of the target loss, make the matching model update the model parameters in the direction of reducing the target loss, that is, increasing the first difference, so as to continuously improve the matching degree prediction performance of the matching model.
[0204] In an exemplary embodiment, the number of first matching degrees is one, and the number of second matching degrees may be one or multiple. For the case where the number of second matching degrees is one, the first difference refers to the difference between this one first matching degree and this one second matching degree. For the case where the number of second matching degrees is multiple, the first difference refers to the difference between this one first matching value and multiple second matching values.
[0205] Exemplarily, the difference between one first matching value and multiple second matching values (that is, the first difference) may refer to the difference between this one first matching degree and the average value of multiple second matching degrees. This way of determining the first difference takes into account all the second matching degrees and is conducive to ensuring the reliability of the first difference.
[0206] Exemplarily, the difference between one first matching value and multiple second matching values (that is, the first difference) may also refer to the difference between this one first matching degree and a second matching degree randomly selected from multiple second matching degrees. This way of determining the first difference only considers one second matching degree among multiple second matching degrees and is conducive to improving the determination efficiency of the first difference.
[0207] Exemplarily, the difference between one first matching value and multiple second matching values (i.e., the first difference) can also refer to the difference between the one first matching degree and the average value of the second matching degrees that meet the reference condition among the multiple second matching degrees. This way of determining the first difference can achieve a balance between reliability and determination efficiency. The reference condition is set according to experience or flexibly adjusted according to the application scenario, and the embodiments of the present application do not limit this.
[0208] Exemplarily, the second matching degrees that meet the reference condition refer to the top G largest second matching degrees among the multiple second matching degrees, where G is an integer not less than 1 and not greater than H, and H is the number of the multiple second matching degrees, and H is an integer not less than 1. Exemplarily, the second matching degrees that meet the reference condition refer to the second matching degrees not less than the matching degree threshold among the multiple second matching degrees. The matching degree threshold is set according to experience or flexibly adjusted according to the application scenario, and the embodiments of the present application do not limit this.
[0209] After obtaining the first difference between the first matching degree and the second matching degree, based on the first difference, a target loss is obtained. Among them, the target loss has a negative correlation with the first difference. The embodiments of the present application do not limit the implementation manner of obtaining the target loss based on the first difference, as long as it is ensured that the target loss has a negative correlation with the first difference.
[0210] In one possible implementation manner, the implementation manner of obtaining the target loss based on the first difference can be: taking the opposite number of the first difference as the target loss. In another possible implementation manner, the implementation manner of obtaining the target loss based on the first difference can also be: taking the reciprocal of the first difference as the target loss.
[0211] In another possible implementation manner, the number of positive example graph structures and negative example graph structures is both one, that is, the number of the first matching degree and the second matching degree is both one. The one first matching degree and the one second matching degree are both numerical values not greater than the first value and not less than the second value. In this case, the implementation manner of obtaining the target loss based on the first difference can also be: subtracting the first difference from the second difference to obtain a third difference, where the second difference is the difference between the second value and the first value, and taking the maximum value between the third difference and the reference value as the target loss. The first value and the second value are set according to experience or flexibly adjusted according to the application scenario, and the embodiments of the present application do not limit this. For example, the first value is 0 and the second value is 1. The reference value is a numerical value used to ensure that the target loss has a negative correlation with the first difference and can be set according to experience. Exemplarily, the reference value is 0.
[0212] Exemplarily, taking the first value as 0, the second value as 1, and the reference value as 0 as an example, the process of obtaining the target loss based on the first difference is implemented based on the following formula 7:
[0213] Loss=max(0,1-(Score + -Score - )) (Formula 7)
[0214] Where Loss represents the target loss; Score + represents the first matching degree, that is, the matching degree between the overall structure of the sample statement and the positive example graph structure; Score - represents the second matching degree, that is, the matching degree between the overall structure of the sample statement and the negative example graph structure; (Score + -Score - ) represents the first difference.
[0215] In step 704, the model parameters of the initial matching model are updated using the target loss to obtain the target matching model.
[0216] Exemplarily, the process of updating the model parameters of the initial matching model using the target loss can be implemented using the gradient descent method, that is, updating the model parameters of the matching model in the gradient direction of reducing the target loss. Since the target loss is negatively correlated with the first difference between the first matching degree and the second matching degree, updating the model parameters of the matching model in the gradient direction of reducing the target loss can make the matching model train in the direction of increasing the first difference between the first matching degree and the second matching degree. Since the larger the first difference between the first matching degree and the second matching degree is, the better, so by training the matching model in the direction of increasing the first difference between the first matching degree and the second matching degree, it is beneficial to make the trained matching model have a more accurate matching degree prediction function.
[0217] Exemplarily, the process of updating the model parameters of the initial matching model using the target loss to obtain the target matching model includes: using the target loss to reversely update the model parameters of the initial matching model once to obtain the updated matching model; determining whether the updated matching model meets the training termination condition; if the updated matching model meets the training termination condition, then using the updated matching model as the target matching model.
[0218] If the updated matching model does not meet the training termination condition, then a new target loss is obtained based on the methods of steps 701 to 703, and the model parameters of the updated matching model are reversely updated once using the new target loss, and so on, until a matching model that meets the training termination condition is obtained, and the matching model that meets the training termination condition is used as the target matching model. Exemplarily, in the process of obtaining a new target loss based on the methods of steps 701 to 703, the sample statements and the corresponding positive example graph structures and negative example graph structures of the sample statements may or may not change, and the embodiments of the present application do not limit this.
[0219] The training termination condition is set according to experience or adjusted flexibly according to the application scenario, and the embodiments of the present application do not limit this. In an exemplary embodiment, the matching model satisfying the training termination condition includes but is not limited to any of the following: the number of model parameter updates (which can also be referred to as the number of iterations) that have been performed when obtaining the matching model reaches the maximum number of iterations, the target loss on which the obtained matching model is based converges, and the target loss on which the obtained matching model is based is less than the loss threshold. The maximum number of iterations and the loss threshold are set according to experience or adjusted flexibly according to the application scenario, and the embodiments of the present application do not limit this.
[0220] It should be noted that updating the model parameters of the initial matching model using the target loss means updating the model parameters of each model included in the initial matching model using the target loss. Exemplarily, for the case where the initial matching model includes a first feature extraction model, a second feature extraction model, and a similarity calculation model, it is necessary to update the model parameters of the first feature extraction model, the model parameters of the second feature extraction model, and the model parameters of the similarity calculation model using the target loss. The obtained target matching model includes a first target feature extraction model, a second target feature extraction model, and a target similarity calculation model.
[0221] After obtaining the target matching model, during the process of statement parsing, the target matching model can be used to obtain the matching degree between the overall structure of the query statement to be parsed and each candidate graph structure, and then based on the candidate graph structure whose matching degree meets the selection condition, the parsing result of the query statement can be determined. The implementation manner of this process is shown in Figure 2 the embodiments shown, and details are not described herein again.
[0222] The training method of the matching model provided by the embodiments of the present application, the target loss used to update the model parameters of the initial matching model is a loss that is negatively correlated with the difference between the first matching degree and the second matching degree. Using such a loss to train the initial matching model is beneficial to making the initial matching model update the model parameters in the direction of increasing the difference between the first matching degree and the second matching degree. The larger the difference between the first matching degree and the second matching degree, the more accurately the matching model can distinguish the matching degree between the overall structure of the sample statement and the positive example graph structure, and the matching degree between the overall structure of the sample statement and the negative example graph structure, that is, the better the matching degree prediction performance of the matching model. Using this method can train a target matching model that can more accurately predict the matching degree between the overall structure of the statement and the graph structure, thereby providing a basis for the statement parsing process and improving the accuracy of statement parsing.
[0223] See Figure 10 , the embodiments of the present application provide a statement parsing device, and the device includes:
[0224] The first acquisition unit 1001 is configured to acquire a query statement to be parsed and the knowledge graph corresponding to the query statement.
[0225] The recognition unit 1002 is configured to perform entity recognition on the query statement to obtain at least one query entity.
[0226] The second acquisition unit 1003 is configured to acquire at least one candidate graph structure based on at least one query entity and the knowledge graph.
[0227] The third acquisition unit 1004 is configured to obtain the matching degree between the overall structure of the query statement and at least one candidate graph structure, and determine the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition.
[0228] In a possible implementation manner, the second acquisition unit 1003 is configured to determine a target graph structure template, where the target graph structure template is used to constrain the form of a graph structure including a first number of entity nodes, and the first number is the number of at least one query entity; acquire candidate entities corresponding to each query entity respectively based on the knowledge graph; query at least one set of filling data that matches the target graph structure template from the knowledge graph based on the candidate entities corresponding to each query entity respectively, and use the at least one set of filling data to fill the target graph structure template to obtain at least one candidate graph structure.
[0229] In a possible implementation manner, the recognition unit 1002 is configured to extract features of each character in the query statement to obtain character features corresponding to each character respectively; acquire annotation results corresponding to each character respectively based on the character features corresponding to each character respectively, and the annotation result corresponding to any character is used to indicate the matching probability between any character and each candidate character type, and each candidate character type includes an entity type and a non-entity type; determine the highest matching probability among the matching probabilities indicated by the annotation result corresponding to any character, and use the candidate character type corresponding to the highest matching probability as the target character type of any character, and acquire at least one query entity based on the target character types of each character.
[0230] In a possible implementation manner, the third acquisition unit 1004 is configured to call a target matching model to obtain the matching degree between the overall structure of the query statement and at least one candidate graph structure.
[0231] In a possible implementation manner, the apparatus further includes:
[0232] The query unit is configured to query a response result that matches the parsing result from the knowledge graph.
[0233] The statement parsing device provided by the embodiment of the present application determines the parsing result of the query statement based on a candidate graph structure whose matching degree with the overall structure of the query statement meets the selection condition. That is to say, the query statement is parsed by considering the overall structure of the query statement. On the basis of considering the overall structure of the query statement, regardless of the number of entities and attributes included in the query statement, the parsing of the query statement can be realized, and the applicable range of this statement parsing method is relatively wide. In addition, the candidate graph structure whose matching degree with the overall structure of the query statement meets the selection condition can accurately represent the overall structure of the query statement. Determining the parsing result of the query statement based on this graph structure can ensure the accuracy of the parsing result, and thus improve the accuracy of the response result obtained according to the parsing result.
[0234] See Figure 11 , the embodiment of the present application provides a training device for a matching model, and the device includes:
[0235] The fourth acquisition unit 1101 is configured to acquire a sample statement and a positive example graph structure and a negative example graph structure corresponding to the sample statement, where the positive example graph structure is a graph structure corresponding to the overall structure of the sample statement, and the negative example graph structure is a graph structure different from the positive example graph structure;
[0236] The fifth acquisition unit 1102 is configured to call an initial matching model to obtain a first matching degree between the overall structure of the sample statement and the positive example graph structure, and a second matching degree between the overall structure of the sample statement and the negative example graph structure;
[0237] The sixth acquisition unit 1103 is configured to obtain a target loss based on a first difference between the first matching degree and the second matching degree, and the target loss has a negative correlation with the first difference;
[0238] The updating unit 1104 is configured to update the model parameters of the initial matching model by using the target loss to obtain a target matching model.
[0239] In a possible implementation manner, the initial matching model includes a first feature extraction model, a second feature extraction model, and a similarity calculation model. The fifth acquisition unit 1102 is configured to call the first feature extraction model to extract features from the sample statement to obtain first features; call the second feature extraction model to extract features from the positive example graph structure to obtain second features; call the similarity calculation model to calculate the similarity between the first features and the second features, and use the similarity as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
[0240] In a possible implementation manner, the fifth acquisition unit 1102 is configured to acquire each triple corresponding to the positive example graph structure, where any triple is obtained based on two adjacent nodes in the positive example graph structure and the edge between the two adjacent nodes; call the second feature extraction model to perform feature extraction on each triple respectively to obtain sub-features corresponding to each triple respectively; and acquire a second feature based on the sub-features corresponding to each triple respectively.
[0241] In a possible implementation manner, the fifth acquisition unit 1102 is configured to convert the sub-features corresponding to each triple respectively into scores corresponding to each triple respectively; use the ratio of the score corresponding to any triple to the total score as the weight corresponding to any triple, where the total score is the sum of the scores corresponding to each triple respectively; and perform weighted summation on the sub-features corresponding to each triple respectively based on the weights corresponding to each triple respectively to obtain a second feature.
[0242] In a possible implementation manner, both the first matching degree and the second matching degree are values not greater than a first value and not less than a second value. The sixth acquisition unit 1103 is configured to subtract the first difference from the second difference to obtain a third difference, where the second difference is the difference between the second value and the first value; and use the maximum value between the third difference and a reference value as the target loss, where the reference value is a value used to ensure that the target loss has a negative correlation with the first difference.
[0243] The training device for the matching model provided by the embodiments of the present application updates the model parameters of the initial matching model by using a target loss that has a negative correlation with the difference between the first matching degree and the second matching degree. Using such a loss to train the initial matching model is beneficial to making the initial matching model update the model parameters in the direction of increasing the difference between the first matching degree and the second matching degree. The larger the difference between the first matching degree and the second matching degree, the more accurately the matching model can distinguish the matching degree between the overall structure of the sample sentence and the positive example graph structure, and the matching degree between the overall structure of the sample sentence and the negative example graph structure. That is to say, the better the matching degree prediction performance of the matching model. Using this method can train a target matching model that can more accurately predict the matching degree between the overall structure of the sentence and the graph structure, thereby providing a basis for the sentence parsing process and improving the accuracy of sentence parsing.
[0244] It should be noted that when the device provided in the above embodiments implements its functions, only the above-mentioned division of each functional unit is used for illustration. In actual applications, the above functions can be allocated to different functional units according to needs, that is, the internal structure of the device is divided into different functional units to complete all or part of the functions described above. In addition, the device provided in the above embodiments and the method embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments and will not be repeated here.
[0245] In an exemplary embodiment, a computer device is further provided. The computer device includes a processor and a memory, and at least one computer program is stored in the memory. The at least one computer program is loaded and executed by one or more processors, so that the computer device implements the training method of any one of the above statement parsing or matching models. The computer device can be a server or a terminal. Next, the structures of the server and the terminal will be introduced separately.
[0246] Figure 12 FIG. is a schematic structural diagram of a server provided by an embodiment of the present application. The server may vary greatly due to different configurations or performances, and may include one or more processors (Central Processing Units, CPUs) 1201 and one or more memories 1202. Among them, at least one computer program is stored in the one or more memories 1202, and the at least one computer program is loaded and executed by the one or more processors 1201, so that the server implements the statement parsing method or the training method of the matching model provided by each of the above method embodiments. Of course, the server may also have components such as a wired or wireless network interface, a keyboard, and an input / output interface for input / output. The server may also include other components for implementing the functions of the device, which will not be elaborated here.
[0247] Figure 13 FIG. is a schematic structural diagram of a terminal provided by an embodiment of the present application. The terminal may be: a PC, a mobile phone, a smart phone, a PDA, a wearable device, a PPC, a tablet computer, a smart car machine, a smart TV, a smart speaker, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, a VR device, an AR device. The terminal may also be referred to by other names such as a user equipment, a portable terminal, a laptop terminal, a desktop terminal, etc.
[0248] Generally, the terminal includes: a processor 1501 and a memory 1502.
[0249] The processor 1501 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. The processor 1501 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 1501 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1501 may be integrated with a GPU (Graphics Processing Unit), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1501 may further include an AI (Artificial Intelligence) processor, and the AI processor is used to process computational operations related to machine learning.
[0250] The memory 1502 may include one or more computer-readable storage media, and the computer-readable storage media may be non-transitory. The memory 1502 may further include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash storage devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1502 is used to store at least one instruction, and the at least one instruction is to be executed by the processor 1501 so that the terminal implements the statement parsing method or the training method of the matching model provided in the method embodiments of the present application.
[0251] In some embodiments, the terminal may further optionally include: a peripheral device interface 1503 and at least one peripheral device. The processor 1501, the memory 1502, and the peripheral device interface 1503 may be connected by a bus or signal lines. Each peripheral device may be connected to the peripheral device interface 1503 through a bus, signal lines, or a circuit board. Specifically, the peripheral devices include at least one of a radio frequency circuit 1504, a display screen 1505, a camera assembly 1506, an audio circuit 1507, and a power supply 1508.
[0252] The peripheral device interface 1503 can be used to connect at least one I / O (Input / Output) related peripheral device to the processor 1501 and the memory 1502. In some embodiments, the processor 1501, the memory 1502, and the peripheral device interface 1503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1501, the memory 1502, and the peripheral device interface 1503 can be implemented on separate chips or circuit boards, and this embodiment does not limit this.
[0253] The radio frequency circuit 1504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 1504 communicates with a communication network and other communication devices through electromagnetic signals. The radio frequency circuit 1504 converts an electrical signal into an electromagnetic signal for transmission, or converts the received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 1504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and so on. The radio frequency circuit 1504 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes but is not limited to: metropolitan area network, generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area network, and / or WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 1504 may further include a circuit related to NFC (Near Field Communication), and this application does not limit this.
[0254] The display screen 1505 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1505 is a touch display screen, the display screen 1505 also has the ability to collect touch signals on or above the surface of the display screen 1505. The touch signals can be input as control signals to the processor 1501 for processing. At this time, the display screen 1505 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1505, which is provided on the front panel of the terminal; in other embodiments, there may be at least two display screens 1505, which are respectively provided on different surfaces of the terminal or are in a folding design; in other embodiments, the display screen 1505 may be a flexible display screen, which is provided on the curved surface or the folding surface of the terminal. Even further, the display screen 1505 can also be set to an irregular non-rectangular shape, that is, an irregular-shaped screen. The display screen 1505 can be prepared using materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0255] The camera module 1506 is used to capture images or videos. Optionally, the camera module 1506 includes a front camera and a rear camera. Generally, the front camera is provided on the front panel of the terminal, and the rear camera is provided on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth camera, a wide-angle camera, and a telephoto camera, so as to implement functions such as background blurring by fusing the main camera and the depth camera, panoramic shooting and VR shooting functions or other fusion shooting functions by fusing the main camera and the wide-angle camera. In some embodiments, the camera module 1506 may also include a flash. The flash can be a single-color temperature flash or a two-color temperature flash. A two-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation under different color temperatures.
[0256] The audio circuit 1507 may include a microphone and a speaker. The microphone is used to collect sound waves of the user and the environment, and convert the sound waves into electrical signals for input to the processor 1501 for processing, or input to the radio frequency circuit 1504 to achieve voice communication. For the purpose of stereo collection or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal. The microphone may also be an array microphone or an omnidirectional collection microphone. The speaker is used to convert the electrical signal from the processor 1501 or the radio frequency circuit 1504 into sound waves. The speaker may be a traditional thin film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for uses such as ranging. In some embodiments, the audio circuit 1507 may further include a headphone jack.
[0257] The power supply 1508 is used to supply power to each component in the terminal. The power supply 1508 may be alternating current, direct current, a disposable battery or a rechargeable battery. When the power supply 1508 includes a rechargeable battery, the rechargeable battery may support wired charging or wireless charging. The rechargeable battery may also be used to support fast charging technology.
[0258] In some embodiments, the terminal further includes one or more sensors 1509. The one or more sensors 1509 include but are not limited to: an acceleration sensor 1510, a gyroscope sensor 1511, a pressure sensor 1512, an optical sensor 1513, and a proximity sensor 1514.
[0259] The acceleration sensor 1510 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established with the terminal. For example, the acceleration sensor 1510 can be used to detect the components of the gravitational acceleration on the three coordinate axes. The processor 1501 can control the display screen 1505 to display the user interface in a landscape view or a portrait view according to the gravitational acceleration signal collected by the acceleration sensor 1510. The acceleration sensor 1510 can also be used for collecting game or user movement data.
[0260] The gyroscope sensor 1511 can detect the body direction and rotation angle of the terminal. The gyroscope sensor 1511 can cooperate with the acceleration sensor 1510 to collect the 3D actions of the user on the terminal. According to the data collected by the gyroscope sensor 1511, the processor 1501 can implement the following functions: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0261] The pressure sensor 1512 can be disposed on the side frame of the terminal and / or the lower layer of the display screen 1505. When the pressure sensor 1512 is disposed on the side frame of the terminal, it can detect the holding signal of the user for the terminal, and the processor 1501 can perform left / right hand recognition or shortcut operations according to the holding signal collected by the pressure sensor 1512. When the pressure sensor 1512 is disposed on the lower layer of the display screen 1505, the processor 1501 can control the operable controls on the UI interface according to the pressure operation of the user on the display screen 1505. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0262] The optical sensor 1513 is used to collect the ambient light intensity. In one embodiment, the processor 1501 can control the display brightness of the display screen 1505 according to the ambient light intensity collected by the optical sensor 1513. Specifically, when the ambient light intensity is high, the display brightness of the display screen 1505 is increased; when the ambient light intensity is low, the display brightness of the display screen 1505 is decreased. In another embodiment, the processor 1501 can also dynamically adjust the shooting parameters of the camera module 1506 according to the ambient light intensity collected by the optical sensor 1513.
[0263] The proximity sensor 1514, also known as the distance sensor, is usually disposed on the front panel of the terminal. The proximity sensor 1514 is used to collect the distance between the user and the front of the terminal. In one embodiment, when the proximity sensor 1514 detects that the distance between the user and the front of the terminal is gradually decreasing, the processor 1501 controls the display screen 1505 to switch from the lit state to the off state; when the proximity sensor 1514 detects that the distance between the user and the front of the terminal is gradually increasing, the processor 1501 controls the display screen 1505 to switch from the off state to the lit state.
[0264] Those skilled in the art can understand that Figure 13 the structure shown in
[0265] does not limit the terminal, and may include more or fewer components than shown in the figure, or combine some components, or adopt different component arrangements.
[0266] In one possible implementation, the above computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, optical data storage device, etc.
[0267] In an exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program or computer instructions, which are loaded and executed by a processor to enable a computer to implement any of the above statement parsing methods or training methods of a matching model.
[0268] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions. For example, the query statements involved in this application are obtained under full authorization.
[0269] It should be understood that "a plurality of" mentioned herein refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0270] The above are only exemplary embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A statement parsing method, characterized in that, The method includes: Obtaining a query statement to be parsed and the knowledge graph corresponding to the query statement; Performing entity recognition on the query statement to obtain at least one query entity; Determining a target graph structure template, where the target graph structure template is used to constrain the form of a graph structure including a first number of entity nodes, and the first number is the number of the at least one query entity; Obtaining candidate entities corresponding to each query entity respectively based on the knowledge graph; Based on the candidate entities corresponding to each query entity respectively, querying at least one set of filling data that matches the target graph structure template from the knowledge graph, and using the at least one set of filling data to fill the target graph structure template to obtain at least one candidate graph structure; Obtaining the matching degree between the overall structure of the query statement and the at least one candidate graph structure, and determining the parsing result of the query statement based on the candidate graph structure whose matching degree meets the selection condition.
2. The method according to claim 1, wherein The performing entity recognition on the query statement to obtain at least one query entity includes: Performing feature extraction on each character in the query statement to obtain character features corresponding to each character respectively; Based on the character features corresponding to each character respectively, obtaining a labeling result corresponding to each character, and the labeling result corresponding to any character is used to indicate the matching probability between the any character and each candidate character type, and the candidate character types include entity types and non-entity types; Determining the highest matching probability among the matching probabilities indicated by the labeling result corresponding to any character, using the candidate character type corresponding to the highest matching probability as the target character type of the any character, and obtaining the at least one query entity based on the target character types of each character.
3. The method according to claim 1 or 2, characterized in that, The obtaining the matching degree between the overall structure of the query statement and the at least one candidate graph structure includes: Invoking a target matching model to obtain the matching degree between the overall structure of the query statement and the at least one candidate graph structure.
4. The method according to claim 1 or 2, characterized in that, After determining the parsing result of the query statement, the method further includes: Querying a response result that matches the parsing result from the knowledge graph.
5. The method according to claim 3, wherein The target matching model is trained by the following method: Obtaining a sample statement and a positive example graph structure and a negative example graph structure corresponding to the sample statement, where the positive example graph structure is the graph structure corresponding to the overall structure of the sample statement, and the negative example graph structure is a graph structure different from the positive example graph structure; Invoking an initial matching model to obtain a first matching degree between the overall structure of the sample statement and the positive example graph structure, and a second matching degree between the overall structure of the sample statement and the negative example graph structure; Obtaining a target loss based on a first difference between the first matching degree and the second matching degree, and the target loss has a negative correlation with the first difference; Updating the model parameters of the initial matching model using the target loss to obtain the target matching model.
6. The method according to claim 5, wherein The initial matching model includes a first feature extraction model, a second feature extraction model, and a similarity calculation model. The step of calling the initial matching model to obtain the first matching degree between the overall structure of the sample statement and the positive example graph structure includes: Calling the first feature extraction model to extract features from the sample statement to obtain first features; calling the second feature extraction model to extract features from the positive example graph structure to obtain second features; Calling the similarity calculation model to calculate the similarity between the first features and the second features, and using the similarity as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
7. The method according to claim 6, wherein The step of calling the second feature extraction model to extract features from the positive example graph structure to obtain second features includes: Obtaining each triple corresponding to the positive example graph structure, where any triple is obtained based on two adjacent nodes in the positive example graph structure and the edge between the two adjacent nodes; Calling the second feature extraction model to extract features from each of the triples respectively to obtain sub-features corresponding to each of the triples respectively; Based on the sub-features corresponding to each of the triples respectively, obtaining the second features.
8. The method according to claim 7, wherein The step of obtaining the second features based on the sub-features corresponding to each of the triples respectively includes: Converting the sub-features corresponding to each of the triples respectively into scores corresponding to each of the triples respectively; using the ratio of the score corresponding to any triple to the total score as the weight corresponding to the any triple, where the total score is the sum of the scores corresponding to each of the triples respectively; Based on the weights corresponding to each of the triples respectively, performing weighted summation on the sub-features corresponding to each of the triples respectively to obtain the second features.
9. The method according to any one of claims 5-8, characterized in that Both the first matching degree and the second matching degree are values not greater than a first value and not less than a second value. The step of obtaining the target loss based on the first difference between the first matching degree and the second matching degree includes: Subtracting the second difference from the first difference to obtain a third difference, where the second difference is the difference between the second value and the first value; Using the maximum value between the third difference and a reference value as the target loss, where the reference value is a value used to ensure a negative correlation between the target loss and the first difference.
10. A statement parsing device, characterized in that, The device includes: A first acquisition unit configured to acquire a query statement to be parsed and the knowledge graph corresponding to the query statement; An identification unit configured to perform entity identification on the query statement to obtain at least one query entity; A second acquisition unit configured to determine a target graph structure template, where the target graph structure template is used to constrain the form of a graph structure including a first number of entity nodes, and the first number is the number of the at least one query entity; acquiring candidate entities corresponding to each of the query entities respectively based on the knowledge graph; querying at least one set of filling data that matches the target graph structure template from the knowledge graph based on the candidate entities corresponding to each of the query entities respectively, and using the at least one set of filling data to fill the target graph structure template to obtain at least one candidate graph structure; A third acquisition unit, configured to acquire a matching degree between the overall structure of the query statement and the at least one candidate graph structure, and determine a parsing result of the query statement based on a candidate graph structure whose matching degree meets a selection condition.
11. The device according to claim 10, characterized in that, The recognition unit is configured to perform feature extraction on each character in the query statement to obtain a character feature corresponding to each character; based on the character features corresponding to the respective characters, obtain a labeling result corresponding to each character, where the labeling result corresponding to any character is used to indicate a matching probability between the any character and each candidate character type, and the candidate character types include an entity type and a non-entity type; determine a highest matching probability among the matching probabilities indicated by the labeling result corresponding to any character, and use the candidate character type corresponding to the highest matching probability as the target character type of the any character, and obtain the at least one query entity based on the target character types of the respective characters.
12. The device according to claim 10 or 11, characterized in that, The third acquisition unit is configured to call a target matching model to acquire a matching degree between the overall structure of the query statement and the at least one candidate graph structure.
13. The device according to claim 10 or 11, characterized in that, The apparatus further includes: A query unit, configured to query a response result matching the parsing result from the knowledge graph.
14. The device according to claim 12, characterized in that, The apparatus further includes: A fourth acquisition unit, configured to acquire a sample statement, a positive example graph structure, and a negative example graph structure corresponding to the sample statement, where the positive example graph structure is a graph structure corresponding to the overall structure of the sample statement, and the negative example graph structure is a graph structure different from the positive example graph structure. A fifth acquisition unit, configured to call an initial matching model to acquire a first matching degree between the overall structure of the sample statement and the positive example graph structure, and a second matching degree between the overall structure of the sample statement and the negative example graph structure. A sixth acquisition unit, configured to acquire a target loss based on a first difference between the first matching degree and the second matching degree, where the target loss has a negative correlation with the first difference. An update unit, configured to update model parameters of the initial matching model by using the target loss to obtain the target matching model.
15. The device according to claim 14, characterized in that, The initial matching model includes a first feature extraction model, a second feature extraction model, and a similarity calculation model. The fifth acquisition unit is configured to call the first feature extraction model to perform feature extraction on the sample statement to obtain a first feature; call the second feature extraction model to perform feature extraction on the positive example graph structure to obtain a second feature. Call the similarity calculation model to calculate a similarity between the first feature and the second feature, and use the similarity as the first matching degree between the overall structure of the sample statement and the positive example graph structure.
16. The device according to claim 15, wherein The fifth acquisition unit is configured to acquire each triple corresponding to the positive example graph structure, where any triple is obtained based on two adjacent nodes in the positive example graph structure and an edge between the two adjacent nodes; call the second feature extraction model to perform feature extraction on each triple respectively to obtain a sub-feature corresponding to each triple; and obtain the second feature based on the sub-features corresponding to the respective triples.
17. The device according to claim 16, characterized in that, The fifth obtaining unit is configured to convert the sub-features respectively corresponding to the respective triples into scores respectively corresponding to the respective triples; use the ratio of the score corresponding to any one triple to the total score as the weight corresponding to any one triple, where the total score is the sum of the scores respectively corresponding to the respective triples; and perform weighted summation on the sub-features respectively corresponding to the respective triples based on the weights respectively corresponding to the respective triples to obtain the second feature.
18. The device according to any one of claims 14-17, characterized in that, Both the first matching degree and the second matching degree are values not greater than a first value and not less than a second value. The sixth obtaining unit is configured to subtract the first difference from the second difference to obtain a third difference, where the second difference is the difference between the second value and the first value; and use the maximum value between the third difference and a reference value as the target loss, where the reference value is a value for ensuring a negative correlation between the target loss and the first difference.
19. A computer device, characterized in that, The computer device includes a processor and a memory. At least one computer program is stored in the memory, and the at least one computer program is loaded and executed by the processor so that the computer device implements the statement parsing method according to any one of claims 1 to 9.
20. A computer-readable storage medium, characterized in that, At least one computer program is stored in the computer-readable storage medium, and the at least one computer program is loaded and executed by a processor so that a computer implements the statement parsing method according to any one of claims 1 to 9.
21. A computer program product, characterized in that, The computer program product includes a computer program or computer instructions, and the computer program or the computer instructions are loaded and executed by a processor so that a computer implements the statement parsing method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Question analysis method and device, knowledge graph question-answering system and electronic equipment
CN111488441A
Query information processing method and device, storage medium and electronic device
CN111831911A
Model training method and device, equipment and storage medium
CN113821623A