Knowledge extraction method, device, equipment and storage medium
By calculating the correlation between the statements to be extracted and the attribute relationship and using the reading comprehension model to be extracted, the problem of poor knowledge extraction flexibility in the existing technology is solved, and high-accurate knowledge extraction is achieved.
Patent Information
- Application Number
- CN202111175771.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-09
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2041-10-09
AI Technical Summary
The prior art has poor flexibility in knowledge extraction, and it is difficult to extract triplets from sentences to be extracted that have not been edited in a limited sentence structure.
By obtaining the statement to be extracted and multiple attribute relationships, calculating the correlation degree, determining the target attribute relationship, and inputting it into the reading comprehension model, the entity with the target attribute relationship is determined.
It improves the flexibility of knowledge extraction, and can accurately extract the entity and target attribute relationships with target attribute relationships from the sentences to be extracted that have not been edited according to the limited sentence structure, and the extraction results are highly accurate.
Smart Images

Figure CN113935326B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a knowledge extraction method, device, equipment and storage medium. Background Art
[0002] In the related art, the attribute relationship between entities in the sentence to be extracted can be extracted by knowledge extraction, and a triple is output according to the extraction result, wherein the triple is composed of a first entity, a second entity and the attribute relationship between the two entities. For example, for the sentence to be extracted "The capital of China is Beijing", the triple <China, capital, Beijing> can be output, wherein "China" is the first entity, "Beijing" is the second entity, and "capital" is the attribute relationship between "China" and "Beijing". The premise for successfully extracting triples from the sentence to be extracted is that the sentence to be extracted needs to be edited through a limited sentence structure. However, in actual applications, there are many ways to edit information. If the sentence to be extracted is not edited according to a limited sentence structure, it is difficult to extract triples from the sentence to be extracted. The flexibility of the knowledge extraction method in the related art is poor. Summary of the invention
[0003] The embodiments of the present invention provide a knowledge extraction method, apparatus, device and storage medium to improve the flexibility of knowledge extraction.
[0004] In a first aspect, an embodiment of the present invention provides a knowledge extraction method, the method comprising:
[0005] Acquire a sentence to be extracted and a plurality of attribute relationships, wherein the attribute relationships are used to describe the connections between different entities in the sentence to be extracted;
[0006] Determine the relevance between the sentence to be extracted and each attribute relationship;
[0007] Based on the relevance, determining a target attribute relationship included in the sentence to be extracted from the multiple attribute relationships;
[0008] Inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determining an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model;
[0009] Output entities having the target attribute relationship and the target attribute relationship.
[0010] In a second aspect, an embodiment of the present invention provides a knowledge extraction device, including:
[0011] An acquisition module, used to acquire a sentence to be extracted and a plurality of attribute relationships, wherein the attribute relationships are used to describe the connections between different entities in the sentence to be extracted;
[0012] A calculation module, used to determine the correlation between the sentence to be extracted and each attribute relationship;
[0013] A determination module, configured to determine, based on the relevance, a target attribute relationship included in the sentence to be extracted from among the multiple attribute relationships;
[0014] An extraction module, used for inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determining an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model;
[0015] An output module is used to output entities having the target attribute relationship and the target attribute relationship.
[0016] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the knowledge extraction method in the first aspect.
[0017] In a fourth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor can at least implement the knowledge extraction method in the first aspect.
[0018] By adopting the method provided by the embodiment of the present invention, the correlation between the sentence to be extracted and the attribute relationship can be calculated, the target attribute relationship contained in the sentence to be extracted can be matched based on the correlation, and then the entity with the target attribute relationship in the sentence to be extracted can be determined through the reading comprehension model. In this way, even if the sentence to be extracted is not edited according to the specified sentence structure, the entity with the target attribute relationship and the target attribute relationship can still be accurately extracted from the sentence to be extracted based on the semantics of the sentence to be extracted and the attribute relationship, and the flexibility of knowledge extraction is high and the accuracy of the extraction result is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 A schematic diagram of a flow chart of a knowledge extraction method provided by an embodiment of the present invention;
[0021] Figure 2A schematic diagram of vector model training provided by an embodiment of the present invention;
[0022] Figure 3 A schematic diagram of using a reading comprehension model provided by an embodiment of the present invention;
[0023] Figure 4 A schematic diagram of a flow chart of another knowledge extraction method provided by an embodiment of the present invention;
[0024] Figure 5 A schematic diagram of the structure of a knowledge extraction device provided by an embodiment of the present invention;
[0025] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two.
[0028] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0029] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0030] The embodiment of the present invention provides a knowledge extraction method, which can be executed in an electronic device. The electronic device may include a commercial service robot, a sweeping robot, a floor scrubber, a kitchen robot, a smart speaker, a smart phone, and other devices with voice recognition and control functions and capable of voice interaction. Figure 1A flow chart of a knowledge extraction method provided by an embodiment of the present invention is as follows: Figure 1 As shown, the method comprises the following steps:
[0031] 101. Obtain a sentence to be extracted and multiple attribute relationships, wherein the attribute relationship is used to describe the connection between different entities in the sentence to be extracted.
[0032] 102. Determine the relevance between the sentence to be extracted and each attribute relationship.
[0033] 103. Based on the relevance, determine the target attribute relationship included in the sentence to be extracted from multiple attribute relationships.
[0034] 104. Input the target attribute relationship and the sentence to be extracted into the reading comprehension model, and determine the entity with the target attribute relationship in the sentence to be extracted based on the result output by the reading comprehension model.
[0035] 105. Output entities with target attribute relationships and target attribute relationships.
[0036] The above-mentioned sentence to be extracted may be composed of multiple entities, and the entity may specifically be a phrase. There may be connections between different entities, and the connections between different entities can be described by attribute relationships. It should be noted that the sentence to be extracted may contain one attribute relationship, may contain multiple attribute relationships, or may not contain any attribute relationship. The method provided in the embodiment of the present invention can be used to determine whether the sentence to be extracted contains an attribute relationship, and if it contains an attribute relationship, which attribute relationships are specifically included. The process of extracting entities with attribute relationships and the attribute relationships between entities from the sentence to be extracted can be called a knowledge extraction process.
[0037] In practical applications, a large number of words used to describe attribute relationships can be collected in advance, such as words such as author, address, nationality, price, etc., and then the correlation between the sentence to be extracted and each of the above words is calculated. If the correlation between the sentence to be extracted and certain attribute relationships is high, it means that the possibility of these attribute relationships being contained in the sentence to be extracted is high. Based on this, the target attribute relationship contained in the sentence to be extracted can be determined from multiple attribute relationships based on the correlation. The method of matching the target attribute relationship contained in the sentence to be extracted from multiple attribute relationships based on the correlation can increase the speed of determining the target attribute relationship, and can also improve the accuracy of extracting the target attribute relationship. By matching the sentence to be extracted and the attribute relationship for correlation, the attribute relationship implicitly contained in the sentence to be extracted can be extracted.
[0038] Optionally, the above process of calculating the correlation between the sentence to be extracted and each attribute relationship can be implemented as follows: input the sentence to be extracted into the first machine learning model to obtain the sentence vector corresponding to the sentence to be extracted; obtain the relationship vectors corresponding to multiple attribute relationships, wherein the relationship vectors are obtained by inputting the multiple attribute relationships into the second machine learning model in advance; determine the distance between the sentence vector and each relationship vector as the correlation between the sentence to be extracted and each attribute relationship.
[0039] The first machine learning model is used to map the sentence to be extracted into a sentence vector, and the second machine learning model is used to map the attribute relationship into a relationship vector. It can be understood that the sentence vector or the relationship vector can be considered as a point in the n-dimensional space, and there is a distance between points. Based on this, the distance between the sentence vector and the relationship vector is calculated, and the correlation between the sentence to be extracted and the corresponding attribute relationship can be obtained.
[0040] In order to improve the extraction efficiency of the knowledge extraction method provided by the embodiment of the present invention, multiple attribute relationships can be pre-input into the second machine learning model respectively, and the second machine learning model outputs the relationship vectors corresponding to each attribute relationship. These relationship vectors can then be stored in a relationship database. In this way, when the relationship vector is used, the mapped relationship vector can be directly read from the relationship database without the need for real-time mapping, and remapping of the relationship vector each time it is used can be avoided, thereby improving the efficiency of knowledge extraction.
[0041] The first machine learning model and the second machine learning model can be set as two parts of the same machine learning model, and the overall machine learning model can be called a vector model. The training process of the vector model will be described below.
[0042] The vector model can be trained by contrastive learning, that is, positive samples and negative samples are used as samples to train the vector model. The data form of the training samples can be: sentence-attribute relationship. An example of training is Figure 2 As shown. Assume that the sentences to be extracted include "The author of Journey to the West is Wu Chengen", "Company A is located at No. 18 Youxiang Road", "James is from the United States", "This mobile phone sells for 9600, which is too expensive", and the correct attribute relationships contained in these sentences to be extracted are "author", "address", "nationality", and "price" respectively. The sentences to be extracted and the correct attribute relationships they contain can be used as positive samples, and the sentences to be extracted and the incorrect attribute relationships they do not contain can be used as negative samples to train the vector model. For example, "The author of Journey to the West is Wu Chengen" and "nationality" can be combined together as a negative sample. In Figure 2 In the example shown, the sentences to be extracted and the attribute relationship as positive samples are connected by solid lines, and the sentences to be extracted and the attribute relationship as negative samples are connected by dotted lines.
[0043] After obtaining positive samples and negative samples, the vector model can be trained based on the positive samples and negative samples. During the training process, the vector model can be trained with the following goal as the training goal: to make the distance between the sentences to be extracted with the correct corresponding relationship and the vectors corresponding to the attribute relationship in the positive samples small, and to make the distance between the sentences to be extracted without the correct corresponding relationship and the vectors corresponding to the attribute relationship in the negative samples large. In this way, after the vector model is trained, when the sentence to be extracted is input, if the sentence to be extracted contains a certain attribute relationship, the distance between the vectors corresponding to them is small, and if the sentence to be extracted does not contain a certain attribute relationship, the distance between the vectors corresponding to them is large. Based on this, the trained vector model can identify the connection between the sentence to be extracted and a certain attribute relationship.
[0044] The method introduced above can be used to calculate the distances corresponding to the sentence vector and multiple relationship vectors respectively. Then, in each relationship vector, a preset number of target relationship vectors whose distances from the sentence vector meet preset conditions can be determined, and the attribute relationship corresponding to the target relationship vector can be determined as the target attribute relationship contained in the sentence to be extracted.
[0045] In practical applications, the relationship vectors can be sorted in ascending order of distance from the sentence vector, and then a preset number of target relationship vectors ranked first are selected, and the attribute relationships corresponding to the target relationship vectors are determined as the target attribute relationships contained in the sentence to be extracted.
[0046] After determining the target attribute relationship contained in the sentence to be extracted, the target attribute relationship and the sentence to be extracted may be input into a reading comprehension model, and entities having the target attribute relationship in the sentence to be extracted may be determined based on the result output by the reading comprehension model.
[0047] It should be noted that the above reading comprehension model can be an improved reading comprehension model. For the reading comprehension model, before the improvement, the question and the passage containing the answer to the question can be input into the reading comprehension model, and then the starting position and ending position of the answer in the passage can be determined according to the result output by the reading comprehension model. In the process of improving the reading comprehension model, the reading comprehension model can be improved by replacing the training samples, changing the output mode of the model output layer, etc. After the improvement, Figure 3As shown, the reading comprehension model can output a result based on the sentence D to be extracted and the target attribute relationship P, and then determine the entities with the target attribute relationship in the sentence to be extracted according to the output result. The output result can be data representing a probability distribution, specifically, it can be the probabilities that each character in the sentence to be extracted becomes the starting character of the first entity S, the ending character of the first entity S, the starting character of the second entity O, and the ending character of the second entity O. Among them, the first entity and the second entity are entities with the target attribute relationship.
[0048] For example, for the sentence "The author of Journey to the West is Wu Chengen", the character "作" can become the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, or the ending character of the second entity. And the probabilities that the character "作" actually becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity respectively correspond to certain probabilities. The reading comprehension model provided by the embodiments of the present invention can calculate such probabilities. After the reading comprehension model outputs the result, based on the probabilities that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity, the entities with the target attribute relationship in the sentence to be extracted can be determined.
[0049] Optionally, the process of determining the entities with the target attribute relationship in the sentence to be extracted based on the probabilities that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity can be implemented as follows: generating a first entity candidate set and a second entity candidate set based on the characters in the sentence to be extracted, where the first entity candidate set includes at least one candidate entity, and the second entity candidate set includes at least one candidate entity; determining the first entity in the first entity candidate set and the second entity in the second entity candidate set based on the probabilities that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity.
[0050] The candidate entities included in the above first entity candidate set and second entity candidate set can be the same. The embodiments of the present invention provide a way to generate the first entity candidate set and the second entity candidate set: for the target character in the sentence to be extracted, determining the target character as the starting character of the candidate entity, and sequentially determining the characters other than the target character in the sentence to be extracted as the ending characters of the candidate entity, to obtain the first entity candidate set and the second entity candidate set, where the target character is any character in the sentence to be extracted.
[0051] For example, the sentence "The author of Journey to the West is Wu Chengen" has a total of 10 characters. If "Xi" is taken as the starting character of the first entity and "You" as the ending character of the first entity, then the first entity obtained is "Xi You"; if "Xi" is taken as the starting character of the first entity and "Ji" as the ending character of the first entity, then the first entity obtained is "Journey to the West"; and if "You" is taken as the starting character of the first entity and "Zuo" as the ending character of the first entity, then the first entity obtained is "You Ji De Zuo".
[0052] The above method can be used to determine all possible combinations of characters, obtaining a candidate set for the first entity and a candidate set for the second entity. To improve the efficiency of knowledge extraction, the candidate set for the first entity and the candidate set for the second entity can be screened to delete combinations of characters that have no practical meaning. Specifically, in the sentence to be extracted, combinations of characters of the starting character after the ending character can be deleted. For example, assuming that "Wu" in "The author of Journey to the West is Wu Chengen" is taken as the starting character and "Zuo" as the ending character, obviously the combination of characters where the position of the starting character is after the ending character is unreasonable, so such combinations of characters can be filtered out.
[0053] The following introduces the method of determining the first entity in the candidate set for the first entity and the second entity in the candidate set for the second entity based on the output result of the reading comprehension model:
[0054] For the target candidate entity in the candidate set for the first entity, determine the probability that the starting character constituting the target candidate entity becomes the starting character of the first entity, determine the probability that the ending character constituting the target candidate entity becomes the ending character of the first entity, and calculate the first sum value of the determined probabilities, where the target candidate entity is any candidate entity in the candidate set for the first entity; for the target candidate entity in the candidate set for the second entity, determine the probability that the starting character constituting the target candidate entity becomes the starting character of the second entity, determine the probability that the ending character constituting the target candidate entity becomes the ending character of the second entity, and calculate the second sum value of the determined probabilities, where the target candidate entity is any candidate entity in the candidate set for the second entity; in the candidate set for the first entity, determine the candidate entity with the largest first sum value as the first entity, and in the candidate set for the second entity, determine the candidate entity with the largest second sum value as the second entity.
[0055] For example, the sentence to be extracted is "The author of Journey to the West is Wu Chengen". Suppose currently, "you" is the starting character of the first entity and "zuo" is the ending character of the first entity, then the target candidate entity is "youji de zuo". The probability that "you" is the starting character of the first entity is 0.2, and the probability that "zuo" is the ending character of the first entity is 0.1. Then the first sum value corresponding to "youji de zuo" is 0.3. Among them, as described above, the probability that each character becomes the starting character or the ending character of a different entity can be obtained by looking up the output result of the reading comprehension model.
[0056] Using the method introduced above, the first sum value corresponding to any candidate entity in the first entity candidate set and the second sum value corresponding to any candidate entity in the second entity candidate set can be calculated. Then, the candidate entity with the largest first sum value in the first entity candidate set can be determined as the first entity, and the candidate entity with the largest second sum value in the second entity candidate set can be determined as the second entity. For example, taking the first entity candidate set as an example, the largest calculated first sum value is 0.8, and the candidate entity corresponding to the maximum value of the first sum value is "Journey to the West". Thus, it can be determined that "Journey to the West" is the first entity.
[0057] To improve the accuracy of knowledge extraction and avoid extracting incorrect entities, optionally, it can also be determined first whether the sentence to be extracted actually contains the target attribute relationship according to the output result of the reading comprehension model. If the sentence to be extracted does contain the target attribute relationship, then the entities with the target attribute relationship are output. If the sentence to be extracted actually does not contain the target attribute relationship, then no output is made. Specifically, it can be implemented as follows: If the probability that the starting character of the candidate entity with the largest first sum value becomes the starting character of the first entity is greater than the preset threshold, and the probability that the starting character of the candidate entity with the largest second sum value becomes the starting character of the second entity is greater than the preset threshold, then it is determined that the sentence to be extracted actually contains the target attribute relationship, and then the entities with the target attribute relationship are output.
[0058] For example, the sentence to be extracted is "The author of Journey to the West is Wu Chengen", the target attribute relationship is the publication time, and the candidate entity with the largest first sum value is "Xi You", its starting character is "Xi". The probability that "Xi" becomes the starting character of the first entity is 0.2, and the probability that "Xi" becomes the starting character of the first entity is less than the preset threshold of 0.5. Then it means that there is no such attribute relationship as the publication time in "The author of Journey to the West is Wu Chengen".
[0059] Using the method introduced in the embodiments of the present invention, entities with target attribute relationships and the target attribute relationships can be extracted from the sentence to be extracted. Then, according to the extraction results, entities with target attribute relationships and the target attribute relationships can be output. Optionally, the extraction results can be output in the form of triples, where the triples can be expressed as <Entity A, Target Attribute Relationship, Entity B>.
[0060] Optionally, the extraction results can also be annotated manually to mark whether the extraction results are correct. In one possible implementation, the extraction results marked as correct can be stored in the knowledge database for backup. If the extraction results are correct, other conceivable attribute relationships that have not been extracted can be manually supplemented to the knowledge database. Optionally, the extraction results marked as correct can be used as positive samples, and the extraction results marked as incorrect can be used as negative samples to train the vector model and reading comprehension model mentioned above, so as to continuously optimize the model and enhance the system capabilities.
[0061] In summary, the overall flow chart of the method provided by the embodiment of the present invention is as follows: Figure 4 As shown. First, the sentence to be extracted can be input into the vector model, and the vector model maps the sentence to be extracted into a sentence vector. Then, the target relationship vector matching the sentence vector is retrieved from the storage relational database, and the target attribute relationship corresponding to the target relationship vector is determined. The target attribute relationship and the sentence to be extracted are input into the reading comprehension model. Based on the output result of the reading comprehension model, the entity with the target attribute relationship in the sentence to be extracted is extracted. Then, the extraction result can be used as knowledge 1, and the correctness of knowledge 1 is annotated by manual annotation to obtain knowledge 2. The vector model and the reading comprehension model are optimized by knowledge 2.
[0062] By adopting the method provided by the embodiment of the present invention, the correlation between the sentence to be extracted and the attribute relationship can be calculated, the target attribute relationship contained in the sentence to be extracted can be matched based on the correlation, and then the entity with the target attribute relationship in the sentence to be extracted can be determined through the reading comprehension model. In this way, even if the sentence to be extracted is not edited according to the specified sentence structure, the entity with the target attribute relationship and the target attribute relationship can still be accurately extracted from the sentence to be extracted based on the semantics of the sentence to be extracted and the attribute relationship, and the flexibility of knowledge extraction is high and the accuracy of the extraction result is high.
[0063] For ease of understanding, taking the application of the knowledge extraction method provided in an embodiment of the present invention in a commercial service robot as an example, the specific implementation of the knowledge extraction method provided above is exemplified in combination with the following application scenario.
[0064] Commercial service robots can usually be service robots placed in public service scenarios, such as a guide robot placed in the lobby on the first floor of a shopping mall. User 1 can chat with the guide robot. The following dialogue may occur in the actual human-machine interaction process:
[0065] User 1: What kind of books do you like to read?
[0066] Leading robot: I like watching "Journey to the West".
[0067] User 1: In the first year of the Wanli era, Wu Chengen completed the writing of "Journey to the West".
[0068] The guiding robot can obtain the sentence "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" input by User 1, and use this sentence as the sentence to be extracted. The process of extracting knowledge from this sentence is as follows:
[0069] The sentence "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" can be input into the vector model set in the guiding robot. The vector model maps this sentence to sentence vector A, and then matches sentence vector A with the relationship vectors stored in the relational database to obtain the target relationship vectors. Suppose the four relationship vectors closest to sentence vector A are the target relationship vectors a, b, c, d. The target attribute relationships corresponding to the target relationship vectors a, b, c, d can be determined, and the target attribute relationships corresponding to the determined target relationship vectors a, b, c, d are "original work", "description", "time", and "completion time" in sequence.
[0070] Next, "original work" and "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" can be input into the reading comprehension model. The first entity and the second entity extracted are "Journey to the West" and "Wu Chengen" in sequence; "description" and "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" are input into the reading comprehension model, and the candidate entity with the largest first sum value obtained is "Journey to the West", and its starting character is "West". The probability that "West" becomes the starting character of the first entity is 0.2, and the probability that "West" becomes the starting character of the first entity is less than the preset threshold of 0.5, indicating that there is no such attribute relationship as "description" in "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'". Therefore, the first entity and the second entity extracted for the attribute relationship "description" are empty; "time" and "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" are input into the reading comprehension model, and the first entity and the second entity extracted are "Journey to the West" and "the first year of the Wanli era" in sequence; "completion time" and "In the first year of the Wanli era, Wu Chengen completed the writing of 'Journey to the West'" are input into the reading comprehension model, and the first entity and the second entity extracted are "Journey to the West" and "the first year of the Wanli era" in sequence.
[0071] In the above process, the target attribute relationship and the sentence to be extracted can be separated by the separator [SEP] and then combined, and the combined result is input into the reading comprehension model.
[0072] Based on what user 1 said, "Wu Chengen completed the writing of Journey to the West in the first year of the Wanli reign," the leading robot extracted the entities with the original work relationship: Wu Chengen and Journey to the West, and the entities with the time or writing time relationship: Journey to the West and the first year of the Wanli reign. After extracting this knowledge, the leading robot can store the extracted knowledge. In this way, the more knowledge is stored, the more the fluency of human-computer interaction can be improved.
[0073] Based on the stored knowledge, user 2 can smoothly conduct the following conversation with the leading robot:
[0074] User 2: What kind of books do you like to read?
[0075] Leading robot: I like watching "Journey to the West".
[0076] User 2: Let me test you. Who wrote Journey to the West?
[0077] Leading Robot: "Journey to the West" was written by Wu Cheng'en.
[0078] Finally, the knowledge extraction results can be annotated by manual annotation. For the extraction results in the above example, the manual annotation is all correct. Optionally, the extraction results can also be supplemented manually. For example, in addition to the extracted attribute relationship of "original work", "Journey to the West" and "Wu Chengen" actually also have the attribute relationship of "author", and the attribute relationship "author" can be supplemented manually.
[0079] For ease of understanding, the application of the knowledge extraction method provided in an embodiment of the present invention in a commercial service robot is taken as an example, and then the specific implementation of the knowledge extraction method provided above is exemplified in combination with other application scenarios.
[0080] For another example, a commercial service robot may be a service robot placed at the entrance of a restaurant in a shopping mall. User 1 may have the following conversation with the service robot:
[0081] Service robot: Dear, it’s already noon. Have you eaten?
[0082] User 1: I have already eaten.
[0083] Service robot: Please comment on the food you had today so that I can provide suggestions to other friends.
[0084] User 1: Dish 1 at Restaurant A is really delicious.
[0085] After receiving the voice information input by the user, the service robot can use "The dish 1 of Restaurant A is really delicious" as a sentence to be extracted to extract the knowledge. The service robot can input "The dish 1 of Restaurant A is really delicious" into the vector model, and the vector model maps "The dish 1 of Restaurant A is really delicious" into a sentence vector X, and then matches the sentence vector X with the relationship vector stored in the relational database to obtain the target relationship vector. Assuming that the first two relationship vectors closest to the sentence vector X are the target relationship vectors a and b, the target attribute relationships corresponding to the target relationship vectors a and b can be determined, and the target attribute relationships corresponding to the target relationship vectors a and b are "subordinate" and "description" respectively.
[0086] Next, "subordinate" and "A dish in Restaurant A is really delicious" can be input into the reading comprehension model, and the first and second entities extracted are "Restaurant A" and "Dish 1" respectively; "description" and "Dish 1 in Restaurant A is really delicious" can be input into the reading comprehension model, and the first and second entities extracted are "Dish 1" and "delicious" respectively.
[0087] Based on the user's words "Dish 1 in Restaurant A is really delicious", the service robot extracts the entities with subordinate relationships as Restaurant A and Dish 1, and the entities with description relationships as Dish 1 and Delicious. After extracting this knowledge, the service robot can store the extracted knowledge. When other users ask the service robot to recommend a restaurant in the mall, it can actively recommend Dish 1 to other users entering the store based on the stored knowledge.
[0088] For ease of understanding, the application of the knowledge extraction method provided in an embodiment of the present invention in a commercial service robot is taken as an example, and then the specific implementation of the knowledge extraction method provided above is exemplified in combination with other application scenarios.
[0089] For another example, the commercial service robot may be a service robot placed in a hospital, and user 1 may have the following conversation with the service robot:
[0090] Service robot: What’s wrong with you?
[0091] User 1: I have a cold and a runny nose.
[0092] Service robot: Drink more hot water and get enough rest.
[0093] After receiving the voice information input by the user, the service robot can use "I have a cold and a runny nose" as a sentence to be extracted to extract the knowledge. The service robot can input "I have a cold and a runny nose" into the vector model, and the vector model maps "I have a cold and a runny nose" into a sentence vector Y, and then matches the sentence vector Y with the relationship vector stored in the relational database to obtain the target relationship vector. Assuming that the relationship vector closest to the sentence vector Y is the target relationship vector a, the target attribute relationship corresponding to the target relationship vector a can be determined, and the target attribute relationship corresponding to the determined target relationship vector a is "symptoms".
[0094] Next, “symptoms” and “I have a cold and a runny nose” can be input into the reading comprehension model, and the first entity and the second entity extracted are “cold” and “runny nose” respectively.
[0095] Based on the user's words "I have a cold and a runny nose", the service robot extracts the entities with symptom relationships as cold and runny nose. After extracting this knowledge, the service robot can store the extracted knowledge. Based on the stored knowledge, user 2 can smoothly have the following conversation with the leading robot:
[0096] User 2: What are the symptoms of a cold?
[0097] Service robot: has a runny nose.
[0098] By adopting the method provided in the embodiment of the present invention, the correlation between the sentence to be extracted and the attribute relationship can be calculated, the target attribute relationship contained in the sentence to be extracted can be matched based on the correlation, and then the entity with the target attribute relationship in the sentence to be extracted can be determined through the reading comprehension model. In this way, even if the sentence to be extracted is not edited according to the specified sentence structure, the entity with the target attribute relationship and the target attribute relationship can still be accurately extracted from the sentence to be extracted based on the semantics of the sentence to be extracted and the attribute relationship, and the flexibility of knowledge extraction is high and the accuracy of the extraction result is high.
[0099] The following will describe in detail the knowledge extraction device of one or more embodiments of the present invention. Those skilled in the art will appreciate that these knowledge extraction devices can be configured using commercially available hardware components through the steps taught in this solution.
[0100] Figure 5 A schematic diagram of the structure of a knowledge extraction device provided by an embodiment of the present invention is shown in FIG. Figure 5 As shown, the device comprises:
[0101] An acquisition module 51 is used to acquire a sentence to be extracted and a plurality of attribute relationships, wherein the attribute relationship is used to describe the connection between different entities in the sentence to be extracted;
[0102] A calculation module 52, used to determine the correlation between the sentence to be extracted and each attribute relationship;
[0103] A determination module 53, configured to determine, based on the relevance, a target attribute relationship included in the sentence to be extracted from among the multiple attribute relationships;
[0104] An extraction module 54, configured to input the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determine an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model;
[0105] The output module 55 is used to output the entity having the target attribute relationship and the target attribute relationship.
[0106] Optionally, the calculation module 52 is used to:
[0107] Inputting the sentence to be extracted into a first machine learning model to obtain a sentence vector corresponding to the sentence to be extracted;
[0108] Obtaining relationship vectors corresponding to the multiple attribute relationships respectively, wherein the relationship vectors are obtained by respectively inputting the multiple attribute relationships into a second machine learning model in advance;
[0109] The distances respectively corresponding to the sentence vector and each relationship vector are determined as the correlations respectively corresponding to the sentence to be extracted and each attribute relationship.
[0110] Optionally, the determining module 53 is used to:
[0111] Determine, among the relationship vectors, a preset number of target relationship vectors whose distances from the sentence vector meet a preset condition;
[0112] The attribute relationship corresponding to the target relationship vector is determined as the target attribute relationship contained in the sentence to be extracted.
[0113] Optionally, the extraction module 54 is used to:
[0114] Inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, obtaining the probability of each character in the sentence to be extracted becoming the starting character of a first entity, the ending character of the first entity, the starting character of a second entity, and the ending character of the second entity, wherein the first entity and the second entity are entities having the target attribute relationship;
[0115] Based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity, the entity having the target attribute relationship in the sentence to be extracted is determined.
[0116] Optionally, the extraction module 54 is used to:
[0117] Generate a first entity candidate set and a second entity candidate set based on the characters in the sentence to be extracted, wherein the first entity candidate set includes at least one candidate entity, and the second entity candidate set includes at least one candidate entity;
[0118] Based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity, the first entity is determined in the first entity candidate set, and the second entity is determined in the second entity candidate set.
[0119] Optionally, the extraction module 54 is used to:
[0120] For a target character in the sentence to be extracted, the target character is determined as the starting character of the candidate entity, and the characters in the sentence to be extracted except the target character are sequentially determined as the ending characters of the candidate entity to obtain a first entity candidate set and a second entity candidate set, wherein the target character is any character in the sentence to be extracted.
[0121] Optionally, the extraction module 54 is used to:
[0122] For a target candidate entity in the first entity candidate set, determining a probability that a starting character constituting the target candidate entity becomes a starting character of the first entity, determining a probability that an ending character constituting the target candidate entity becomes an ending character of the first entity, and calculating a first sum of the determined probabilities, wherein the target candidate entity is any candidate entity in the first entity candidate set;
[0123] For a target candidate entity in the second entity candidate set, determining a probability that a starting character constituting the target candidate entity becomes a starting character of the second entity, determining a probability that an ending character constituting the target candidate entity becomes an ending character of the second entity, and calculating a second sum of the determined probabilities, wherein the target candidate entity is any candidate entity in the second entity candidate set;
[0124] In the first entity candidate set, a candidate entity with the largest first sum value is determined as the first entity, and in the second entity candidate set, a candidate entity with the largest second sum value is determined as the second entity.
[0125] Optionally, the extraction module 54 is used to:
[0126] If the probability that the starting character of the candidate entity with the largest first sum value becomes the starting character of the first entity is greater than a preset threshold, and the probability that the starting character of the candidate entity with the largest second sum value becomes the starting character of the second entity is greater than the preset threshold, then in the first entity candidate set, the candidate entity with the largest first sum value is determined as the first entity, and in the second entity candidate set, the candidate entity with the largest second sum value is determined as the second entity.
[0127] Figure 5 The device shown can perform the aforementioned Figures 1 to 4 The knowledge extraction method provided in the illustrated embodiment, the detailed execution process and technical effects can be found in the description of the aforementioned embodiment, which will not be repeated here.
[0128] In one possible design, the above Figure 5 The structure of the knowledge extraction device shown can be implemented as an electronic device, such as Figure 6 As shown, the electronic device may include: a processor 91 and a memory 92. The memory 92 stores executable code, and when the executable code is executed by the processor 91, the processor 91 can at least implement the above-mentioned Figures 1 to 4 The knowledge extraction method provided in the illustrated embodiment.
[0129] Optionally, the electronic device may further include a communication interface 93 for communicating with other devices.
[0130] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, wherein an executable code is stored on the non-transitory machine-readable storage medium. When the executable code is executed by a processor of an electronic device, the processor can at least implement the above-mentioned Figures 1 to 4 The knowledge extraction method provided in the illustrated embodiment.
[0131] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.
[0132] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0133] The knowledge extraction method provided in the embodiment of the present invention can be executed by a certain program / software, which can be provided by the network side. The electronic device mentioned in the above embodiment can download the program / software to a local non-volatile storage medium, and when it needs to execute the above knowledge extraction method, the program / software is read into the memory by the CPU, and then the CPU executes the program / software to implement the knowledge extraction method provided in the above embodiment. The execution process can refer to the above Figures 1 to 4 Instructions in .
[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A knowledge extraction method, characterized in that: include: Acquire a sentence to be extracted and a plurality of attribute relationships, wherein the attribute relationships are used to describe the connections between different entities in the sentence to be extracted; Determine the relevance between the sentence to be extracted and each attribute relationship; Based on the relevance, determining a target attribute relationship included in the sentence to be extracted from the multiple attribute relationships; Inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determining an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model; Output entities having the target attribute relationship and the target attribute relationship.
2. The method according to claim 1, characterized in that Determining the relevance between the sentence to be extracted and each attribute relationship includes: Inputting the sentence to be extracted into a first machine learning model to obtain a sentence vector corresponding to the sentence to be extracted; Obtaining relationship vectors corresponding to the multiple attribute relationships respectively, wherein the relationship vectors are obtained by respectively inputting the multiple attribute relationships into a second machine learning model in advance; The distances respectively corresponding to the sentence vector and each relationship vector are determined as the correlations respectively corresponding to the sentence to be extracted and each attribute relationship.
3. The method according to claim 2, characterized in that The step of determining, based on the relevance, a target attribute relationship included in the sentence to be extracted from the plurality of attribute relationships includes: Determine, among the relationship vectors, a preset number of target relationship vectors whose distances from the sentence vector meet a preset condition; The attribute relationship corresponding to the target relationship vector is determined as the target attribute relationship contained in the sentence to be extracted.
4. The method according to claim 1, characterized in that The step of inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determining an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model, comprises: Inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, obtaining the probability of each character in the sentence to be extracted becoming the starting character of a first entity, the ending character of the first entity, the starting character of a second entity, and the ending character of the second entity, wherein the first entity and the second entity are entities having the target attribute relationship; Based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity, the entity having the target attribute relationship in the sentence to be extracted is determined.
5. The method according to claim 4, characterized in that The determining the entity having the target attribute relationship in the sentence to be extracted based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity includes: Generate a first entity candidate set and a second entity candidate set based on the characters in the sentence to be extracted, wherein the first entity candidate set includes at least one candidate entity, and the second entity candidate set includes at least one candidate entity; Based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity, the first entity is determined in the first entity candidate set, and the second entity is determined in the second entity candidate set.
6. The method according to claim 5, characterized in that The step of generating a first entity candidate set and a second entity candidate set based on the characters in the sentence to be extracted includes: For a target character in the sentence to be extracted, the target character is determined as the starting character of the candidate entity, and the characters in the sentence to be extracted except the target character are sequentially determined as the ending characters of the candidate entity to obtain a first entity candidate set and a second entity candidate set, wherein the target character is any character in the sentence to be extracted.
7. The method according to claim 5, characterized in that The step of determining the first entity in the first entity candidate set and determining the second entity in the second entity candidate set based on the probability that each character in the sentence to be extracted becomes the starting character of the first entity, the ending character of the first entity, the starting character of the second entity, and the ending character of the second entity comprises: For a target candidate entity in the first entity candidate set, determining a probability that a starting character constituting the target candidate entity becomes a starting character of the first entity, determining a probability that an ending character constituting the target candidate entity becomes an ending character of the first entity, and calculating a first sum of the determined probabilities, wherein the target candidate entity is any candidate entity in the first entity candidate set; For a target candidate entity in the second entity candidate set, determining a probability that a starting character constituting the target candidate entity becomes a starting character of the second entity, determining a probability that an ending character constituting the target candidate entity becomes an ending character of the second entity, and calculating a second sum of the determined probabilities, wherein the target candidate entity is any candidate entity in the second entity candidate set; In the first entity candidate set, a candidate entity with the largest first sum value is determined as the first entity, and in the second entity candidate set, a candidate entity with the largest second sum value is determined as the second entity.
8. The method according to claim 7, characterized in that The step of determining, in the first entity candidate set, a candidate entity with a maximum first sum value as the first entity, and determining, in the second entity candidate set, a candidate entity with a maximum second sum value as the second entity, comprises: If the probability that the starting character of the candidate entity with the largest first sum value becomes the starting character of the first entity is greater than a preset threshold, and the probability that the starting character of the candidate entity with the largest second sum value becomes the starting character of the second entity is greater than the preset threshold, then in the first entity candidate set, the candidate entity with the largest first sum value is determined as the first entity, and in the second entity candidate set, the candidate entity with the largest second sum value is determined as the second entity.
9. A knowledge extraction device, characterized in that: include: An acquisition module, used to acquire a sentence to be extracted and a plurality of attribute relationships, wherein the attribute relationships are used to describe the connections between different entities in the sentence to be extracted; A calculation module, used to determine the correlation between the sentence to be extracted and each attribute relationship; A determination module, configured to determine, based on the relevance, a target attribute relationship included in the sentence to be extracted from among the multiple attribute relationships; An extraction module, used for inputting the target attribute relationship and the sentence to be extracted into a reading comprehension model, and determining an entity having the target attribute relationship in the sentence to be extracted based on a result output by the reading comprehension model; An output module is used to output entities having the target attribute relationship and the target attribute relationship.
10. An electronic device, characterized in that: include: A memory and a processor; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the knowledge extraction method as described in any one of claims 1 to 8.
11. A non-transitory machine-readable storage medium, characterized in that: The non-transitory machine-readable storage medium stores executable code, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the knowledge extraction method as described in any one of claims 1-8.
Citation Information
Patent Citations
Information extraction method based on artificial intelligence, storage medium and related device
CN111143536A
Text data relationship extraction method, apparatus and device, and readable storage medium
CN112559770A