A method, device, computing device and storage medium for entity classification
By constructing a question-and-answer dialogue in entity classification and fusing multiple sets of output results, the prediction inaccurate problem caused by insufficient information in short text is solved, and the accuracy and generalization ability of entity classification are improved.
Patent Information
- Application Number
- CN202110603261.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-31
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2041-05-31
AI Technical Summary
In the prior art, when classification of entities in short text, the prediction results are inaccurate, making it difficult to correctly predict the types of unknown entities.
By combining the entities to be predicted in the short text with known entities to be constructed, the short text is contextually supplemented with the prior knowledge of the known entities, and the output results of multiple sets of question-and-answer conversations are fused to improve the accuracy of the classification model.
By introducing prior knowledge of known entities, the amount of input information is expanded, the accuracy of the entity classification model for the classification of entities to be predicted in short text is improved, and the accuracy and generalization ability of prediction are enhanced.
Smart Images

Figure CN113221573B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing, and in particular to a method, apparatus, computing device and storage medium for entity classification. Background Art
[0002] The entity linking task has been a hot topic in the research and application of natural language processing methods in recent years, and is very useful in scenarios such as the construction of knowledge graphs. Entity linking aims to associate entities in short texts with corresponding entities in knowledge graphs, so as to achieve the purpose of entity interpretation and disambiguation in short texts. The existing knowledge graphs have widely included a large number of entities and are constantly expanding. Despite this, there are still some uncommon entities that do not exist in the knowledge graphs. For these uncommon entities, we can classify them according to their characteristics, and achieve the purpose of entity disambiguation to a certain extent through entity classification tasks. However, short texts containing uncommon entities often have problems such as insufficient information and unclear semantics, which poses a great challenge to correctly predicting the entity types therein. Summary of the invention
[0003] The present application provides an entity classification method, which uses multiple known entities in a short text that exist in a knowledge graph, obtains prior knowledge of the known entities from the knowledge graph as a supplement to the context, constructs multiple groups of question-answering dialogues for an entity to be predicted based on the supplementary information of each known entity, outputs multiple classification predictions obtained based on each group of question-answering dialogues, and finally obtains the classification prediction results for the entity to be predicted. By introducing prior knowledge of known entities in the context into the model input to expand the amount of information, the accuracy of the classification model in classifying the entities to be predicted in short texts can be improved.
[0004] In the first aspect, the present application provides an entity classification method, the method comprising: obtaining an entity to be predicted and at least one known entity in a first text, wherein the entity to be predicted is an entity that does not exist in the knowledge graph, and the at least one known entity is an entity that already exists in the knowledge graph; constructing a question-answering dialogue according to each of the entity to be predicted and the at least one known entity, respectively, to obtain at least one group of question-answering dialogues, wherein each known entity corresponds to a group of question-answering dialogues; respectively inputting at least one group of question-answering dialogues into a trained classification model, to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted, wherein each group of predicted probability distributions in at least one group of predicted probability distributions includes the probability that the entity to be predicted belongs to each category predicted by the classification model, and a group of question-answering dialogues corresponds to a group of predicted probability distributions; determining the category to which the entity to be predicted belongs according to at least one group of predicted probability distributions. In a short text, there are some uncommon entity names that do not exist in the knowledge graph. For these unknown entities, they cannot be associated with an entity in the knowledge graph, but entity classification can be performed according to their characteristics. The biggest problem with entity classification of short texts is that insufficient contextual information leads to inaccurate prediction results. The entities to be predicted are combined with known entities one by one, the original set of inputs is expanded into multiple groups, and finally the output results of multiple sets of inputs are fused to obtain the final prediction result.
[0005] In a possible implementation, a question-answering dialogue is constructed based on the entity to be predicted and each known entity of at least one known entity to obtain at least one group of question-answering dialogues, including: constructing a question text based on the first text and the entity to be predicted; obtaining prior knowledge corresponding to each known entity, the prior knowledge including the category to which the entity belongs; obtaining at least one group of question-answering dialogues based on the prior knowledge corresponding to the question text and each known entity, each group of question-answering dialogues in the at least one group of question-answering dialogues includes the prior knowledge corresponding to the question text and a known entity.
[0006] In addition to the original input text, the prior knowledge of known entities is added in the form of question-answering dialogue to supplement the contextual information. This is equivalent to adding manually annotated information supplements to the input, allowing the model to capture more semantic information and type features to achieve more accurate predictions for the predicted entities.
[0007] In a possible implementation, the question text of each group of question-answer dialogues includes an identifier, and at least one group of question-answer dialogues is input into a trained classification model to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted, including: converting each group of question-answer dialogues into a representation vector; performing feature extraction on the representation vector to obtain a first feature vector; concatenating the feature vector at the position corresponding to the identifier in the first feature vector and the feature vector at the position corresponding to the entity to be predicted in the first feature vector to obtain a second feature vector; and outputting the probability of the entity to be predicted belonging to each category according to the second feature vector to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted.
[0008] The feature vector corresponding to each text contains the context and the text itself, and the feature vector at the identifier position contains the information of the entire sentence pair. Therefore, the feature vectors at the corresponding positions of the identifier and <entity to be predicted> are selected for mean concatenation as the second feature vector used for classification prediction.
[0009] In one possible implementation, determining the category to which the entity to be predicted belongs based on at least one set of prediction probability distributions includes: obtaining the prediction probability that the entity to be predicted belongs to a target category in each set of prediction probability distributions, and determining the mean prediction probability that the entity to be predicted belongs to the target category, where the target category is any one of the entity categories in the prediction probability distribution; obtaining the prediction probability mean distribution corresponding to the entity to be predicted based on the mean prediction probability that the entity to be predicted belongs to each category, determining that the category corresponding to the maximum prediction probability mean is the category to which the entity to be predicted belongs, and the prediction probability mean distribution includes the prediction probability mean that the entity to be predicted belongs to each category.
[0010] For an entity to be predicted, N groups of question-answer dialogues can be constructed in combination with N known entities in the first text. After the constructed N groups of question-answer dialogues are predicted by the classification model, the predicted probability distribution of the N groups of entities to be predicted is obtained. According to the N groups of predicted probability distributions, the predicted probability mean of the entity to be predicted belonging to each category is calculated to obtain the predicted probability mean distribution of the entity to be predicted as the prediction result. According to the predicted probability mean distribution, the category corresponding to the maximum predicted probability mean is determined as the prediction result of the entity to be predicted.
[0011] In one possible implementation, obtaining an entity to be predicted and at least one known entity in a first text includes: segmenting the first text to obtain multiple entities; matching the multiple entities with entities in a knowledge graph, determining entities corresponding to the multiple entities in the first text in the knowledge graph, taking at least one entity in the first text that matches a corresponding entity in the knowledge graph as a known entity, and taking at least one entity in the first text that does not match a corresponding entity in the knowledge graph as an entity to be predicted.
[0012] In a possible implementation, before inputting each group of question-and-answer dialogues into a trained classification model, the method further includes: obtaining a second text, wherein the second text includes a plurality of entities; taking one of the plurality of entities in the second text as a label entity, and taking the other entities among the plurality of entities except the label entity as known entities corresponding to the label entity in the second text; constructing a question-and-answer dialogue according to the label entity and each known entity corresponding to the label entity, respectively, to obtain at least one group of question-and-answer dialogues corresponding to the label entity, wherein each known entity corresponding to the label entity corresponds to a group of question-and-answer dialogues; inputting the at least one group of question-and-answer dialogues corresponding to the label entity into the classification model to be trained for training, to obtain a trained classification model.
[0013] The model loss is calculated based on at least one set of predicted probability distributions, where the model loss is used to represent the error between the predicted result of the classification model and the actual result. The model loss can be calculated based on each set of predicted probability distributions of the labeled entity and the actual probability distribution of the labeled entity, or the model loss can be calculated based on the predicted probability mean distribution of the labeled entity and the actual probability distribution of the labeled entity. The classification model parameters are updated based on the model loss, so that the model loss of the classification model after the model parameters are updated is reduced, and the category prediction of the entity to be predicted is more accurate.
[0014] In a possible implementation, a question-answering dialogue is constructed according to the label entity and each known entity corresponding to the label entity, and obtaining at least one group of question-answering dialogues corresponding to the label entity includes: constructing a question text according to the second text and the label entity; obtaining prior knowledge corresponding to each known entity and prior knowledge corresponding to the label entity; obtaining at least one group of question-answering dialogues corresponding to the label entity according to the question text constructed by the second text and the label entity, the prior knowledge corresponding to each known entity corresponding to the label entity, and the prior knowledge corresponding to the label entity, wherein each group of question-answering dialogues corresponding to the label entity includes the question text constructed by the second text and the label entity, the prior knowledge corresponding to a known entity corresponding to the label entity, and the prior knowledge corresponding to the label entity.
[0015] In a second aspect, the present application provides an entity classification device, which includes: an identification unit, a question-answering dialogue construction unit and a classification prediction unit; the identification unit is used to obtain an entity to be predicted and at least one known entity in a first text, the entity to be predicted is an entity that does not exist in the knowledge graph, and the at least one known entity is an entity that already exists in the knowledge graph; the construction unit is used to construct a question-answering dialogue according to the entity to be predicted and each known entity in the at least one known entity, respectively, to obtain at least one group of question-answering dialogues, wherein each known entity corresponds to a group of question-answering dialogues; the classification prediction unit is used to input at least one group of question-answering dialogues into a trained classification model to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted, wherein each group of predicted probability distributions in the at least one group of predicted probability distributions includes the probability that the entity to be predicted belongs to each category predicted by the classification model, and a group of question-answering dialogues corresponds to a group of predicted probability distributions; the category to which the entity to be predicted belongs is determined according to the at least one group of predicted probability distributions.
[0016] In a third aspect, the present application provides a computing device comprising a processor and a memory; the memory is used to store instructions, and the processor is used to execute the instructions. When the processor executes the instructions, the computing device executes the method described in the first aspect or any possible implementation of the first aspect.
[0017] In a fourth aspect, the present application provides a computer storage medium, wherein the computer storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect or any possible implementation of the first aspect is implemented.
[0018] This application constructs a question-answering dialogue by combining known entities in the text with the entities to be predicted, and supplements the context of the short text knowledge based on the known entities, so that the classification model can judge the entities to be predicted with the help of the types of known entities. A short text can be expanded into n model inputs based on the n known entities therein, and multiple output results are fused and judged, thereby improving the accuracy and generalization ability of the prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A flow chart of an entity classification method provided in an embodiment of the present application;
[0020] Figure 2 A flowchart of a question-and-answer dialogue structure provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of the structure of an entity classification model provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of a process of entity classification provided in an embodiment of the present application;
[0023] Figure 5 A schematic diagram of a classification model training process provided in an embodiment of the present application;
[0024] Figure 6 This is a schematic diagram of the structure of an entity classification model provided by an embodiment of the present application;
[0025] Figure 7 It is a structural diagram of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0027] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0028] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0029] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0030] As used in this specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0031] First, the application scenario of this application is introduced. An entity refers to an object or thing that objectively exists in the real world and can be distinguished from each other. It can be a specific person or thing, or an abstract concept or connection. The entity classification task aims to correctly classify entities that do not exist in the knowledge graph into multiple types. For example, entities can be divided into 24 types including events, people, works, regional places, time calendars, brands, natural geography, games, biology, drugs, food, software, vehicles, website platforms, disease symptoms, organizations, awards, education, culture, constellations, laws and regulations, virtual things, diagnostic treatment plans and others.
[0032] In traditional entity classification tasks, text is directly input into the classification model for entity classification prediction. When training the model, the category of the target entity in the text is simply labeled and then input into the model for training. This method utilizes context information to a certain extent and can solve some entity classification tasks, but the prediction accuracy for short texts is low. For example, in the short text "George Page took the school bus to school, the bus ran out of gas halfway, and Super Wings came to save them", the entity to be predicted "Super Wings" is predicted. Based on the context information in the short text, it is likely that "Super Wings" will be predicted as a "character" type, while the actual classification of "Super Wings" should be "virtual thing". The core problem of inaccurate prediction of short texts is the lack of information, which leads to low classification accuracy of the classification model.
[0033] In order to solve the above problems, the embodiment of the present application supplements the short text by obtaining information about known entities in the short text from the knowledge graph. Since there are multiple known entities in the knowledge graph in the short text, the entities to be predicted are combined with the known entities one by one to construct multiple groups of question-answering dialogues. The question-answering dialogues contain the prior knowledge of the known entities in the knowledge graph. The question-answering dialogues are input into the classification model for classification prediction, and multiple prediction results of the same entity to be predicted are fused as the final prediction result. Among them, the knowledge graph includes mutually related entities and their prior knowledge. Exemplarily, the entity information recorded in the knowledge graph is as follows:
[0034] {"alias":[],
[0035] "subject_id":"10051",
[0036] "data":[
[0037] {"predicate":"Abstract","object":""Mirage" is a song written and composed by Xiong Xianjing and sung by Wu Mochuan."},
[0038] {"predicate":"meaning description","object":"Songs sung by Wu Mochuan"}],
[0039] "type":"Works",
[0040] "subject":"Mirage"}
[0041] Where "alias", "subject_id", "data", "type" and "subject" refer to "entity alias", "entity number", "details", "entity type" and "entity name" respectively.
[0042] The following is an entity classification method provided by this application, see Figure 1 , Figure 1 A flow chart of an entity classification method provided in an embodiment of the present application.
[0043] S101: Obtain an entity to be predicted and at least one known entity in a first text.
[0044] Among them, the entity to be predicted is the entity that does not exist in the knowledge graph, and the known entity is the entity that already exists in the knowledge graph.
[0045] After obtaining the first text, it is first necessary to determine the multiple entities contained in the first text, and determine the entities to be predicted and the known entities among these multiple entities. In an embodiment of the present application, the entities to be predicted and the known entities in the first text can be determined by entity linking, wherein entity linking is to map certain strings in a text to corresponding entities in the knowledge graph. Specifically, firstly, multiple entities in the first text are obtained by a word segmentation method, and then each of these multiple entities is entity linked with the knowledge graph to determine the entities corresponding to the multiple entities in the first text in the knowledge graph, and the entities for which corresponding entities are found in the knowledge graph are taken as known entities, and the entities for which corresponding entities are not found are entities to be predicted that are not included in the knowledge graph, and their categories need to be predicted by a classification model.
[0046] The above-mentioned word segmentation method can be a word list-based word segmentation method or a character-based word segmentation method. The embodiment of the present application is not specifically limited. Among them, the word list-based word segmentation method first divides the sentence into words according to the dictionary, and then finds the best combination of words; the character-based word segmentation method is to form words by characters, first divide the sentence into individual characters, and then combine the characters into words to find the optimal segmentation strategy, which can also be converted into a sequence labeling problem.
[0047] S102: construct a question-answering dialogue according to the entity to be predicted and each known entity in at least one known entity, to obtain at least one group of question-answering dialogues.
[0048] Among them, each known entity corresponds to a set of question-answering dialogues.
[0049] See also Figure 2 , each known entity in the first text can obtain additional supplementary information from the knowledge graph, and a set of question-answering dialogues can be constructed based on the supplementary information of the entity to be predicted and each known entity. If there are multiple entities in the first text, multiple sets of question-answering dialogues can be obtained.
[0050] In a possible implementation, each group of question-answering dialogues includes a question text and prior knowledge of a known entity, wherein the prior knowledge includes the category to which the entity belongs. When constructing a question-answering dialogue based on the entity to be predicted and each known entity of at least one known entity, first, a question text is constructed based on the first text and the entity to be predicted, and then the prior knowledge corresponding to each known entity is obtained. Based on the prior knowledge corresponding to the question text and each known entity, at least one group of question-answering dialogues corresponding to the first text is obtained, wherein each group of question-answering dialogues includes the prior knowledge corresponding to the question text and a known entity.
[0051] Exemplarily, a method for constructing a question-answer dialogue is as follows:
[0052] When the first text is "George Peppa went to school on the school bus, the car ran out of gas halfway, and Super Wings came to save them", the entity to be predicted is "Super Wings", and the known entities are "George", "Peppa", "school bus", "school", "car" and "gas". According to "Super Wings", question-answering dialogues are constructed with the known entities respectively. Taking the known entity "George" as an example, the prior knowledge of "George" obtained from the knowledge graph is "George is a character in the animation "Peppa Pig", and George's type is a virtual thing", and a set of question-answering dialogues can be obtained:
[0053] [“George Page went to school on the school bus. The bus ran out of gas halfway through the journey. Super Wings came to save them. What type of Super Wings is it?”,
[0054] "George is a character in the cartoon Peppa Pig. George's type is a fictional thing"].
[0055] According to the entity to be predicted "Super Wings" and other known entities, question-answering dialogues are constructed according to the above structure, which will not be repeated here.
[0056] S103: Input at least one set of question-answer dialogues into a trained classification model to obtain at least one set of prediction probability distributions corresponding to the entity to be predicted.
[0057] At least one set of question-answer dialogues corresponding to the first text obtained in S102 above is respectively input into the trained classification model to obtain at least one set of predicted probability distributions corresponding to the entity to be predicted. Each set of predicted probability distributions in the at least one set of predicted probability distributions includes the probability that the entity to be predicted belongs to each category predicted by the classification model based on a set of question-answer dialogues, and each set of question-answer dialogues corresponds to a set of predicted probability distributions. For example, if the classification model needs to identify the entity to be predicted as one of 24 categories, each set of predicted probability distributions includes 24 probability values, each of which represents the probability that the entity to be predicted belongs to the corresponding category.
[0058] In one possible implementation, the classification model processes the question-answering dialogue. Figure 3 , Figure 3 A schematic diagram of the structure of an entity classification model provided in an embodiment of the present application. The classification model includes a bidirectional encoder representation from transformers (BERT) model and a SOFTMAX layer.
[0059] After adding the identifier [CLS] before the question text of each set of question-answering dialogues, the BERT model is input. The input question-answering dialogue is converted into a representation vector at the input layer. The feature vector is extracted from the representation vector to obtain the feature vector corresponding to each character in the question-answering dialogue, which is output as the first feature vector. Among them, the feature vector corresponding to each character contains the context and the information of the character itself, and the feature vector at the position of the identifier [CLS] contains the information of the entire sentence pair. Therefore, the feature vector corresponding to the identifier [CLS] and the <entity to be predicted> is selected for classification prediction. The feature vector corresponding to the identifier and the <entity to be predicted> in the output first feature vector are concatenated to obtain the second feature vector and input into the SOFTMAX layer. The SOFTMAX layer outputs the probability that the entity to be predicted belongs to each category based on the second feature vector, and outputs a set of predicted probability distributions of the entity to be predicted. Among them, the predicted probability distribution is the probability that the classification model predicts that the entity to be predicted belongs to each category.
[0060] S104: Determine the category to which the entity to be predicted belongs according to at least one set of prediction probability distributions.
[0061] Multiple groups of question-and-answer dialogues are constructed based on an entity to be predicted and multiple known entities. Multiple groups of prediction probability distributions can be obtained based on the multiple groups of question-and-answer dialogues. Each group of prediction probability distributions contains the prediction probability value of the entity to be predicted belonging to each category. The average value is calculated based on the prediction probability values of the entity to be predicted belonging to each category in the multiple groups of prediction probability distributions, and finally the category to which the entity to be predicted belongs is determined.
[0062] In a possible implementation, for an entity to be predicted, N groups of question-and-answer dialogues can be constructed in combination with N known entities in the first text, and the constructed N groups of question-and-answer dialogues are predicted by the classification model to obtain the predicted probability distribution of the N groups of entities to be predicted. The predicted probability distribution includes the predicted probability value of the entity to be predicted belonging to each category. For the target category, the average value is calculated based on the N predicted probability values of the entity to be predicted belonging to the target category in the N groups of predicted probability distributions to obtain the predicted probability mean of the entity to be predicted belonging to the target category, and the target category is any one of the entity categories in the predicted probability distribution. The predicted probability mean of the entity to be predicted belonging to each category is calculated based on at least one group of predicted probability distributions to obtain the predicted probability mean distribution of the entity to be predicted. According to the predicted probability mean distribution, the category corresponding to the maximum predicted probability mean is determined to be the category to which the entity to be predicted belongs.
[0063] The following example illustrates the entity classification method. The first text "George Page took the school bus to school, the bus ran out of gas, and Super Wings came to save them" is classified. Figure 4 , Figure 4 A schematic diagram of a process of entity classification provided in an embodiment of the present application.
[0064] The first text is segmented and the entities in the short text are determined to be "George", "Peppa", "school bus", "school", "car", "oil" and "Super Wings".
[0065] According to the knowledge graph, a matching model is built, such as an AC state machine, and entities are input into the matching model in sequence for entity matching. The output results are as follows:
[0066] {"text":"George Page is on the school bus going to school, but the bus runs out of gas halfway through, so Super Wings comes to save them",
[0067] "mention_data":
[0068] [{"kb_id":"126702","mention":"George","offset":"0"},
[0069] {"kb_id":"175787","mention":"Page","offset":"2"},
[0070] {"kb_id":"175717","mention":"school bus","offset":"5"},
[0071] {"kb_id":"160800","mention":"Going to school","offset":"8"},
[0072] {"kb_id":"11954","mention":"Car","offset":"14"},
[0073] {"kb_id":"20376","mention":"Oil","offset":"17"},
[0074] {"kb_id":"NIL_VirtualThings","mention":"Super Wings","offset":"20"}]}.
[0075] Among them, text refers to the first text, mention_data refers to the entity contained in the first text, kb_id and mention refer to the entity number and entity name corresponding to the entity in the knowledge graph respectively, and offset refers to the starting position of the entity in the first text.
[0076] The entities "George", "Peppa", "school bus", "go to school", "car", and "oil" are matched to corresponding entities in the knowledge graph and are identified as known entities; the entity "Super Wings" is not matched to a corresponding entity in the knowledge graph and is identified as an entity to be predicted.
[0077] The entities in the knowledge graph are divided into 24 types, including events, people, works, regional places, time calendars, brands, natural geography, games, biology, drugs, food, software, vehicles, website platforms, disease symptoms, organizations, awards, education, culture, constellations, laws and regulations, virtual things, diagnosis and treatment plans, and others. The type of "Super Wings" is a virtual thing, and the type of "Super Wings" needs to be correctly predicted based on the information of the known entities in the context.
[0078] For the first text "George Page took the school bus to school. The car ran out of gas halfway through the journey. Super Wings came to save them", we use the entity to be predicted "Super Wings" and the known entities "George", "Page", "school bus", "school", "car" and "gas" to construct the question-answering dialogue as follows:
[0079] Question and answer dialogue 1: ["George Page took the school bus to school. The bus ran out of gas halfway through the journey. Super Wings came to save them. What type of Super Wings is it?",
[0080] "George is a character in the cartoon Peppa Pig. George's type is a fictional thing"];
[0081] Question and answer dialogue 2: ["George Page took the school bus to school. The bus ran out of gas halfway through the journey. Super Wings came to save them. What type of Super Wings is it?",
[0082] "Peppa is a character in the cartoon Peppa Pig. Peppa's type is a fictional thing"];
[0083] …
[0084] Question and answer dialogue 6: ["George Page took the school bus to school. The bus ran out of gas halfway through the journey. Super Wings came to save them. What type of Super Wings is it?",
[0085] "Oil is a general term for liquid hydrophobic substances at room temperature. The types of oil are other"].
[0086] Taking the first set of question-answer dialogues as an example, the question-answer dialogues ["George Peppa Pig is going to school on the school bus. The bus ran out of gas halfway through the journey. Super Wings came to save them. What type of Super Wings is it?", "George is a character in the cartoon Peppa Pig. George's type is a virtual thing"] are input into the classification model. Among them, the BERT model converts the input text into a representation vector, and then extracts features from the representation vector to obtain the first feature vector output. The feature vectors of [CLS] and the position of the entity to be predicted <Super Wings> are selected for mean concatenation to obtain the second feature vector and input into the SOFTMAX layer. The SOFTMAX layer classifies and predicts the entity to be predicted <Super Wings> based on the second feature vector, and obtains a set of predicted probability distributions of <Super Wings> belonging to 24 categories.
[0087] For the first text "George Page took the school bus to school. The car ran out of gas halfway through the journey. Super Wings came to save them", the entity to be predicted "Super Wings" is combined with the known entities "George", "Page", "school bus", "school", "car" and "gas" in the first text to construct six sets of question-answering dialogues. After prediction by the classification model, the predicted probability distribution of the six sets of entities to be predicted is output:
[0088] George [P10, P11, P12, P13, ..., P1 23 ];
[0089] Page [P20, P21, P22, P23, ..., P2 23 ];
[0090] …
[0091] Oil [P60, P61, P62, P63, ..., P6 23 ].
[0092] P10 indicates that in the question-answering dialogue constructed by combining the entity to be predicted "Super Wings" with the known entity "George", the classification model predicts the probability that the entity to be predicted belongs to the first category; P11 indicates that in the question-answering dialogue constructed by combining the entity to be predicted "Super Wings" with the known entity "George", the classification model predicts the probability that the entity to be predicted belongs to the second category; P20 indicates that in the question-answering dialogue constructed by combining the entity to be predicted "Super Wings" with the known entity "Page", the classification model predicts the probability that the entity to be predicted belongs to the first category.
[0093] For each category, the mean probability of the entity to be predicted belonging to the category is calculated based on all predicted probability distributions. For example, the mean probability P0 is calculated based on the probabilities P10-P60 of the entity to be predicted belonging to the first category in all predicted probability distributions. Finally, the predicted probability mean distribution of the entity to be predicted belonging to each category can be obtained:
[0094] Super Wings [P0, P1, P2, P3, ..., P 23 ].
[0095] Among the 24 prediction probability means, determine that the category corresponding to the maximum prediction probability mean is the category to which the entity to be predicted "Super Wings" belongs, and output it as the prediction result of the classification model for the "Super Wings" category.
[0096] This application constructs a question-answering dialogue by combining known entities in the text with entities to be predicted, and supplements the context of short text knowledge based on known entities, so that the classification model can judge the entities to be predicted with the help of the types of known entities. A short text can be expanded into N model inputs based on N known entities, and multiple output results can be fused and judged, thereby improving the accuracy and generalization ability of prediction.
[0097] The present application also provides a method for training a classification model, see Figure 5 ,Before each set of question and answer dialogue is input into the trained ,classification model, the second text is used to train the classification model.
[0098] S501: Obtain a second text, where the second text includes multiple entities.
[0099] The second text is a training sample containing multiple known entities, and each entity in the second text is an entity existing in the knowledge graph.
[0100] S502: Take one of the multiple entities in the second text as a label entity, and take the other entities among the multiple entities except the label entity as known entities corresponding to the label entity in the second text.
[0101] Each entity in the second text is taken as a label entity, and the remaining entities are taken as known entities. Thus, one second text can be expanded into multiple groups of training samples for training.
[0102] For example, the classification model is trained using the second text "George Page took the school bus to school, the bus ran out of gas halfway, and Super Wings came to save them." The entities "George," "Page," "school bus," "school," "car," "gas," and "Super Wings" are all entities that already exist in the knowledge base.
[0103] Taking "George" as the label entity, "Peppa", "school bus", "school", "car", "oil" and "Super Wings" are six known entities, and the first set of training samples is obtained; taking "Peppa" as the entity to be predicted, "George", "school bus", "school", "car", "oil" and "Super Wings" are six known entities, and the second set of training samples is obtained. Taking each entity in the second text as the entity to be predicted, seven sets of training samples can be obtained to train the classification model, where each set of training samples includes six question-answer dialogues constructed based on a predicted entity and six known entities.
[0104] S503: construct a question-answering dialogue according to the label entity and each known entity corresponding to the label entity, and obtain at least one set of question-answering dialogues.
[0105] Each known entity corresponds to a set of question-answering dialogues. The question-answering dialogue includes a question text and prior knowledge. The question text is constructed according to the second text and an entity to be predicted; the prior knowledge corresponding to each known entity and the prior knowledge corresponding to an entity to be predicted are obtained, and the prior knowledge includes the category to which the entity belongs; at least one set of question-answering dialogues is obtained according to the question text, the prior knowledge corresponding to each known entity, and the prior knowledge corresponding to an entity to be predicted, and each set of question-answering dialogues in at least one set of question-answering dialogues includes the question text, the prior knowledge corresponding to a known entity, and the prior knowledge corresponding to an entity to be predicted.
[0106] For example, taking the first set of training samples in S501 as an example, "George" is used as a label entity, and the actual category of "George" is a virtual thing. The actual category of the label entity is added to the question-answering dialogue as prior knowledge. Then a set of question-answering dialogues constructed by combining the label entity "George" with the known entity "Page" is:
[0107] [“George Page is going to school on the school bus. The bus runs out of gas halfway through the journey. Super Wings comes to save them. What type is <George>?”,
[0108] "Peppa is a character in the cartoon Peppa Pig. Peppa's type is a virtual thing, and George's type is a virtual thing"].
[0109] S504: input at least one group of question-answer dialogues corresponding to the label entity into the classification model to be trained to obtain a trained classification model.
[0110] At least one set of question-answering dialogues is input into the classification model respectively to obtain at least one set of predicted probability distributions corresponding to the label entities, wherein each set of predicted probability distributions in the at least one set of predicted probability distributions includes the probability that the label entity belongs to each category predicted by the classification model, and each set of predicted probability distributions corresponds to a set of question-answering dialogues.
[0111] The model loss is calculated according to at least one set of predicted probability distributions, wherein the model loss is used to represent the error between the predicted result of the classification model and the actual result. In an embodiment of the present application, the model loss can be calculated according to each set of predicted probability distributions of the label entity and the actual probability distribution of the label entity, and the model loss can also be calculated according to the predicted probability mean distribution of the label entity and the actual probability distribution of the label entity. Taking S503 as an example, six groups of question-answering dialogues can be constructed according to the label entity "George" and the known entities "Page", "school bus", "school", "car", "oil" and "Super Wings", and six groups of predicted probability distributions are obtained. A set of model losses can be calculated according to each set of predicted probability distributions, and a total of six sets of model losses are obtained, and the classification model parameters are updated according to each set of model losses. It is also possible to calculate the predicted probability mean distribution of each category of the label entity "George" according to the six sets of predicted probability distributions, and calculate a set of model losses according to the predicted probability mean distribution, and update the classification model parameters according to the model losses.
[0112] The classification model parameters are updated according to the model loss, so that the model loss of the classification model after the model parameters are updated is reduced, and the category prediction of the entity to be predicted is more accurate. The trained classification model is used to perform the method in steps S103-S104 above to predict the category of the entity to be predicted.
[0113] The following describes an entity classification device provided by an embodiment of the present application. Figure 6 The entity classification device 600 includes a recognition unit 610, a construction unit 620 and a classification prediction unit 630;
[0114] The identification unit 610 is used to obtain a to-be-predicted entity and at least one known entity in the first text, wherein the to-be-predicted entity is an entity that does not exist in the knowledge graph, and the at least one known entity is an entity that already exists in the knowledge graph. The identification unit 610 is used to perform the operation described in step S101 above.
[0115] The construction unit 620 is used to construct a question-answering dialogue according to the entity to be predicted and each known entity in the at least one known entity, respectively, to obtain at least one group of question-answering dialogues, wherein each known entity corresponds to a group of question-answering dialogues. The construction unit 620 is used to perform the operation described in the above step S102.
[0116] The classification prediction unit 630 is used to input at least one set of question-answer dialogues into the trained classification model to obtain at least one set of predicted probability distributions corresponding to the entity to be predicted, wherein each set of predicted probability distributions in the at least one set of predicted probability distributions includes the probability of the entity to be predicted belonging to each category predicted by the classification model, and each set of predicted probability distributions corresponds to a set of question-answer dialogues; the category to which the entity to be predicted belongs is determined according to the at least one set of predicted probability distributions. The classification prediction unit 630 is used to perform the operations described in steps S103-S104 above.
[0117] The following is a schematic diagram of a computing device provided in an embodiment of the present application. Figure 7 The computing device 700 includes a module for implementing the operation of the entity classification model training method, including: one or more processors 710, a communication interface 720 and a memory 730. Optionally, the processor 710, the communication interface 720 and the memory 730 are interconnected via a bus 750, wherein the processor 710 is used to execute the above Figure 1 The steps performed in S101-S104 are not repeated here.
[0118] The processor 710 may have a variety of specific implementation forms. For example, the processor 710 may be a central processing unit or an image processor. The processor 710 may also be a single-core processor or a multi-core processor. The processor 710 may also be a combination of a CPU and a hardware chip.
[0119] The communication interface 720 may be a wired interface or a wireless interface for communicating with other modules or devices. The wired interface may be an Ethernet interface, a local interconnect network (LIN), etc., and the wireless interface may be a cellular network interface or a wireless local area network interface, etc.
[0120] The memory 730 may be a non-volatile memory, such as a read-only memory (ROM), a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), or a flash memory. The memory 730 may also be a volatile memory, which may be a random access memory (RAM) used as an external cache.
[0121] The memory 730 may also be used to store instructions and data, so that the processor 710 calls the instructions stored in the memory 730 to implement the operations performed in the above S101-S104. In addition, the computing device 700 may include a Figure 7 Show more or fewer components, or have different component configurations.
[0122] The bus 750 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus 750 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0123] Optionally, the computing device 700 may further include an input / output interface 740 , to which an input / output device is connected for receiving input information and outputting operation results.
[0124] An embodiment of the present application also provides a non-volatile computer-readable storage medium, in which a computer program is stored. When the computer program runs on a processor, the method steps performed in the above method embodiment can be implemented. The specific implementation of the processor of the computer storage medium in executing the above method steps can refer to the specific operations of S101-S104 in the above method embodiment, which will not be repeated here.
[0125] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0126] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices, electronic devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0127] In the several embodiments provided in the present application, it should be understood that the disclosed devices, electronic devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.
[0128] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0129] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0130] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. An entity classification method, characterized in that: The method comprises: Obtaining an entity to be predicted and at least one known entity in the first text, wherein the entity to be predicted is an entity that does not exist in the knowledge graph, and the at least one known entity is an entity that already exists in the knowledge graph; Constructing a question-answering dialogue according to the entity to be predicted and each of the at least one known entity, respectively, to obtain at least one group of question-answering dialogues, wherein each of the known entities corresponds to a group of question-answering dialogues; Inputting the at least one set of question-answer dialogues into the trained classification model respectively to obtain at least one set of predicted probability distributions corresponding to the entity to be predicted, wherein each set of predicted probability distributions in the at least one set of predicted probability distributions includes the probability of the entity to be predicted belonging to each category predicted by the classification model, and a set of question-answer dialogues corresponds to a set of predicted probability distributions; Determining the category to which the to-be-predicted entity belongs according to the at least one set of prediction probability distributions; Wherein, constructing a question-answering dialogue according to the entity to be predicted and each known entity in the at least one known entity to obtain at least one group of question-answering dialogues respectively includes: constructing a question text according to the first text and the entity to be predicted; obtaining prior knowledge corresponding to each known entity, the prior knowledge including the category to which the entity belongs; obtaining the at least one group of question-answering dialogues according to the prior knowledge corresponding to the question text and each known entity, each group of question-answering dialogues in the at least one group of question-answering dialogues including the prior knowledge corresponding to the question text and a known entity; The question text of each group of question-and-answer dialogues includes an identifier in front of it, and the inputting of the at least one group of question-and-answer dialogues into the trained classification model to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted includes: converting each group of question-and-answer dialogues into a representation vector; performing feature extraction on the representation vector to obtain a first feature vector; concatenating the feature vector at the position corresponding to the identifier in the first feature vector and the feature vector at the position corresponding to the entity to be predicted in the first feature vector to obtain a second feature vector; and outputting the probability of the entity to be predicted belonging to each category according to the second feature vector to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted.
2. The method according to claim 1, characterized in that Determining the category to which the to-be-predicted entity belongs according to the at least one set of prediction probability distributions includes: Obtaining the predicted probability that the entity to be predicted belongs to a target category in each group of predicted probability distributions, and determining the mean predicted probability that the entity to be predicted belongs to the target category, where the target category is any one of the entity categories in the predicted probability distributions; According to the mean predicted probability that the entity to be predicted belongs to each category, the predicted probability mean distribution corresponding to the entity to be predicted is obtained, and the category corresponding to the maximum predicted probability mean is determined to be the category to which the entity to be predicted belongs. The predicted probability mean distribution includes the predicted probability mean that the entity to be predicted belongs to each category.
3. The method according to claim 2, characterized in that The obtaining of the to-be-predicted entity and at least one known entity in the first text comprises: Segmenting the first text to obtain multiple entities; Match the multiple entities with entities in the knowledge graph, determine the entities corresponding to the multiple entities in the first text in the knowledge graph, take at least one entity in the first text that matches the corresponding entity in the knowledge graph as a known entity, and take at least one entity in the first text that does not match the corresponding entity in the knowledge graph as an entity to be predicted.
4. The method according to claim 2, characterized in that: Before inputting each group of the question-answer dialogues into the trained classification model, the method further includes: Acquire a second text, where the second text includes a plurality of entities; Taking one of the multiple entities in the second text as a label entity, and taking other entities among the multiple entities except the label entity as known entities corresponding to the label entity in the second text; Constructing the question-answer dialogue according to the label entity and each known entity corresponding to the label entity, respectively, to obtain at least one group of question-answer dialogues corresponding to the label entity, wherein each known entity corresponding to the label entity corresponds to a group of question-answer dialogues; At least one set of question-answer dialogues corresponding to the label entity is input into the classification model to be trained for training to obtain a trained classification model.
5. The method according to claim 4, characterized in that The step of constructing the question-answer dialogue according to the label entity and each known entity corresponding to the label entity to obtain at least one set of question-answer dialogues corresponding to the label entity comprises: Constructing a question text according to the second text and the label entity; Acquire the prior knowledge corresponding to each known entity and the prior knowledge corresponding to the label entity; Based on the question text constructed by the second text and the label entity, the prior knowledge corresponding to each known entity corresponding to the label entity and the prior knowledge corresponding to the label entity, at least one group of question-answer dialogues corresponding to the label entity is obtained, and each group of question-answer dialogues in the at least one group of question-answer dialogues corresponding to the label entity includes the question text constructed by the second text and the label entity, the prior knowledge corresponding to a known entity corresponding to the label entity and the prior knowledge corresponding to the label entity.
6. An entity classification device, the device being used to execute the method according to any one of claims 1 to 5, characterized in that: The device comprises: an identification unit, a construction unit and a classification prediction unit; The recognition unit is used to obtain a to-be-predicted entity and at least one known entity in the first text, wherein the to-be-predicted entity is an entity that does not exist in the knowledge graph, and the at least one known entity is an entity that already exists in the knowledge graph; The construction unit is used to construct a question-answering dialogue according to the entity to be predicted and each known entity of the at least one known entity, respectively, to obtain at least one group of question-answering dialogues, wherein each known entity corresponds to a group of question-answering dialogues; The classification prediction unit is used to input the at least one group of question-answering dialogues into the trained classification model to obtain at least one group of predicted probability distributions corresponding to the entity to be predicted, wherein each group of predicted probability distributions in the at least one group of predicted probability distributions includes the probability of the entity to be predicted belonging to each category predicted by the classification model, and a group of question-answering dialogues corresponds to a group of predicted probability distributions; The category to which the to-be-predicted entity belongs is determined according to the at least one set of prediction probability distributions.
7. A computing device, characterized in that The computing device comprises a processor and a memory; the memory is used to store instructions, the processor is used to execute the instructions, and when the processor executes the instructions, the computing device executes the method according to any one of claims 1 to 5.
8. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Question answering method, electronic equipment and computer readable storage medium
CN110532368A
Knowledge graph question-answering method and device
CN111639171A