Text processing method, device, electronic device, medium and program product
By segmenting text sentences and determining relation tuples inside and outside sub-text sentences, and using text processing models to build knowledge graphs, the problem of inaccurate knowledge graphs in the existing technology is solved, and more accurate and comprehensive extraction of relation tuples is achieved.
Patent Information
- Application Number
- CN202210903474.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-27
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-07-27
AI Technical Summary
When the existing technology extracts relational tuples from text sentences, the extraction template is relatively fixed, resulting in a knowledge graph that is not accurate enough and cannot fully capture the specified relationships in the text sentence.
By dividing text sentences into sub-text sentences, and determining relation tuples within and between sub-text sentences, a relational knowledge graph is constructed, and the first text processing model and the second text processing model are used to mark and predict relation tuples respectively, thereby improving Accuracy of knowledge graphs.
It achieves finer-grained and more comprehensive extraction of relation tuples, making the constructed knowledge graph more accurate and reliable, and suitable for multiple languages and associated relationships.
Smart Images

Figure CN115827884B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a text processing method, device, electronic device, medium and program product. Background Art
[0002] With the continuous development of computer technology, entity combinations with specified relationships can be extracted from text sentences through natural language processing (NLP) and other related technologies to construct triples, and knowledge graphs can be constructed based on triples. For example, participle combinations with upper and lower relationships can be extracted from the text, and relationship tuples can be constructed for the participle combinations to obtain a knowledge graph indicating the upper and lower relationships. In some implementations, an extraction template corresponding to a specified relationship is usually constructed based on grammar, and two entities are extracted using the extraction template as an entity combination. However, the language structure of the text sentence is very flexible, and the extraction template is relatively fixed, which makes the extraction result not comprehensive enough, resulting in the knowledge graph constructed being inaccurate. Summary of the invention
[0003] The embodiments of the present application provide a text processing method, device, electronic device, medium and program product, which can more comprehensively obtain word segmentation combinations with specified relationships in text sentences and improve the accuracy of the constructed knowledge graph.
[0004] On the one hand, an embodiment of the present application provides a text processing method, the method comprising:
[0005] Acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain multiple sub-text sentences;
[0006] Determine at least one first relation tuple according to the plurality of subtext sentences; a first relation tuple includes two participles, the two participles are from the same subtext sentence and have a specified association relationship;
[0007] Determine at least one second relation tuple according to the plurality of subtext sentences; a second relation tuple includes two participles, the two participles are from different subtext sentences and have a specified association relationship;
[0008] A relational knowledge graph corresponding to the text sentence set is constructed according to at least one first relation tuple and at least one second relation tuple.
[0009] On the one hand, an embodiment of the present application provides a text processing device, the device comprising:
[0010] An acquisition module is used to acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences;
[0011] A processing module, configured to determine at least one first relation tuple according to a plurality of subtext sentences; a first relation tuple includes two participles, the two participles are from the same subtext sentence and have a specified association relationship;
[0012] The processing module is further used to determine at least one second relation tuple according to the plurality of subtext sentences; a second relation tuple includes two participles, the two participles are from different subtext sentences and have a specified association relationship;
[0013] The processing module is also used to construct a relational knowledge graph corresponding to the text sentence set based on at least one first relation tuple and at least one second relation tuple.
[0014] On the one hand, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute some or all of the steps in the above method.
[0015] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program includes program instructions, which, when executed by a processor, are used to execute some or all of the steps in the above method.
[0016] Accordingly, according to one aspect of the present application, a computer program product or a computer program is provided, wherein the computer program product or the computer program comprises computer instructions, and when the computer instructions are executed by a processor, some or all of the steps in the above method can be implemented.
[0017] In an embodiment of the present application, a text sentence set can be obtained, and the text sentences in the text sentence set can be segmented based on segmentation characters to obtain multiple sub-text sentences, and at least one first relationship tuple is determined based on the multiple sub-text sentences, and at least one second relationship tuple is determined based on the multiple sub-text sentences; a second relationship tuple includes two participles, and the two participles come from different sub-text sentences and have a specified association relationship, and a relational knowledge graph corresponding to the text sentence set is constructed based on at least one first relationship tuple and at least one second relationship tuple. Through the above method, multiple relationship tuples can be determined based on the content within a sub-text sentence and the content between two sub-text sentences, so that the relationship tuples can be determined based on the text sentences in a more fine-grained and comprehensive manner, making the constructed knowledge graph more accurate and reliable. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0019] Figure 1 A schematic diagram of an application architecture provided for an embodiment of the present application;
[0020] Figure 2 A flowchart of a text processing method provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of a relational knowledge graph provided in an embodiment of the present application;
[0022] Figure 4 A flowchart of a text processing method provided in an embodiment of the present application;
[0023] Figure 5a A schematic diagram of a scenario for determining a first relationship tuple provided in an embodiment of the present application;
[0024] Figure 5b A schematic diagram of a scenario for determining a first relationship tuple provided in an embodiment of the present application;
[0025] Figure 6a A schematic diagram of a knowledge graph construction framework provided in an embodiment of the present application;
[0026] Figure 6b A schematic diagram of a knowledge graph construction framework provided in an embodiment of the present application;
[0027] Figure 7a A schematic diagram of a scenario for determining a first relation tuple based on a first text processing model provided in an embodiment of the present application;
[0028] Figure 7b A schematic diagram of a scenario for determining a second relation tuple based on a second text processing model provided in an embodiment of the present application;
[0029] Figure 8 A structural diagram of a text processing device provided in an embodiment of the present application;
[0030] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] 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 only 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.
[0032] The text processing method proposed in the embodiment of the present application is implemented in an electronic device, which can be a server or a terminal. Among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc., but is not limited to this. The embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.
[0033] Next, the technical terms involved in the technical fields to which the solutions of the embodiments of the present application may be applied are introduced:
[0034] 1. Artificial Intelligence
[0035] The embodiments of the present application relate to the field of artificial intelligence technology, and specifically to natural language processing technology in artificial intelligence. Natural language processing is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can realize effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language used by people in daily life, so it is closely related to the study of linguistics. Natural language processing technology generally includes technologies such as text processing, semantic understanding, machine translation, robot question and answer, knowledge graph, etc. For example, natural language processing related technologies can be used to realize the determination of relational tuples and the construction of relational knowledge graphs in the technical solution of this application.
[0036] 2. Knowledge Graph:
[0037] The knowledge graph represents the relationship between different entities and can be constructed based on multiple triples. A triple can indicate two entities and a specific relationship between the two entities. The technical solution of the present application can determine two participles (entities) with a specified association relationship in a text sentence, and construct a corresponding relationship tuple (triplet) based on the two participles. The specified association relationship can be a hierarchical relationship, a causal relationship, etc., which is not limited here. For example, it is determined from the text sentence that participle A and participle B have a hierarchical relationship and participle A is the hypernym of participle B, then the constructed relationship tuple can be recorded as [A, B, X], which indicates two participles A (first participle) and participle B (second participle), and X is used to indicate that A and B meet the specified association conditions, such as A and B have a hierarchical relationship, and the first participle is the hypernym of the second participle.
[0038] In some embodiments, see Figure 1 , Figure 1 The following is a schematic diagram of an application architecture provided in an embodiment of the present application, through which the text processing method proposed in the present application can be executed. Figure 1 As shown, the electronic device can obtain multiple sub-text sentences, for example, it can be obtained by obtaining a text sentence set, and obtaining the sub-text sentences obtained by segmenting the text sentences in the obtained text sentence set, or it can be obtained by obtaining pre-segmented sub-text sentences; determine at least one first relationship tuple based on the multiple sub-text sentences, and the two participles in the first relationship tuple are from the same sub-text sentence, that is, it can be determined from each sub-text sentence whether it contains two participles with a specified association relationship (such as determining two associated participles from sub-text sentence A, and determining two associated participles from sub-text sentence B), determine at least one second relationship tuple based on the multiple sub-text sentences, and the two participles in the second relationship tuple are from different sub-text sentences, that is, it can be determined from each two sub-text sentences whether it contains two participles with a specified association relationship (such as determining two associated participles from sub-text sentence A and sub-text sentence B, one participle is from sub-text sentence A, and the other participle is from sub-text sentence B), and subsequently a relational knowledge graph can be constructed based on the first association tuple and the second relationship tuple. In some embodiments, the first relation tuple may be obtained through a first text processing model, and the second relation tuple may be obtained through a second text processing model.
[0039] Understandably, Figure 1 It is only an exemplary representation of the possible application architecture of the technical solution of the present application, and does not limit the specific architecture of the technical solution of the present application, that is, the technical solution of the present application can also provide other forms of application architecture.
[0040] Optionally, in some embodiments, the electronic device may execute the text processing method to improve the accuracy of knowledge graph construction according to actual business needs. The technical solution of the present application can be applied to any type of knowledge graph construction scenario. For example, the text sentence set may be sentences related to character profiles, and the knowledge graph may be constructed for the hierarchical relationship in the character profiles. At this time, the relationship tuple may be a triple indicating that two participles (i.e., a participle combination) have a hierarchical relationship. The two participles may include a word representing a superordinate position and a word representing a subordinate position. For example, if the text sentence is "Zhang San is an actor", the participle representing the superordinate position is "actor" and the participle representing the subordinate position is "Zhang San".
[0041] For another example, the text sentence set may be sentences related to medical literature, and a knowledge graph may be constructed for causal relationships in medical literature. In this case, the relationship tuple may be a triple indicating that two participles (i.e., participle combinations) have a causal relationship. The two participles may include a word indicating the cause (such as "diabetes") and a word indicating the result. For example, "diabetes leads to renal failure", the participle indicating the cause is "diabetes" and the participle indicating the result is "renal failure". The electronic device may obtain a text sentence set, and obtain participle combinations from the same subtext sentence or from different subtext sentences from the text sentence set according to the method proposed in the technical solution of the present application, so as to construct a knowledge graph of a specified association relationship (such as a hierarchical relationship, a causal relationship).
[0042] Optionally, the data involved in this application, such as text sentence sets, relational knowledge graphs, etc., can be stored in a database, or can be stored in a blockchain, such as through a blockchain distributed system, which is not limited in this application.
[0043] It should be noted that in the specific implementation of the present application, if obtaining a text sentence set involves collecting relevant data of user information, such as collecting text corpus written by users to construct a text sentence set, then when the above embodiments of the present application are applied to specific products or technologies, it is necessary to obtain user permission or consent, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0044] It is understood that the above scenarios are only examples and do not constitute a limitation on the application scenarios of the technical solutions provided in the embodiments of the present application. The technical solutions of the present application can also be applied to other scenarios. For example, it is known to those skilled in the art that with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0045] Based on the above description, the present application embodiment proposes a text processing method, which can be executed by the electronic device mentioned above. Figure 2 , Figure 2A flowchart of a text processing method provided in an embodiment of the present application is shown below. Figure 2 As shown, the process of the text processing method of the embodiment of the present application may include the following:
[0046] S201: Acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences.
[0047] In some embodiments, the text sentence set may include one or more text sentences, which may be text sentences in articles or paragraphs. For example, a text sentence may be a complete sentence. The so-called sentence is the basic unit of language use. It is composed of words and phrases (phrases) and can express a complete meaning. It generally ends with a period, question mark, ellipsis, exclamation mark, and other completion identifiers. In some embodiments, the text sentence set may be obtained by segmenting the acquired text corpus (such as a complete document or a part of a paragraph in a document). For example, the text corpus may be segmented according to a preset completion identifier to obtain multiple text sentences as a text sentence set. The text corpus may be data input by relevant business personnel, or data scraped from a website (such as an encyclopedia); or data obtained from a specified field database (such as a medical field database); or data obtained from a document library, etc., and the source of the text corpus is not limited here. The acquired text corpus may be any type of text data, such as medical-related text corpus data, or text corpus data related to character profiles, which is not limited here. In addition, the text corpus constituting the text sentence set can be in any natural language form, for example, the text corpus can be in Chinese or English. This application does not limit the specific form. Therefore, this application can realize the construction of a knowledge graph for unstructured data (i.e., text corpus).
[0048] In some embodiments, the electronic device may preprocess a text sentence set, and perform the following method on the preprocessed text sentence set. The preprocessing may include at least one of the following: text sentence part of speech analysis, text sentence screening. The processing process and principle of each text sentence are the same, and the preprocessing process of a text sentence is used as an example for explanation.
[0049] In some embodiments, the text sentence part-of-speech word segmentation of a text sentence may specifically be to perform word segmentation processing and part-of-speech tagging processing on the text sentence to obtain an initial word segmentation set. The initial word segmentation set includes multiple word segments with part-of-speech tags, and the initial word segmentation set is merged according to a specified merging rule to obtain a target word segmentation set corresponding to the text sentence, thereby avoiding the problem that word segmentation cannot express the complete meaning due to a relatively fine word segmentation granularity. For example, texsmart (a word segmentation tool) can be used to perform word segmentation and part-of-speech tagging on the text sentence. Among them, the specified merging rule is used to merge specified adjacent word segments in the initial word segmentation set, that is, it can be used to obtain word segments that express more complete semantics in the text sentence.
[0050] The above-mentioned specified merging rule may include at least one or more of the following: 1) Adjacent nouns are merged. For example, if the adjacent word segments are "knowledge / NN" and "graph / NN", they can be merged to obtain "knowledge graph / NN"; 2) Adjacent modifiers and nouns are merged. For example, if the adjacent word segments are "limited / JJ" and "company / NN", they can be merged to obtain "limited company / NN". 3) Adjacent numeral-classifier words and nouns are merged. For example, if the adjacent word segments are "the first / NR", "one / CD", and "middle school / NN", they can be merged to obtain "the first middle school / NN". 4) Adjacent inclusion identifiers and the included internal words are merged. The inclusion identifier can be a book title mark, double quotation marks, parentheses, etc. For example, if the adjacent word segments are "《 / PU", "limited / JJ", "company / NN", "》 / PU", they can be merged to obtain "《Limited Company》 / NN". The unmerged word segments (including part-of-speech) and the merged word segments (including part-of-speech) in the initial word segmentation set can be used as the target word segmentation set. Among them, NN represents a noun, JJ represents a modifier, NR represents a proper noun, CD represents a numeral-classifier word, and PU represents a punctuation word.
[0051] In addition, when performing adjacent word segment merging, it can be further determined according to a specified rule whether the two word segments can form a single word segment. For example, they can be merged when they can form a proper noun or a common word. For example, the adjacent word segments "knowledge" and "graph" can be merged into "knowledge graph", and the adjacent word segments "XX" and "university" can be merged into "XX university", but the adjacent word segments "actor" and "Zhang San" cannot be merged into a single word segment; the specified rule can be to merge word segments with specified part-of-speech tagging types. For example, based on the above (1), only adjacent nouns both marked as "NN" are merged; or a common sense word library in the relevant field can be constructed, and if the word formed by the adjacent word segments belongs to this common sense word library, they are merged; or it can be intelligently judged through related technologies. For example, a model is constructed to determine whether the two word segments can be merged, etc., which is not limited here. The above-mentioned specified merging rule may also include other contents, which can specifically be set by relevant business personnel according to the actual application scenario.
[0052] In some embodiments, text sentence screening can specifically be performed by determining whether to filter out or screen out the text sentence based on the first filtering vocabulary to achieve text sentence level filtering. If the text sentence includes any filter word in the first filtering vocabulary, the text sentence is filtered out from the text sentence set; if the text sentence does not include all the filter words in the first filtering vocabulary, the text sentence is filtered out as a text sentence set for subsequent segmentation processing. That is, a text sentence containing any filter word in the first filtering vocabulary can be regarded as a text sentence in which there is no word combination with a specified association relationship, thereby improving the accuracy of subsequent determination of relationship tuples. The first filtering vocabulary can be set by relevant business personnel according to actual scenarios. For example, as shown in Table 1 below:
[0053] Filter words Text sentence example Legend <![CDATA[Sentence 1 of the text: {In legend} 过滤 Capricorn is a large mountain goat <!-- 5 -->]]> today <![CDATA[Sentence 2 of the text: {Today} 过滤 is cloudy]]> Like <![CDATA[Sentence 3 of the text: This mountain {looks like} 过滤 a Buddha]]>
[0054] Table 1
[0055] Taking text sentence 2 as an example, the filter word is "today". Text sentence 2 includes "today", which means that it is highly unlikely that any relation tuple will be determined from text sentence 2, and text sentence 2 is filtered from the text sentence set.
[0056] In some embodiments, the segmentation character (also called segmentation identifier) can be a symbol that segments text or text sentences at a smaller granularity than the completion identifier, such as a comma, a semicolon, etc. The segmentation character can be set by relevant business personnel according to the specific grammatical structure of the text sentence. Therefore, the electronic device can segment the text sentence based on the segmentation character to obtain multiple sub-text sentences with shorter lengths and less semantic content. For example, each text sentence in the preprocessed text sentence set is segmented. Subsequently, the relational tuples used to construct the relational knowledge graph can be determined from within a sub-text sentence and between two sub-text sentences.
[0057] S202: Determine at least one first relation tuple according to a plurality of sub-text sentences.
[0058] In some embodiments, the electronic device can determine the first relationship tuple from the sub-text sentence, that is, the first relationship tuple includes two participles (such as the first participle and the second participle), and the two participles are from the same sub-text sentence and have a specified association relationship. For example, a hyponym relationship. The first relationship tuple is also used to indicate the specified association conditions that the two participles should satisfy, such as the two participles in the first relationship tuple have a specified association relationship, and satisfy the condition that the previous participle (such as the first participle) is the hypernym of the next participle (such as the second participle), or satisfy the condition that the previous participle (such as the first participle) is the hyponym of the next participle (such as the second participle), etc. It can be understood that the first participle and the second participle here can represent the order and position in the first relationship tuple.
[0059] In some embodiments, the process and principle of determining whether there is a first associated tuple within each sub-text sentence are the same. Here, any one of the multiple sub-text sentences (the target sub-text sentence) is taken as an example for illustration. Specifically, each character in the target sub-text sentence is marked, and the first relational tuple is determined based on each marked character.
[0060] In some embodiments, the marking process is to mark each character with a label for a specified associated relationship. The label can be set based on the specific specified associated relationship and is used to extract the first word segment and the second word segment in the target sub-text sentence. For example, when the specified associated relationship is the hypernym-hyponym relationship, the labels can specifically include a first label, a second label, and a third label. The first label can be used to mark the characters that make up the hypernym (such as the first word segment), the second label can be used to mark the characters that make up the hyponym (such as the second word segment), and the third label can be used to mark the remaining characters, that is, the characters that do not have the hypernym-hyponym relationship. Another example is that when the specified associated relationship is the causal relationship, the labels can specifically include a first label, a second label, and a third label. The first label can be used to mark the characters that make up the cause word (such as the first word segment), the second label can be used to mark the characters that make up the result word (such as the second word segment), and the third label can be used to mark the remaining characters, that is, the characters that do not have the causal relationship. Therefore, the word segment determined according to the first label and the word segment determined according to the second label have the specified associated relationship.
[0061] In some embodiments, among each marked character, the consecutive characters marked with the first label can be determined as the first word segment, and the consecutive characters marked with the second label can be determined as the second word segment. Based on the first word segment and the second word segment, a first relational tuple is constructed. For example, the target sub-text sentence is "Zhang San is an actor". Among them, the characters "演" and "员" are marked with the first label, and the characters "张" and "三" are marked with the second label. Therefore, the two consecutive characters "演" and "员" can be used as the first word segment, and the two consecutive characters "张" and "三" can be used as the second word segment, and a first relational tuple (such as [actor, Zhang San, X]) is constructed according to the first word segment and the second word segment. Here, let X be used to indicate that the first word segment and the second word segment have the hypernym-hyponym relationship, and the first word segment is the hypernym of the second word segment (and / or the second word segment is the hyponym of the first word segment), that is, the specified associated condition is satisfied.
[0062] In some embodiments, the marking process for each character in the target sub-text sentence can be implemented by a first text processing model. The specific process and the specific description of the first text processing model can be referred to the relevant descriptions in the following embodiments.
[0063] S203. Determine at least one second relational tuple according to multiple sub-text sentences.
[0064] In some embodiments, the electronic device may determine a second relation tuple from between every two subtext sentences. The relevant description of the second relation tuple may be the same as the relevant description of the first relation tuple.
[0065] In some embodiments, the process and principle of determining whether there is a second associated tuple between each two subtext sentences are the same. Here, two subtext sentences (a first subtext sentence and a second subtext sentence) among multiple subtext sentences are used as examples for explanation. Specifically, the process may be to obtain a first candidate segmentation set corresponding to the first subtext sentence and a second candidate segmentation set corresponding to the second subtext sentence, and to construct at least one candidate relation tuple based on the first candidate segmentation set and the second candidate segmentation set, and to determine at least one second relation tuple from the at least one candidate relation tuple. The first candidate segmentation set includes the specified segmentation constituting the first subtext sentence, and the second candidate segmentation set includes the specified segmentation constituting the second subtext sentence. The candidate relation tuple includes one candidate segmentation from the first candidate segmentation set and one candidate segmentation from the second candidate segmentation set.
[0066] Among them, the first subtext sentence and the second subtext sentence can be any two subtext sentences from a plurality of subtext sentences, or can be two subtext sentences from the same text sentence from a plurality of subtext sentences. For example, the text sentence set includes text sentence 1 and text sentence 2, and text sentence 1 is segmented to obtain subtext sentence 1 and subtext sentence 2, and subtext sentence 2 is segmented to obtain subtext sentence 3 and subtext sentence 4. Subtext sentences 1-4 can be combined in pairs, and candidate relation tuples can be determined according to the candidate segmentation sets corresponding to all subtext sentence combinations; or candidate relation tuples can be determined according to the candidate segmentation sets corresponding to subtext sentence 1 and the candidate segmentation sets corresponding to subtext sentence 2, and candidate relation tuples can be determined according to the candidate segmentation sets corresponding to subtext sentence 3 and the candidate segmentation sets corresponding to subtext sentence 4. It can be understood that when a text sentence does not include a segmentation character, the text sentence is also a subtext sentence, that is, the first relation tuple can be determined from the subtext sentence only according to the process of step S202, and there are no other subtext sentences for determining the second relation tuple in the subtext sentence.
[0067] In some embodiments, the first candidate segmentation set and the second candidate segmentation set are obtained in the same manner. Taking the first candidate segmentation set as an example, it can be specifically obtained from the target segmentation set corresponding to the first subtext sentence that satisfies the specified part-of-speech condition as the first candidate segmentation set. The specified part-of-speech condition can be set by relevant business personnel according to the actual scenario. For example, in the upper-lower relationship, since the upper-lower and lower-higher words are usually nouns, the specified part-of-speech condition can be to extract the segmentation of the noun part of speech. The target segmentation set corresponding to the first subtext sentence is obtained from the target segmentation set corresponding to the text sentence to which it belongs.
[0068] In some embodiments, constructing at least one candidate relationship tuple based on the first candidate segmentation set and the second candidate segmentation set can be specifically that each candidate segmentation in the first candidate segmentation set is used as the first segmentation, and a candidate relationship tuple is constructed with each candidate segmentation in the second candidate segmentation set, and each candidate segmentation in the second candidate segmentation set is used as the first segmentation, and a candidate relationship tuple is constructed with each candidate segmentation in the second candidate segmentation set. For example, the first candidate segmentation set includes segmentation A and segmentation B, and the second candidate segmentation set includes segmentation C and segmentation D; therefore, the candidate relationship tuple constructed with the first candidate segmentation set as the first segmentation includes [A, C, X], [A, D, X], [B, C, X], [B, D, X], and the candidate relationship tuple constructed with the second candidate segmentation set as the first segmentation includes [C, A, X], [C, B, X], [D, A, X], [D, B, X].
[0069] In some embodiments, determining at least one second relation tuple from at least one candidate relation tuple may specifically be to determine the probability that two candidate participles in each candidate relation tuple satisfy the specified association condition, and determine at least one second relation tuple according to the probability corresponding to each candidate relation tuple. Among them, the candidate relation tuple whose corresponding probability is greater than a preset probability threshold may be used as the second relation tuple. Determining the probability that two candidate participles in the candidate relation tuple satisfy the specified association condition may be implemented by a second text processing model, and the specific process and the specific description of the second text processing model may refer to the relevant description of the following embodiments.
[0070] S204. Construct a relational knowledge graph corresponding to the text sentence set based on at least one first relation tuple and at least one second relation tuple.
[0071] In some embodiments, a relational knowledge graph corresponding to the text sentence set may be constructed according to at least one first relation tuple and at least one second relation tuple and in a specified construction method. The specified construction method may be to use the participles in the first relation tuple or the second relation tuple as nodes, and to connect the nodes in the direction from the second participle to the first participle (or the direction from the first participle to the second participle) to form a relational indication graph.
[0072] For example, Figure 3 As shown, Figure 3 A schematic diagram of a relational knowledge graph provided in an embodiment of the present application; wherein the relational knowledge graph represents the hyponym and hyponym relationships covered in the text corpus corresponding to the set of text sentences. Taking the relational tuple [actor, Zhang San, X] as an example, the participles "Zhang San" and "actor" are nodes, and the two nodes are connected in the direction of the second participle pointing to the first participle, which means that the hyponym "Zhang San" points to the hypernym "actor".
[0073] Therefore, by accurately determining the relationship tuples within a sub-text sentence and between two sub-texts, a more accurate, reliable and high-quality relationship knowledge graph can be constructed. There is no restriction on the length of the text corpus used to construct the relationship knowledge graph, and it can be applied to the determination of tuples of any association relationship in any language form, that is, it has higher flexibility and versatility, strong generalization ability, and can be applied to a variety of application scenarios. Subsequently, similar things can be aggregated through the constructed relationship knowledge graph, and hypernyms of different granularities can be provided for each hyponym. For example, for a hypernym with different connection levels and dimensions, the multiple hyponyms can be similar things corresponding to the hypernym, and a hyponym with different connection levels and dimensions, so that the hypernyms of multiple granularities of a hyponym can be determined. In addition, a high-quality relationship knowledge graph can improve the application effect of downstream tasks, such as in related entity recommendation tasks such as assisting named entity recognition or labeling articles and works, which can play a good role.
[0074] In an embodiment of the present application, a text sentence set can be obtained, and the text sentences in the text sentence set can be segmented based on segmentation characters to obtain multiple sub-text sentences, at least one first relationship tuple is determined based on the multiple sub-text sentences, at least one second relationship tuple is determined based on the multiple sub-text sentences, and a relational knowledge graph corresponding to the text sentence set is constructed based on the at least one first relationship tuple and the at least one second relationship tuple. Through the above method, multiple relationship tuples can be determined based on the content within a sub-text sentence and the content between two sub-text sentences, so that the relationship tuples can be determined based on the text sentences in a more fine-grained and comprehensive manner, making the constructed knowledge graph more accurate and reliable.
[0075] See also Figure 4 , Figure 4 The following is a flowchart of a text processing method provided in an embodiment of the present application, which can be executed by the electronic device mentioned above. Figure 4 As shown, the process of the text processing method in the embodiment of the present application may include the following:
[0076] S401, obtaining a text sentence set, and segmenting the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences. The specific implementation of step S401 can refer to the relevant description of the above embodiment, which will not be repeated here.
[0077] S402: Determine at least one first relation tuple according to a plurality of sub-text sentences.
[0078] In some embodiments, the first relation tuple may be determined from a subtext sentence. The specific description of the first relation tuple may refer to the related description of the first relation tuple in the above embodiment, which will not be repeated here.
[0079] In some embodiments, taking any one of a plurality of sub - text sentences as the target sub - text sentence, determining at least one first relational tuple according to the target sub - text sentence may specifically be to perform annotation processing on each character in the target sub - text, determine the first word segmentation according to the characters labeled with the first label, and determine the second word segmentation according to the characters labeled with the second label. Based on the first word segmentation and the second word segmentation, at least one first relational tuple is constructed. Any one of the first relational tuples includes a first word segmentation and a second word segmentation. After the annotation processing, in the target sub - text sentence, the word segmentation determined according to the first label and the word segmentation determined according to the second label have a specified association relationship.
[0080] In some embodiments, the annotation processing may be BIO annotation, where B - begin (start), I - inside (inside), O - outside (other). That is, B can represent the starting character of a word segmentation, I can represent the characters other than the starting character in a word segmentation, and O can represent the remaining characters other than the specified word segmentation, that is, characters of no any type. Therefore, the first label may include B - N and I - N, which are used to represent the starting character and the remaining characters of the first word segmentation (N) respectively, and the second label may include B - M and I - M, which are used to represent the starting character and the remaining characters of the second word segmentation (M) respectively.
[0081] In some embodiments, determining the first word segmentation according to the characters labeled with the first label may be to determine the continuous characters from the starting character identified in the first label to the labeled remaining characters as the first word segmentation. For example, if the continuous characters "的", "电", "视", "剧", "是" are labeled as O, B - N, I - N, I - N, O in sequence, then "电" is labeled as the starting character, and "视" and "剧" are labeled as the remaining characters and are continuous characters. Therefore, "电", "视", "剧" can be determined as the first word segmentation "电视剧". Another example is that if the continuous characters "手", "机", "电", "脑" are labeled as B - N, I - N, B - N, I - N in sequence, then "手" is labeled as the starting character, "机" is labeled as the remaining character and is continuous, so "手" and "机" can be determined as the first word segmentation "手机", and the next continuous character "电" is labeled as the starting character, "脑" is labeled as the remaining character, and "电脑" is determined as the second first word segmentation. The method for determining the second word segmentation is the same as that for determining the first word segmentation and will not be elaborated here.
[0082] In some embodiments, one or more first participles and one or more second participles can be determined in a target sub-text sentence, and a first relation tuple can be constructed based on each first participle and each second participle. For example, the hypernyms marked in the target sub-text sentence are A and B, and the hyponyms marked are C and D, and the constructed first relation tuples are [A, C, X], [B, C, X], [A, D, X], [B, D, X]. For another example, the hypernyms marked in the target sub-text sentence are A and B, and the hyponym marked is C, and the constructed first relation tuples are [A, C, X], [B, C, X].
[0083] Therefore, the tagging process is to tag each character, and then determine the two participles with the specified association relationship in the target sub-text sentence based on the tagging results. If a target sub-text sentence includes more than one first participle and / or second participle, there may be a situation where the first relation tuple is constructed incorrectly. For example, the hypernyms marked in the target sub-text sentence are A and B, and the hyponyms marked are C and D. The first relation tuple will be constructed based on A and C, B and C, but A may not be the hypernym of C, or in the semantics represented by the target sub-text sentence, A and C do not reflect the corresponding hypernym relationship. Therefore, by determining the first relation tuple through a more fine-grained sub-text sentence, the possibility of a sub-text sentence containing multiple groups of participle combinations with a specified association relationship can be reduced, and the distance between the first participle and the second participle can be guaranteed to be within a smaller range. Sub-text sentences usually have less content and a shorter distance, while complete text sentences usually have more content and a longer distance, that is, compared with directly tagging the complete text sentence, the tagging difficulty can be reduced, and the accuracy of the tagging process can be improved, thereby improving the accuracy of the determined first relation tuple.
[0084] For example, Figure 5a-Figure 5b As shown, Figure 5a-Figure 5b Schematic diagram of the scenario for determining the first relation tuple; taking the hypernym relationship as an example, the first label is used to mark the hypernym, which may include B-ENT and I-ENT; the second label is used to mark the hyponym, which may include B-CAT and I-CAT; the third label is used to mark other payments, which may be O; suppose the text sentence is "The TV series "ABC" is very good, and there is actor Zhang San in it", if the complete text sentence is marked, the marking result may be Figure 5a, the hypernyms determined based on the first label include "TV series" and "actor", and the hyponyms determined based on the second label include "ABC" and "Zhang San", so there are 4 first relation tuples determined. At this time, it can be seen that the first relation tuples 2-3 are wrong relation tuples in the semantics represented by the text sentence. Therefore, the sub-text sentences obtained by segmentation can be annotated at a smaller granularity to reduce the probability that the first relation tuple determined is wrong when a sub-text sentence includes a combination of word segments in multiple relation tuples; that is, the text sentence can be segmented to obtain sub-text sentence 1 and sub-text sentence 2, and annotated separately. The annotation results obtained may be Figure 5b As shown, the first relation tuple determined based on sub-text sentence 1 is [TV series, "ABC", X], and the second relation tuple determined based on sub-text sentence 2 is [actor, Zhang San, X].
[0085] In some embodiments, the above-mentioned tagging of the sub-text sentence to determine at least one first relation tuple can be performed and determined based on the first text processing model. That is, the first initial model can be trained to obtain the first text processing model, and the first text processing model can tag the input sub-text sentence and output the tagging result of each character in the sub-text sentence.
[0086] In some embodiments, training the first initial model to obtain the first text processing model may specifically include obtaining a sample set and a relationship extraction template, extracting relationship tuples from multiple sample text sentences in the sample set based on the relationship extraction template to obtain an initial relationship tuple set, screening the initial relationship tuple set to obtain at least one reference relationship tuple, and training the first initial model based on multiple sample text sentences and at least one reference relationship tuple to obtain the first text processing model. The two sample participles of the reference relationship tuple come from the same sample text sentence. Any reference relationship tuple includes two sample participles, the two sample participles have a specified association relationship, and the two sample participles include a first sample participle and a second sample participle that meet the specified association condition, i.e., the first participle and the second participle in the corresponding first relationship tuple (second relationship tuple).
[0087] In some embodiments, the sample set may be obtained by segmenting the collected sample text corpus. For example, the sample text corpus may be segmented according to the completion identifier to obtain a plurality of sample text sentences as the sample set. In addition, the sample set may be preprocessed, and then the relation extraction template may be used to extract relation tuples from the preprocessed sample set. The preprocessing process may refer to the preprocessing process of the text sentence set in the above embodiment.
[0088] In some embodiments, the relation extraction template can be determined based on the grammatical structure and the specified association relationship. The relation tuple extraction of the sample text sentence based on the relation extraction template can be determined according to the target word segmentation set corresponding to the relation extraction template and the sample text sentence, such as obtaining sample word segmentations that meet the specified part of speech from the target word segmentation set, and determining whether the two sample word segmentations meet the grammatical structure and semantic meaning indicated by the relation extraction template in the sample text sentence. If so, the first sample word segmentation and the second sample word segmentation are further determined in the two sample word segmentations according to the indication of the relation extraction template to generate the corresponding relation tuple. For example, the relation extraction template indicates that the first sample word segmentation is a hypernym and the second sample word segmentation is a hyponym, then the relation tuple for the hypernym relationship can be obtained according to the first sample word segmentation and the second sample word segmentation. The target word segmentation set corresponding to the sample text sentence includes the sample word segmentations and the part of speech that constitute the sample text sentence, and the determination method of the target word segmentation set can be the same as the determination method of the target word segmentation set corresponding to the text sentence in the above embodiment.
[0089] For example, taking the specified association relationship as a hyponym relationship as an example, the relationship extraction template for Chinese corpus can be as shown in Table 2 below:
[0090]
[0091]
[0092] Table 2
[0093] Each relation extraction template has extraction accuracy. Take the first template description "{CAT} is a (one / kind of ....) {ENT}" as an example. CAT in template 1 represents a hyponym, and ENT represents a hypernym. The sample text sentence is "Zhang San is an actor". Based on the first template, it can be obtained that "Zhang San" is a hyponym and "actor" is a hypernym.
[0094] It is understandable that when the language form of the text corpus is different and the specified association relationship is different, the relationship extraction template can have multiple forms. The relationship extraction template can be set by relevant business personnel according to the actual scenario, or it can be an intelligently generated relationship extraction template, such as iteratively generated by bootstrap (a natural language processing tool) and other technologies. This is not limited here.
[0095] In some embodiments, after obtaining an initial set of relational tuples based on a relational extraction template, the initial set of relational tuples may be screened according to a specified screening rule to obtain a reference relational tuple with higher accuracy, so as to construct a high-quality relational knowledge graph and provide high-quality training samples for the first and second text processing models. Specifically, it may include at least one of the following: tuple screening based on a second filtering vocabulary, tuple screening based on the frequency of occurrence of the initial relational tuples.
[0096] In some embodiments, the initial relationship tuple set is filtered based on the second filtering vocabulary. If any sample word in the initial relationship tuple is a filtering word in the second filtering vocabulary, the initial relationship tuple is filtered out. If both sample words in the initial relationship tuple are not filtering words in the second filtering vocabulary, the initial relationship tuple is filtered out as a reference relationship tuple to achieve text word-level filtering. That is, the initial relationship tuple containing any filtering word in the second filtering vocabulary can be regarded as an erroneous relationship tuple. In other words, depending on the grammatical structure and semantics, the extracted initial relationship tuple may not have the specified association relationship even if it meets the relationship extraction template. For example, the second filtering vocabulary can be as follows
[0097] As shown in Table 3:
[0098]
[0099]
[0100] Table 3
[0101] Among them, taking sample text sentence 1 as an example, based on the relationship extraction template in the above Table 2, the sample text sentence 1 is subjected to relationship tuple extraction, and the initial relationship tuple [friends, we, X] may be extracted. However, the two sample participles in the initial relationship tuple do not have a hierarchical relationship. Therefore, the initial relationship tuple can be filtered by the filter word "we" in the second filter word list to ensure the accuracy of at least one reference relationship tuple.
[0102] In some embodiments, the second filter word list can be set by relevant business personnel according to actual scenarios. For example, a large number of relationship tuples can be collected through a relationship extraction template, and the word segments in the large number of relationship tuples are counted and analyzed to determine the high-frequency word segments that are obviously wrong, and the high-frequency word segments are determined as the second filter word list.
[0103] In some embodiments, screening the initial relationship tuple set based on the frequency of occurrence of the initial relationship tuple can be to count the frequency of occurrence (or occurrence frequency) of each initial relationship tuple in the initial relationship tuple set, and screen out the initial relationship tuples with a frequency of occurrence (or occurrence frequency) higher than a specified threshold as reference relationship tuples. The initial relationship tuple with a higher frequency of occurrence or probability of occurrence can be regarded as a tuple with a higher probability of being correct. Among them, the frequency of occurrence of the initial relationship tuple x p(x) = w(x) / W; w(x) represents the frequency of occurrence of the initial relationship tuple x in the initial relationship tuple set, and W represents the number of tuples in the initial relationship tuple set.
[0104] In some embodiments, the first initial model is trained based on multiple sample text sentences and at least one reference relation tuple to obtain a first text processing model. Specifically, multiple sample text sentences are separated based on separation characters to obtain multiple sample sub-text sentences, and each character in each sample sub-text sentence is labeled based on at least one reference relation tuple to obtain a first labeling result for multiple sample sub-text sentences, and the first initial model is called to label each sample sub-text sentence to obtain a second labeling result for multiple sample sub-text sentences. The first labeling result is used as a reference, and the first initial model is trained based on the second labeling result to obtain a first text processing model. If a sample text sentence obtains one or more reference relation tuples based on a relation extraction template and screening, the two word segments in the reference relation tuple can come from the same sample sub-text sentence obtained by segmenting the corresponding sample text sentence, or can come from different sample sub-text sentences. Among them, labeling the segmented sample sub-text sentences according to the reference relation tuple can shorten the sentence length, reduce the possibility that the sentence contains multiple word segment combinations, and improve the labeling accuracy.
[0105] In some embodiments, the sample sub-text sentence may be annotated using each reference relation tuple in at least one reference relation tuple (which may be called full annotation), that is, a first annotation result of a sample sub-text sentence may be determined based on all reference relation tuples. It may also be annotated based on the associated reference relation tuple of each sample sub-text sentence (which may be called one-to-one annotation), that is, the first annotation result of sample sub-text sentence A may be determined based on the associated reference relation tuple A of sample sub-text sentence A. The associated reference relation tuple of the sample sub-text sentence may be a reference relation tuple corresponding to the sample text sentence to which the sample sub-text sentence belongs. For example, sample text sentence A is segmented to obtain sample sub-text sentence A and sample sub-text sentence B, and the reference relation tuple corresponding to sample text sentence A determined based on the relation extraction template and after the screening process may be used as the associated reference relation tuple of sample sub-text sentence A and sample sub-text sentence B.
[0106] Therefore, taking a sample subtext sentence (target sample subtext sentence) as an example, the labeling process based on at least one reference relation tuple may be that if the target sample subtext sentence includes the first sample segmentation and the second sample segmentation in any reference relation tuple (expressed as the target relation tuple) in all reference relation tuples (or associated reference relation tuples), then in the sample subtext sentence, the first character constituting the first sample segmentation is labeled as the first label, the second character constituting the second sample segmentation is labeled as the second label, and the remaining characters (i.e., the characters other than the first character and the second character in the target sample subtext sentence) are labeled as the third label, thereby obtaining the first labeling result of the sample subtext sentence. The first sample segmentation is the sample segmentation matching the first label in the target relation tuple, and the second sample segmentation is the sample segmentation matching the second label in the target relation tuple.
[0107] In some embodiments, the first label, the second label and the third label may be constructed based on the BIO labeling method, such as the first label may include BN and IN, which are used to represent the starting character and the remaining characters of the first sample segmentation (N), respectively, the second label may include BM and IM, which are used to represent the starting character and the remaining characters of the second sample segmentation (M), respectively, and the third label may be O, which represents the remaining characters. For example, the sample subtext sentence is "ABC is a TV series", and the first labeling result obtained by labeling based on the reference relation tuple [TV series, ABC, X] is: " / 'B-ENT'A / 'I-ENT'B / 'I-ENT'C / 'I-ENT'" / 'I-ENT' is / 'O' part / 'O' TV / 'B-CAT' TV / 'I-CAT' drama / 'I-CAT'; the first labels B-ENT and I-ENT represent hypernyms, and the second labels B-CAT and I-CAT represent hyponyms.
[0108] Among them, if a sample sub-text sentence does not include the first sample participle and the second sample participle in any reference relation tuple or has no associated reference relation tuple, all characters in the sample sub-text sentence are marked as O; if a sample sub-text sentence includes the first sample participle and the second sample participle in multiple reference relation tuples, each first sample participle and each second sample participle in the sample sub-text sentence is marked with the first label and the second label respectively.
[0109] In some embodiments, the first sample participle and the second sample participle in each reference relation tuple may be text-matched with the sample sub-text sentence to determine whether the sample sub-text sentence includes the first sample participle and the second sample participle, or the sample participle in the target participle set corresponding to the sample sub-text sentence may be matched with the first sample participle and the second sample participle in the reference relation tuple to determine whether the sample sub-text sentence includes the first sample participle and the second sample participle.
[0110] In some embodiments, the electronic device can call the first initial template to determine the second annotation result of each sample sub-text sentence, and use the first annotation result as the real result that the first text processing model should output (i.e., as a benchmark), and train the first initial model in combination with the second annotation result. That is, the prediction deviation of the first initial model can be determined in combination with the first annotation result and the second annotation result, and the model parameters of the first initial model can be corrected using the prediction deviation until the model converges, thereby obtaining the first text processing model. The first text processing model can accurately predict the annotation results in the sub-text sentence to determine the first participle and the second participle in the sample sub-text sentence.
[0111] It can be understood that taking the first annotation result as a benchmark means taking the first annotation result as a sample sub-text sentence (training data) for the annotation label (or real annotation result) of the first text processing model to train the first initial model, and the first annotation result is a high-quality training sample obtained by the relation extraction template. Therefore, remote supervision can be achieved by referring to the relation tuple, that is, automatic annotation of the training data, thereby reducing the workload of manual annotation, improving annotation efficiency and annotation accuracy, and training based on shorter sample sub-text sentences can reduce the modeling difficulty of the first text processing model.
[0112] Among them, the above-mentioned first text processing model can also be called a text-based sequence labeling model, which can be constructed based on any model type and topological structure of a deep neural network that can realize the labeling task. For example, it can be a combination of a classic language processing model and CRF (conditional random field). CRF outputs the labeling results of the characters as a decoder. The language processing model can be a BERT (Bidirectional Encoder Representation from Transformers) model, or it can be other language models selected according to the restrictions on model memory usage and the requirements for extraction speed and accuracy in actual application scenarios, such as LSTM (Long Short-Term Memory) model, gated convolutional neural network, FastBERT model (an improved BERT model), SpanBERT model (an improved BERT model), etc.
[0113] S403: Determine at least one second relation tuple according to the multiple sub-text sentences.
[0114] In some embodiments, the second relation tuple may be determined from two subtext sentences. For a specific description of the second relation tuple, reference may be made to the relevant description of the second relation tuple in the above embodiment.
[0115] In some embodiments, determining at least one second relation tuple may specifically be to obtain a set of candidate segmentation words corresponding to each sub-text sentence, the set of candidate segmentation words including the designated segmentation words constituting the corresponding sub-text sentence; construct at least one candidate relation tuple according to the set of candidate segmentation words corresponding to each sub-text sentence, and determine at least one second relation tuple from the at least one candidate relation tuple. Any candidate relation tuple includes two candidate segmentation words, and the two candidate segmentation words are from different sets of candidate segmentation words. It can be understood that when two segmentation words with a designated association relationship exist in two sub-text sentences, the two segmentation words are relatively far apart in the two sub-text sentences and are in different sub-text sentences, making it inconvenient to extract them. Therefore, it can largely solve the problem that if the relation tuple is directly extracted from the two sub-text sentences, there may be inaccurate extraction and the model has a weak ability to extract two segmentation words with a designated association relationship that are relatively far apart in the text sentence.
[0116] In some embodiments, obtaining the candidate word segmentation set may be to determine the word segmentation satisfying the specified part-of-speech condition from the target word segmentation set corresponding to the sub-text sentence as the candidate word segmentation set corresponding to the sub-text sentence. For example, the specified part-of-speech condition may indicate obtaining the word segmentation of the noun part-of-speech. This is not limited here.
[0117] In some embodiments, determining at least one second relationship tuple from at least one candidate relationship tuple can specifically be, based on the relationship prompt words, generating a to-be-processed text sentence corresponding to each candidate relationship tuple, performing text processing on the to-be-processed text sentence corresponding to each candidate relationship tuple, respectively, to obtain the relationship probability of the to-be-processed text sentence corresponding to each candidate relationship tuple, and determining at least one second relationship tuple from at least one candidate relationship tuple according to the relationship probability corresponding to each candidate relationship tuple.
[0118] In some embodiments, at least one candidate relation tuple may be constructed for each candidate segmentation set corresponding to each two subtext sentences. At least one candidate relation tuple may also be constructed for each candidate segmentation set corresponding to each two subtext sentences belonging to the same text sentence. The specific process of constructing the candidate relation tuple may refer to the relevant description of the above embodiments.
[0119] In some embodiments, the relationship prompt word is used to connect two participles in the candidate relationship tuple, which can not only form a sentence containing complete semantics but also shorten the distance between the two participles. The relationship prompt word can be set by relevant business personnel, such as "is", "includes", etc. The connection rule is determined according to the specified association relationship. For example, the specified association relationship is a hyponym relationship, the connection rule is [hypernym] is [hypernym], the candidate relationship tuple is [actor, Zhang San, X], and "actor" represents the first participle (hypernym), "Zhang San" represents the second participle (hypernym), so based on the relationship prompt word, it can be connected to obtain "Zhang San is an actor". The relationship prompt word can be one or more, and a sub-text sentence can correspond to one or more text sentences to be processed.
[0120] In some embodiments, the relationship probability can be used to indicate the probability that the text sentence to be processed contains two candidate participles with a specified association relationship and the two candidate participles in the candidate relationship tuple corresponding to the text sentence to be processed meet the specified association condition. That is, the greater the probability, the greater the possibility that the corresponding candidate relationship tuple is correct. Therefore, the candidate relationship tuple whose relationship probability is greater than the probability threshold can be determined as the second relationship tuple. In addition, when there are multiple text sentences to be processed corresponding to a candidate relationship tuple, each text sentence to be processed corresponds to a relationship probability, and the average relationship probability corresponding to each text sentence to be processed can be used as the final relationship probability, or each relationship probability is weighted and summed, and the result is used as the final relationship probability, and the second relationship tuple is determined using the final relationship probability.
[0121] In some embodiments, the above-mentioned determination of the relational probabilities of the candidate relational tuples to determine at least one first relational tuple may be performed and determined based on the second text processing model. That is, the second initial model may be trained to obtain the second text processing model, and the second text processing model may perform relation prediction on the input text sentence to be processed, and output the relational probabilities corresponding to the candidate relational tuples.
[0122] In some embodiments, training the second initial model to obtain the second text processing model may specifically include obtaining a sample set and a relationship extraction template, determining at least one reference relationship tuple corresponding to multiple sample text sentences in the sample set based on the relationship extraction template, and training the second initial model based on the at least one reference relationship tuple to obtain the second text processing model. The sample set may be the same as or different from the sample set used to train the first text processing model. The specific process of determining the reference relationship tuple based on the relationship extraction template can refer to the process of determining the reference relationship tuple in the process of training the first text processing model, which will not be repeated here. The reference relationship tuple is a high-quality training sample obtained by the relationship extraction template. In addition, the sample set may be pre-processed, and then the relationship extraction template may be used to extract relationship tuples from the pre-processed sample set. The pre-processing process may refer to the pre-processing process of the text sentence set in the above embodiment.
[0123] In some embodiments, the electronic device may set a relationship label for each reference relationship tuple (for example, 1, indicating that the relationship tuple is a correct relationship tuple), and call the second initial model to output the sample relationship probability of each reference relationship tuple, and determine the prediction deviation for the second initial model based on the relationship label and the sample relationship probability, and correct the model parameters based on the prediction deviation to train the second text processing model. Outputting the sample relationship probability of each reference relationship tuple may be to generate the to-be-processed text corresponding to each reference relationship tuple based on the relationship prompt word, and calling the second initial model to predict the to-be-processed text to obtain the corresponding sample relationship probability.
[0124] In some embodiments, the electronic device may further train a second initial model based on at least one reference relationship tuple and other relationship tuples that are filtered out of the initial relationship tuple except for the at least one reference relationship tuple. For example, a relationship label (such as 1) is set for each reference relationship tuple and a relationship label (such as 0, indicating that the relationship tuple is an erroneous relationship tuple) is set for each other relationship tuple, and the second initial model is trained based on the relationship label of the reference relationship tuple and the relationship label of the other relationship tuples and according to the above training process to obtain a second text processing model.
[0125] In some embodiments, the multiple sample text sentences in the sample set include multiple sample sub-text sentences obtained by segmentation based on segmentation characters. Therefore, the specific method of training the second text processing model can also be to determine at least one sample relationship tuple from the multiple sample sub-text sentences, and determine the relationship label of each sample relationship tuple based on at least one reference relationship tuple, generate the to-be-processed text sentence corresponding to each sample relationship tuple based on the relationship prompt word, call the second initial model to perform text processing on the to-be-processed text sentence corresponding to each sample relationship tuple, and respectively generate the relationship probability of the to-be-processed text sentence corresponding to each sample relationship tuple; the relationship probability indicates the probability that two sample word segments in the sample relationship tuple meet the specified association condition, and train the second initial model according to the relationship probability corresponding to each sample relationship tuple and its relationship label to obtain the second text processing model.
[0126] For example, the prediction deviation for the second initial model can be determined based on the relationship probability and relationship label corresponding to each sample relationship tuple, and the model parameters of the second text processing model can be corrected based on the prediction deviation until the model converges to train the second text processing model. The specific method of generating the text sentence to be processed based on the relationship prompt word can refer to the method of generating the text sentence to be processed corresponding to the candidate relationship tuple mentioned above. It will not be repeated here.
[0127] In some embodiments, determining at least one sample relation tuple from a plurality of sample sub-text sentences may be by respectively obtaining a sample segmentation set corresponding to each sample sub-text sentence, and constructing at least one sample relation tuple according to the sample segmentation set corresponding to each sample sub-text sentence; the sample segmentation set includes specified sample segmentations constituting the corresponding sample sub-text sentence, for example, the sample segmentation set includes sample segmentations satisfying a specified part-of-speech condition, such as the specified part-of-speech condition indicating obtaining sample segmentations of noun part-of-speech in the sample sub-text sentence. Any sample relation tuple includes two sample segmentations, and the two sample segmentations come from different sample segmentation sets. The construction method of the sample relation tuple may be the same as the construction method of the candidate relation tuple, that is, the two sample segmentation sets from which the two sample segmentations come may be sample segmentation sets corresponding to any two sample sub-text sentences in a plurality of sample sub-text sentences, or may be sample segmentation sets corresponding to any two sample sub-text sentences obtained by segmenting the same sample text sentence.
[0128] In some embodiments, the relationship label of each sample relationship tuple is determined based on at least one reference relationship tuple. Specifically, if the sample relationship tuple is any reference relationship tuple, then the sample relationship tuple is the first relationship label, such as 1; if the sample relationship tuple is not any reference relationship tuple, then the sample relationship tuple is the second relationship label, such as 0.
[0129] In some embodiments, since the first text processing model determines the first relation tuple by marking the characters in the sub-text sentence, there may be a sub-text sentence in which more than one first participle or second participle is marked, so that more than one first relation tuple is determined based on a sub-text sentence, and therefore the first relation tuple can be further verified by the second text processing model. For example, when a sub-text sentence is marked with two first participles and two second participles, four first relation tuples will be obtained, and therefore, the to-be-processed text corresponding to each first relation tuple can be generated according to the above method, and the text can be input into the second text processing model in turn to obtain the relation probability corresponding to each first relation tuple, and the four first relation tuples can be screened according to the relation probability. Subsequently, the verified first relation tuple and second relation tuple can be used to construct a relational knowledge graph.
[0130] Among them, the above-mentioned second text processing model can also be called a text-based prompt learning model, which can be constructed based on any model type and topological structure of a deep neural network that can realize the annotation task, such as a BERT model and a probability prediction network layer, such as a linear network layer and a SOFTMAX layer (normalization layer). In the second text processing model, the BERT model can perform feature processing on the text sentence to be processed to obtain text sentence features, and the linear network layer and the SOFTMAX layer can perform feature processing on the text sentence features corresponding to the text sentence to be processed to output the relationship probability corresponding to the text sentence to be processed. The BERT model can be replaced by other language models, such as LSTM model, gated convolutional neural network, FastBERT model, SpanBERT model, etc.
[0131] Therefore, by constructing the text to be processed, the text to be processed can be used to realize the prediction of the second text processing model for the candidate relation tuple. The relation prompt word can be understood as the "prompt information" added to the model input, which can make the model input more suitable for the language model, so that the model prediction has a better effect. The construction of simple short sentences by relation prompt words can avoid the defect of directly extracting long sentences with long distances. The relation tuple prediction between two sub-text sentences can be realized, and the prediction target can be achieved by constructing relatively simple and short-distance text sentences to be processed by relation prompt words, which can not only improve the prediction efficiency and accuracy, but also reduce the modeling difficulty of the model. The reference relation tuple determined by the relation extraction template is used to automatically annotate the first initial model and the second initial model, which can realize the automatic annotation of entity relations (i.e., indicating the relationship between the specified segment words in the sub-text sentence) in a remote supervision (a kind of unsupervised training) manner, and intelligently construct training corpus to reduce the manual participation and labor cost in the model training stage, thereby improving the training efficiency, and solving the problem of modeling difficulty when the segment word combination is long in a text sentence. By determining the relation tuples within and between sub-text sentences through the first text processing model and the second text processing model, the determination efficiency and accuracy can be improved, and the determination recall rate of the relation tuples can be improved, thereby realizing the relation extraction for unstructured text and the automatic construction of the knowledge graph.
[0132] In some embodiments, if there are already a large number of high-quality relational tuples, the template extraction module can be skipped, and the large number of relational tuples can be used directly to train the neural network module, such as obtaining a sample set of a part of the relevant field, annotating the sample subtext sentences included in the sample set through the relational tuple as an annotation label, and training the first text processing model based on the sample subtext sentence, and directly using the relational tuple and its relational label to train the second text processing model. That is, there is no need to obtain a sample set, and then use the relation extraction template to extract the reference relational tuple to train the first text processing model and the second text processing model.
[0133] S404: Obtain a relation extraction template, and extract relation tuples from the text sentences in the text sentence set based on the relation extraction template to obtain at least one third relation tuple.
[0134] In some embodiments, the electronic device can construct a relational knowledge graph directly based on (or after being screened according to specified screening rules) at least one first relation tuple and at least one second relation tuple. Alternatively, a relation extraction template can be obtained, and relation tuples can be extracted based on the relation extraction template to obtain at least one third relation tuple, and the at least one first relation tuple and at least one second relation tuple can be used as supplements to at least one third relation tuple to participate in the construction of the relational knowledge graph, such as directly constructing a relational knowledge graph based on (or after being screened according to specified screening rules) the first, second, and third relation tuples.
[0135] Among them, the specified screening rule may be the screening rule described in the above step S402. The acquired relationship extraction template may be a template used when training the first text processing model and the second text processing model. The electronic device may perform relationship tuple extraction on each text sentence in the text sentence set based on the relationship extraction template to obtain at least one third relationship tuple, and the third relationship tuple includes two participles, and the two participles come from the same text sentence, and may come from different sub-text sentences or the same sub-text sentence in the same text sentence. The method of extracting text sentences based on the relationship extraction template may be the same as the method of extracting sample text sentences based on the relationship extraction template, which will not be repeated here.
[0136] S405. Construct a relational knowledge graph corresponding to the text sentence set according to at least one first relation tuple, at least one second relation tuple, and at least one third relation tuple.
[0137] In some embodiments, the electronic device may directly construct a relational knowledge graph based on the at least one first relation tuple, the at least one second relation tuple, and the at least one third relation tuple. Alternatively, data processing may be performed on the at least one first relation tuple, the at least one second relation tuple, and the at least one third relation tuple to obtain a target relation tuple set, and a relational knowledge graph may be constructed based on the target relation tuple set.
[0138] In some embodiments, data processing may include at least one or more of the following: tuple screening processing, tuple deduplication processing. The specific process of the tuple screening process can refer to the screening process described in the above step S402. The tuple deduplication process is used to delete repeated relationship tuples in at least one first relationship tuple, at least one second relationship tuple, and at least one third relationship tuple. Therefore, under the condition of sufficient text corpus, a high-quality relationship knowledge graph can be quickly constructed in a short time through the above method.
[0139] Based on the above description, the present application embodiment provides a schematic diagram of a knowledge graph construction framework, such as Figure 6a-6bAs shown; wherein, it may include a text preprocessing module, a template extraction module, a neural network module, and a graph construction module; the neural network module may include a first text processing model and a second text processing model, the first text processing model may be a sequence tagging model (BERT+CRF), and the second text processing model may be a prompt learning model (BERT+linear network layer+SOFTMAX layer); the construction process of the knowledge graph includes a training phase and an application phase:
[0140] like Figure 6a , the application stage includes: 1) obtaining text corpus, and segmenting it according to the completion identifier to obtain a text sentence set, and preprocessing the text sentences in the text sentence set in the text preprocessing module, and the preprocessing may include: text sentence part-of-speech analysis and text sentence screening. 2) If only the neural network module is used, the preprocessed text sentence S can be segmented based on the segmentation characters to obtain multiple sub-text sentences [S1, S2, ..., Sm], and each character in each sub-text sentence is annotated using the first text processing model, and at least one first relation tuple Ts is determined according to the character annotation results of each sub-text sentence;
[0141] An example of this process: Figure 7a As shown, Figure 7a A schematic diagram of a scenario for determining a first relation tuple based on a first text processing model provided in an embodiment of the present application, wherein each sub-text sentence Si, i∈[1,m] is sequentially input into the first text processing model to obtain a batch of extracted first relation tuples Ts, such as a sub-text sentence Si is "Zhang San is an actor", the BERT model performs feature processing on Si, and the CRF outputs the labeling result of each character in Si, and the first relation tuple [actor, Zhang San, X] is determined based on the labeling result;
[0142] At the same time, based on the part-of-speech analysis results corresponding to the sub-text sentences, the participles that meet the part-of-speech conditions (such as noun part-of-speech) in each sub-text sentence can be obtained as the candidate participle set Ni = [ni1, ni2, ..., nil] of each sub-text sentence Si, and the candidate participle sets of every two sub-text sentences (Si, Sj, 1≤i<j≤m) are combined in pairs to enumerate the candidate relationship tuples [nik, njz, X] between all sub-text sentences, and based on the relationship prompt word "is", the to-be-processed text sentence corresponding to each candidate relationship tuple is generated, and the second text processing model is input in turn to output the relationship probability corresponding to each candidate relationship tuple, and the second relationship tuple Tp is determined according to the relationship probability;
[0143] An example of this process: Figure 7b As shown, Figure 7bA schematic diagram of a scenario for determining a second relation tuple based on a second text processing model provided in an embodiment of the present application, assuming that the candidate segmentation set of Si includes: ball sports; the candidate segmentation set of Sj includes: football, basketball, then the candidate relation tuples L1-4 between Si and Sj are obtained by pairwise combination: [ball sports, football, X], [ball sports, basketball, X], [football, ball sports, X], [basketball, ball sports, X]; and based on the relation prompt word "is", a to-be-processed text sentence K1-4 is generated, such as [ball sports, football, X] → "football is a ball sport", the BERT model performs feature processing on the to-be-processed text sentence, and the linear network layer and the SOFTMAX layer output the relation probability of the to-be-processed text sentence, such as the relation probability of K1 is 0.9, and the candidate relation tuples whose corresponding relation probability is greater than the probability threshold (such as 0.9) can be determined as the second relation tuple, such as [ball sports, football, X], [ball sports, basketball, X];
[0144] The first relation tuple Ts and the second relation tuple Tp can be integrated to obtain the relation tuple output result of the neural network module. Furthermore, the relation tuple output result can be filtered according to the specified filtering rules, and the relation knowledge graph corresponding to the text sentence set can be constructed according to the filtered relation tuple output result.
[0145] 3) Due to the diversity of grammatical structures, the relation extraction template can only extract a part of the relation tuples, and a large number of sub-text sentences containing word combinations are not suitable for the construction of the relation extraction template.
[0146] As shown in Table 4 below:
[0147]
[0148]
[0149] Table 4
[0150] Therefore, the template extraction module and the neural network model can be used at the same time. At least one first relationship tuple and at least one second relationship tuple can be obtained according to the neural network model as a supplement to at least one third relationship tuple obtained according to the template extraction module, and at least one first, second, and third relationship tuple can be filtered according to specified filtering rules, and a relational knowledge graph corresponding to the text sentence set can be constructed according to the filtered results.
[0151] like Figure 6bThe training phase mainly uses the template extraction module to train the neural network model, including: 1) obtaining sample text corpus, segmenting it according to the completion identifier to obtain a sample set, and preprocessing the sample text sentences in the sample set in the text preprocessing module, which preprocessing may include: text sentence part-of-speech analysis and text sentence screening. 2) Using the template extraction module to extract relations from the preprocessed sample text sentences to obtain an initial relationship tuple set, and screening the initial relationship tuple set according to the specified screening rules to obtain at least one reference relationship tuple. 3) Based on the segmentation characters, the preprocessed sample text sentences are segmented to obtain multiple sample sub-text sentences, and each character in the multiple sample sub-text sentences is annotated by at least one reference relationship tuple to obtain a first annotation result, so as to realize automatic annotation based on remote supervision, and the first initial model is called to annotate the characters in each sample sub-text sentence to obtain a second annotation result, and the first annotation result is used as a reference (i.e., label), and the first initial model is trained according to the second annotation result to obtain a first text processing model. 4) Generate a text sentence to be processed corresponding to each reference relation tuple based on the relation extraction words, and train a second initial model according to the text sentence to be processed and its relation label (for example, 1) to obtain a second text processing model.
[0152] In an embodiment of the present application, a text sentence set can be obtained, and the text sentences in the text sentence set can be segmented based on segmentation characters to obtain multiple sub-text sentences, at least one first relationship tuple can be determined based on the multiple sub-text sentences, at least one second relationship tuple can be determined based on the multiple sub-text sentences, a relationship extraction template can be obtained, and the text sentences in the text sentence set can be extracted from relationship tuples based on the relationship extraction template to obtain at least one third relationship tuple, and a relationship knowledge graph corresponding to the text sentence set can be constructed based on at least one first relationship tuple, at least one second relationship tuple, and at least one third relationship tuple. Through the above method, multiple relationship tuples can be determined based on the content within a sub-text sentence and the content between two sub-text sentences, so that the relationship tuples can be determined based on the text sentences in a more fine-grained and comprehensive manner, making the constructed knowledge graph more accurate and reliable.
[0153] The method of the embodiment of the present application is described in detail above. In order to facilitate better implementation of the above scheme of the embodiment of the present application, the device of the embodiment of the present application is provided below accordingly.
[0154] Figure 8 A schematic diagram of the structure of a text processing device provided by an exemplary embodiment of the present application is shown; the text processing device can be used as a computer program (including program code) running in an electronic device, for example, the text processing device can be an application program in the electronic device; the text processing device can be used to execute Figure 2 and Figure 4Some or all of the steps in the method embodiment shown. Figure 8 , the text processing device includes the following modules:
[0155] The acquisition module 801 is used to acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences;
[0156] A processing module 802 is used to determine at least one first relation tuple according to a plurality of subtext sentences; a first relation tuple includes two participles, the two participles are from the same subtext sentence and have a specified association relationship;
[0157] The processing module 802 is further configured to determine at least one second relation tuple according to the plurality of subtext sentences; a second relation tuple includes two participles, the two participles are from different subtext sentences and have a specified association relationship;
[0158] The processing module 802 is further used to construct a relational knowledge graph corresponding to the text sentence set according to at least one first relation tuple and at least one second relation tuple.
[0159] In some embodiments, when the processing module 802 is used to determine at least one first relation tuple according to a plurality of sub-text sentences, it is specifically used to:
[0160] Performing a tagging process on each character in a target sub-text sentence; the target sub-text sentence is any one of the multiple sub-text sentences;
[0161] Determine a first word segmentation according to the characters marked as the first label, and determine a second word segmentation according to the characters marked as the second label; wherein the word segmentation determined according to the first label has a specified association relationship with the word segmentation determined according to the second label;
[0162] At least one first relation tuple is constructed based on the first participle and the second participle; any first relation tuple includes a first participle and a second participle.
[0163] In some embodiments, when the processing module 802 is used to determine at least one second relation tuple according to a plurality of sub-text sentences, it is specifically used to:
[0164] Obtaining a candidate word segmentation set corresponding to each sub-text sentence respectively; the candidate word segmentation set includes the specified word segmentation constituting the corresponding sub-text sentence;
[0165] Construct at least one candidate relation tuple according to the candidate segmentation set corresponding to each subtext sentence; any candidate relation tuple includes two candidate segmentations, and the two candidate segmentations are from different candidate segmentation sets;
[0166] At least one second relation tuple is determined from the at least one candidate relation tuple.
[0167] In some embodiments, when the processing module 802 is used to determine at least one second relation tuple from at least one candidate relation tuple, it is specifically used to:
[0168] Generate a text sentence to be processed corresponding to each candidate relation tuple based on the relation prompt word;
[0169] Perform text processing on the to-be-processed text sentences corresponding to each candidate relation tuple respectively, and obtain the relation probability of the to-be-processed text sentences corresponding to each candidate relation tuple; the relation probability indicates the probability that two candidate participles in the candidate relation tuple meet the specified association condition;
[0170] At least one second relation tuple is determined from at least one candidate relation tuple according to the relation probability corresponding to each candidate relation tuple.
[0171] In some embodiments, the processing module 802 is further configured to:
[0172] Acquire a relation extraction template, and extract relation tuples from the text sentences in the text sentence set based on the relation determination template to obtain at least one third relation tuple;
[0173] When the processing module 802 is used to construct a relational knowledge graph corresponding to a text sentence set according to at least one first relation tuple and at least one second relation tuple, it is specifically used to:
[0174] Performing data processing on at least one first relation tuple, at least one second relation tuple, and at least one third relation tuple to obtain a target relation tuple set; the data processing includes at least one of the following: tuple screening processing, tuple deduplication processing;
[0175] Construct a relational knowledge graph based on the target relation tuple set.
[0176] In some embodiments, at least one first relation tuple is determined based on a first text processing model; at least one second relation tuple is determined based on a second text processing model; and the processing module 802 is further configured to:
[0177] Obtain a sample set and a relationship extraction template;
[0178] Based on the relation extraction template, relation tuples are extracted from multiple sample text sentences in the sample set to obtain an initial relation tuple set, and the initial relation tuple set is screened to obtain at least one reference relation tuple; any reference relation tuple includes two sample participles, and the two sample participles have a specified association relationship;
[0179] Training a first initial model based on a plurality of sample text sentences and at least one reference relation tuple to obtain a first text processing model;
[0180] The second initial model is trained based on at least one reference relation tuple to obtain a second text processing model.
[0181] In some embodiments, the plurality of sample text sentences include a plurality of sample sub-text sentences obtained by segmentation based on segmentation characters; when the processing module 802 is used to train the first initial model based on the plurality of sample text sentences and at least one reference relation tuple to obtain the first text processing model, it is specifically used to:
[0182] Based on at least one reference relation tuple, each character in each sample sub-text sentence is labeled to obtain first labeling results for the plurality of sample sub-text sentences;
[0183] Calling the first initial model to perform annotation processing on each sample sub-text sentence respectively, to obtain second annotation results for the plurality of sample sub-text sentences;
[0184] Taking the first annotation result as a benchmark, a first initial model is trained based on the second annotation result to obtain a first text processing model.
[0185] In some embodiments, any one of the multiple sample sub-text sentences is represented as a target sample sub-text sentence; when the processing module 802 is used to perform labeling processing on each character in each sample sub-text sentence based on at least one reference relation tuple to obtain a first labeling result for the multiple sample sub-text sentences, it is specifically used to:
[0186] If the target sample sub-text sentence includes a first sample segmentation word and a second sample segmentation word, the first character constituting the first sample segmentation word is marked as a first label, the second character constituting the second sample segmentation word is marked as a second label, and the characters other than the first character and the second character in the target sample sub-text sentence are marked as a third label;
[0187] The first sample segmentation is a sample segmentation matching the first label in the target relation tuple, the second sample segmentation is a sample segmentation matching the second label in the target relation tuple, and the target relation tuple is any one of at least one reference relation tuple.
[0188] According to one embodiment of the present application, Figure 8The various modules in the text processing device shown can be individually or completely combined into one or several other modules to form a structure, or one (or some) of the modules can be further divided into multiple modules with smaller functions to form a structure, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above modules are divided based on logical functions. In actual applications, the function of one module can also be implemented by multiple modules, or the functions of multiple modules can be implemented by one module. In other embodiments of the present application, the text processing device may also include other modules. In actual applications, these functions can also be implemented with the assistance of other modules, and can be implemented by the collaboration of multiple modules. According to another embodiment of the present application, the following can be performed by running on a general computing device such as a computer including processing elements and storage elements such as a central processing module (CPU), a random access storage medium (RAM), and a read-only storage medium (ROM). Figure 2 and Figure 4 A computer program (including program code) for each step involved in the corresponding method shown in FIG. Figure 8 The text processing device shown in the embodiment of the present application is implemented by the text processing method. The computer program can be recorded on a computer-readable recording medium, for example, and loaded into the above-mentioned computing device through the computer-readable recording medium and run therein.
[0189] In the embodiment of the present application, the acquisition module acquires a text sentence set, and segments the text sentences in the text sentence set based on segmentation characters to obtain multiple sub-text sentences; the processing module determines at least one first relation tuple based on the multiple sub-text sentences; the processing module determines at least one second relation tuple based on the multiple sub-text sentences; the processing module constructs a relational knowledge graph corresponding to the text sentence set based on at least one first relation tuple and at least one second relation tuple. Through the above device, multiple relation tuples can be determined based on the content within a sub-text sentence and the content between two sub-text sentences, so that the relation tuples can be determined based on the text sentences in a more fine-grained and comprehensive manner, making the constructed knowledge graph more accurate and reliable.
[0190] See also Fig. 9 , Fig. 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig. 9As shown, the electronic device 900 includes: at least one processor 901 and a memory 902. Optionally, the electronic device may further include a network interface. The processor 901, the memory 902 and the network interface may exchange data, the network interface is controlled by the processor 901 to send and receive messages, the memory 902 is used to store a computer program, the computer program includes program instructions, and the processor 901 is used to execute the program instructions stored in the memory 902. The processor 901 is configured to call the program instructions to execute the above method.
[0191] Among them, the memory 902 may include a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 902 may also include a non-volatile memory (non-volatile memory), such as a flash memory (flash memory), a solid-state drive (SSD), etc.; the memory 902 may also include a combination of the above types of memory.
[0192] The processor 901 may be a central processing unit (CPU). In one embodiment, the processor 901 may also be a graphics processing unit (GPU). The processor 901 may also be a combination of a CPU and a GPU.
[0193] In a possible implementation, the memory 902 is used to store program instructions, and the processor 901 may call the program instructions to perform the following steps:
[0194] Acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain multiple sub-text sentences;
[0195] Determine at least one first relation tuple according to the plurality of subtext sentences; a first relation tuple includes two participles, the two participles are from the same subtext sentence and have a specified association relationship;
[0196] Determine at least one second relation tuple according to the plurality of subtext sentences; a second relation tuple includes two participles, the two participles are from different subtext sentences and have a specified association relationship;
[0197] A relational knowledge graph corresponding to the text sentence set is constructed according to at least one first relation tuple and at least one second relation tuple.
[0198] In some embodiments, when the processor 901 is used to determine at least one first relation tuple according to a plurality of sub-text sentences, it is specifically used to:
[0199] Performing a tagging process on each character in a target sub-text sentence; the target sub-text sentence is any one of the multiple sub-text sentences;
[0200] Determine a first word segmentation according to the characters marked as the first label, and determine a second word segmentation according to the characters marked as the second label; wherein the word segmentation determined according to the first label has a specified association relationship with the word segmentation determined according to the second label;
[0201] At least one first relation tuple is constructed based on the first participle and the second participle; any first relation tuple includes a first participle and a second participle.
[0202] In some embodiments, when the processor 901 is used to determine at least one second relation tuple according to a plurality of sub-text sentences, it is specifically used to:
[0203] Obtaining a candidate word segmentation set corresponding to each sub-text sentence respectively; the candidate word segmentation set includes the specified word segmentation constituting the corresponding sub-text sentence;
[0204] Construct at least one candidate relation tuple according to the candidate segmentation set corresponding to each subtext sentence; any candidate relation tuple includes two candidate segmentations, and the two candidate segmentations are from different candidate segmentation sets;
[0205] At least one second relation tuple is determined from the at least one candidate relation tuple.
[0206] In some embodiments, when the processor 901 is used to determine at least one second relation tuple from at least one candidate relation tuple, it is specifically used to:
[0207] Generate a text sentence to be processed corresponding to each candidate relation tuple based on the relation prompt word;
[0208] Perform text processing on the to-be-processed text sentences corresponding to each candidate relation tuple respectively, and obtain the relation probability of the to-be-processed text sentences corresponding to each candidate relation tuple; the relation probability indicates the probability that two candidate participles in the candidate relation tuple meet the specified association condition;
[0209] At least one second relation tuple is determined from at least one candidate relation tuple according to the relation probability corresponding to each candidate relation tuple.
[0210] In some embodiments, the processor 901 is further configured to:
[0211] Acquire a relation extraction template, and extract relation tuples from the text sentences in the text sentence set based on the relation determination template to obtain at least one third relation tuple;
[0212] When the processor 901 is used to construct a relational knowledge graph corresponding to a text sentence set according to at least one first relation tuple and at least one second relation tuple, it is specifically used to:
[0213] Performing data processing on at least one first relation tuple, at least one second relation tuple, and at least one third relation tuple to obtain a target relation tuple set; the data processing includes at least one of the following: tuple screening processing, tuple deduplication processing;
[0214] Construct a relational knowledge graph based on the target relation tuple set.
[0215] In some embodiments, at least one first relation tuple is determined based on a first text processing model; at least one second relation tuple is determined based on a second text processing model; and the processor 901 is further configured to:
[0216] Obtain a sample set and a relationship extraction template;
[0217] Based on the relation extraction template, relation tuples are extracted from multiple sample text sentences in the sample set to obtain an initial relation tuple set, and the initial relation tuple set is screened to obtain at least one reference relation tuple; any reference relation tuple includes two sample participles, and the two sample participles have a specified association relationship;
[0218] Training a first initial model based on a plurality of sample text sentences and at least one reference relation tuple to obtain a first text processing model;
[0219] The second initial model is trained based on at least one reference relation tuple to obtain a second text processing model.
[0220] In some embodiments, the plurality of sample text sentences include a plurality of sample sub-text sentences obtained by segmentation based on segmentation characters; when the processor 901 is used to train the first initial model based on the plurality of sample text sentences and at least one reference relation tuple to obtain the first text processing model, it is specifically used to:
[0221] Based on at least one reference relation tuple, each character in each sample sub-text sentence is labeled to obtain first labeling results for the plurality of sample sub-text sentences;
[0222] Calling the first initial model to perform annotation processing on each sample sub-text sentence respectively, to obtain second annotation results for the plurality of sample sub-text sentences;
[0223] Taking the first annotation result as a benchmark, a first initial model is trained based on the second annotation result to obtain a first text processing model.
[0224] In some embodiments, any one of the multiple sample sub-text sentences is represented as a target sample sub-text sentence; when the processor 901 is used to perform a tagging process on each character in each sample sub-text sentence based on at least one reference relation tuple to obtain a first tagging result for the multiple sample sub-text sentences, it is specifically used to:
[0225] If the target sample sub-text sentence includes a first sample segmentation word and a second sample segmentation word, the first character constituting the first sample segmentation word is marked as a first label, the second character constituting the second sample segmentation word is marked as a second label, and the characters other than the first character and the second character in the target sample sub-text sentence are marked as a third label;
[0226] The first sample segmentation is a sample segmentation matching the first label in the target relation tuple, the second sample segmentation is a sample segmentation matching the second label in the target relation tuple, and the target relation tuple is any one of at least one reference relation tuple.
[0227] In an embodiment of the present application, the processor can obtain a set of text sentences, and segment the text sentences in the set of text sentences based on segmentation characters to obtain multiple sub-text sentences, determine at least one first relationship tuple based on the multiple sub-text sentences, determine at least one second relationship tuple based on the multiple sub-text sentences, and construct a relational knowledge graph corresponding to the set of text sentences based on at least one first relationship tuple and at least one second relationship tuple. In the above scheme, multiple relationship tuples can be determined based on the content within a sub-text sentence and the content between two sub-text sentences, so that the relationship tuples can be determined based on the text sentences in a more fine-grained and comprehensive manner, making the constructed knowledge graph more accurate and reliable.
[0228] In a specific implementation, the above-described device, processor, memory, etc. can execute the implementation described in the above-mentioned method embodiment, and can also execute the implementation described in the embodiment of the present application, which will not be repeated here.
[0229] A computer (readable) storage medium is also provided in an embodiment of the present application, and the computer storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by the processor, the processor can execute some or all of the steps performed in the above method embodiment. Optionally, the computer storage medium can be volatile or non-volatile. The computer-readable storage medium can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function, etc.; the data storage area can store data created according to the use of the blockchain node, etc.
[0230] The embodiment of the present application also provides a computer program product, which includes computer instructions (program instructions), and when the computer instructions are executed by a processor, some or all of the steps in the above-mentioned text processing method can be implemented. Optionally, the computer instructions can be stored in a computer-readable storage medium, and a processor of a computer device such as an electronic device reads the program instructions from the computer-readable storage medium, and the processor executes the program instructions, so that the computer device performs the above-mentioned text processing method.
[0231] The term "multiple" as used herein refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0232] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. 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.
[0233] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from a website site, a computer, a server or a data center to another website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
[0234] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A text processing method, characterized in that: The method comprises: Acquire a text sentence set, and segment the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences; Determine at least one first relation tuple according to the plurality of subtext sentences; a first relation tuple includes two participles, the two participles are from the same subtext sentence and have a specified association relationship; Respectively obtain a candidate word segmentation set corresponding to each sub-text sentence, and construct at least one candidate relation tuple according to the candidate word segmentation set corresponding to each sub-text sentence; the candidate word segmentation set includes designated word segments constituting the corresponding sub-text sentence, and any candidate relation tuple includes two candidate word segments, and the two candidate word segments are from different candidate word segmentation sets; Generate a to-be-processed text sentence corresponding to each candidate relation tuple based on the relation prompt word, and perform text processing on the to-be-processed text sentence corresponding to each candidate relation tuple respectively, to obtain the relation probability of the to-be-processed text sentence corresponding to each candidate relation tuple, wherein the relation probability is used to indicate the probability that two candidate participles in the candidate relation tuple meet the specified association condition; determine at least one second relation tuple from the at least one candidate relation tuple according to the relation probability corresponding to each candidate relation tuple; the relation prompt word is used to connect the two candidate participles in the candidate relation tuple, and the connection rule corresponding to the relation prompt word is determined according to the specified association relationship; a second relation tuple includes two participles, and the two participles are from different sub-text sentences and have the specified association relationship; A relational knowledge graph corresponding to the text sentence set is constructed according to the at least one first relation tuple and the at least one second relation tuple.
2. The method according to claim 1, characterized in that The determining at least one first relation tuple according to the plurality of sub-text sentences comprises: Performing a tagging process on each character in a target sub-text sentence; the target sub-text sentence is any one of the multiple sub-text sentences; Determine a first word segmentation according to the characters marked as the first label, and determine a second word segmentation according to the characters marked as the second label; wherein the word segmentation determined according to the first label and the word segmentation determined according to the second label have the specified association relationship; The at least one first relation tuple is constructed based on the first participle and the second participle; any first relation tuple includes a first participle and a second participle.
3. The method according to claim 1, characterized in that The method further comprises: Acquire a relation extraction template, and extract relation tuples from the text sentences in the text sentence set based on the relation determination template to obtain at least one third relation tuple; The step of constructing a relational knowledge graph corresponding to the text sentence set according to the at least one first relation tuple and the at least one second relation tuple includes: Performing data processing on the at least one first relation tuple, the at least one second relation tuple, and the at least one third relation tuple to obtain a target relation tuple set; the data processing includes at least one of the following: tuple screening processing, tuple deduplication processing; The relational knowledge graph is constructed according to the target relational tuple set.
4. The method according to claim 1, characterized in that: The at least one first relation tuple is determined based on a first text processing model; the at least one second relation tuple is determined based on a second text processing model; the method further comprises: Obtain a sample set and a relationship extraction template; Based on the relation extraction template, relation tuples are extracted from a plurality of sample text sentences in the sample set to obtain an initial relation tuple set, and the initial relation tuple set is screened to obtain at least one reference relation tuple; any reference relation tuple includes two sample participles, and the two sample participles have the specified association relationship; Training a first initial model based on the multiple sample text sentences and the at least one reference relation tuple to obtain the first text processing model; the first text processing model is used for text annotation; The second initial model is trained based on the at least one reference relation tuple to obtain the second text processing model; the second text processing model is used to determine the relation probability.
5. The method according to claim 4, characterized in that The plurality of sample text sentences include a plurality of sample sub-text sentences obtained by segmentation based on the segmentation characters; the first initial model is trained based on the plurality of sample text sentences and the at least one reference relation tuple to obtain the first text processing model, including: Based on the at least one reference relation tuple, each character in each sample sub-text sentence is respectively labeled to obtain a first labeling result for the plurality of sample sub-text sentences; Calling the first initial model to perform annotation processing on each of the sample sub-text sentences respectively, to obtain second annotation results for the multiple sample sub-text sentences; Taking the first annotation result as a benchmark, the first initial model is trained based on the second annotation result to obtain the first text processing model.
6. The method according to claim 5, characterized in that Any one of the multiple sample sub-text sentences is represented as a target sample sub-text sentence; and the tagging process is performed on each character in each sample sub-text sentence based on the at least one reference relation tuple to obtain a first tagging result for the multiple sample sub-text sentences, including: If the target sample sub-text sentence includes a first sample segmentation word and a second sample segmentation word, a first character constituting the first sample segmentation word is marked as a first label, a second character constituting the second sample segmentation word is marked as a second label, and characters other than the first character and the second character in the target sample sub-text sentence are marked as a third label; The first sample segmentation is a sample segmentation in a target relation tuple that matches the first label, the second sample segmentation is a sample segmentation in the target relation tuple that matches the second label, and the target relation tuple is any one of the at least one reference relation tuple.
7. A text processing device, characterized in that: The device comprises: An acquisition module, used for acquiring a text sentence set, and segmenting the text sentences in the text sentence set based on segmentation characters to obtain a plurality of sub-text sentences; A processing module, configured to determine at least one first relation tuple according to the plurality of sub-text sentences; a first relation tuple includes two participles, the two participles are from the same sub-text sentence and have a specified association relationship; The processing module is further used to obtain a candidate word set corresponding to each sub-text sentence, and construct at least one candidate relationship tuple according to the candidate word set corresponding to each sub-text sentence; the candidate word set includes designated word sets constituting the corresponding sub-text sentence, and any candidate relationship tuple includes two candidate word sets, and the two candidate word sets come from different candidate word sets; based on the relationship prompt word, a to-be-processed text sentence corresponding to each candidate relationship tuple is generated, and text processing is performed on the to-be-processed text sentence corresponding to each candidate relationship tuple to obtain a relationship probability of the to-be-processed text sentence corresponding to each candidate relationship tuple, and the relationship probability is used to indicate the probability that the two candidate word sets in the candidate relationship tuple meet the designated association condition; at least one second relationship tuple is determined from the at least one candidate relationship tuple according to the relationship probability corresponding to each candidate relationship tuple; the relationship prompt word is used to connect the two candidate word sets in the candidate relationship tuple, and the connection rule corresponding to the relationship prompt word is determined according to the designated association relationship; a second relationship tuple includes two word sets, and the two word sets come from different sub-text sentences and have the designated association relationship; The processing module is also used to construct a relational knowledge graph corresponding to the text sentence set based on the at least one first relation tuple and the at least one second relation tuple.
8. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The computer program product comprises computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method and device for constructing medical knowledge graph
CN107657063A
Automatic recognition algorithm for semantic relations of Chinese natural language entities
CN109062894A
Medicine knowledge graph construction method and device, computer equipment and storage medium
CN110390021A
Knowledge extraction method and device based on deep learning
CN111709243A
Method for constructing verb phrase implication map and related equipment
CN112149427A
