Text-based task processing method and device, computer device and storage medium
By querying relevant words in the knowledge graph of the target domain and constructing a text tree, the technical problem of semantic extraction is solved, and the accuracy of semantic extraction in natural language processing tasks is improved. The accuracy of semantic extraction is improved by constructing a text tree, and the accuracy of semantic extraction is improved by constructing a text embedding representation, thereby enhancing the accuracy of semantic features and improving the overall accuracy of the task.
Patent Information
- Application Number
- CN202111205769.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-15
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2042-02-17
AI Technical Summary
In specialized domains, existing technologies for natural language processing tasks exhibit low semantic extraction accuracy, impacting task overall accuracy.
By querying relevant words in the knowledge graph of the target domain and constructing a text tree, the relevant words are fused with the input text to construct a text embedding representation for semantic extraction and task processing.
It improves the accuracy of semantic extraction in natural language processing tasks, thus enhancing the overall accuracy of the task.
Smart Images

Figure CN114282001B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular relates to a text-based task processing method and device, computer equipment and a storage medium. BACKGROUND
[0002] Natural language processing is an important technical means for realizing human-computer interaction and the like based on artificial intelligence (AI).
[0003] In related technologies, a natural language processing task can be subjected to semantic extraction through a semantic encoding network to obtain semantic features, and then subjected to task processing in a specified application scenario, such as intelligent dialogue, intelligent query and the like, through the extracted semantic features. In order to achieve a good semantic extraction effect, the semantic encoding network usually needs to be pre-trained through large-scale corpus.
[0004] However, large-scale corpus is usually general corpus, and in a special field, many words usually have specific meanings, and therefore the semantic extraction accuracy of the scheme shown in the related technologies is low when processing a natural language processing task in a special field, thereby affecting the accuracy of the natural language processing task. SUMMARY
[0005] The embodiments of the present application provide a text-based task processing method and device, computer equipment and a storage medium, which can improve the accuracy of semantic extraction in a natural language processing task, and thereby improve the accuracy of the natural language processing task. The technical scheme is as follows:
[0006] In one aspect, a text-based task processing method is provided, and the method comprises:
[0007] Based on each text word in an input text, relevant knowledge is queried in a knowledge graph of a target field to obtain relevant words corresponding to the each text word respectively;
[0008] A text tree is constructed based on the each text word and the relevant words corresponding to the each text word respectively; the text tree is used to indicate a connection relationship between the each text word and the relevant words corresponding to the each text word respectively;
[0009] A text embedding representation of the input text is constructed based on the text tree;
[0010] Semantic extraction is performed on the text embedding representation of the input text to obtain semantic features of the input text;
[0011] The input text is subjected to target text task processing based on the semantic features of the input text.
[0012] In another aspect, provided is a text-based task processing apparatus, the apparatus comprising:
[0013] a knowledge query module configured to, based on each text word in the input text, perform a relevant knowledge query in a knowledge graph of a target domain to obtain a relevant word corresponding to the text word;
[0014] a text tree construction module configured to construct a text tree based on the text word and the relevant word corresponding to the text word; the text tree being configured to indicate a connection relationship between the text word and the relevant word corresponding to the text word;
[0015] an embedding representation construction module configured to construct a text embedding representation of the input text based on the text tree;
[0016] a semantic extraction module configured to perform semantic extraction on the text embedding representation of the input text to obtain a semantic feature of the input text;
[0017] a task processing module configured to perform a target text task processing on the input text based on the semantic feature of the input text.
[0018] In a possible implementation, the relevant word comprises a relationship word and an entity word; the entity word represents an entity corresponding to the text word in the knowledge graph; and the relationship word represents an entity relationship between the entity word and the text word in the knowledge graph.
[0019] The text tree construction module is configured to construct the text tree based on an order of the text word in the input text and a corresponding relationship between the relevant word and the text word.
[0020] In the text tree, adjacent text words are directly connected; and the text word and the corresponding entity word are indirectly connected through the relationship word.
[0021] In a possible implementation, the text embedding representation of the input text comprises a respective corresponding embedding representation of each word in the text tree.
[0022] The embedding representation comprises a word embedding, a position embedding and a segment embedding.
[0023] The position embedding is configured to represent a level of the corresponding word in the text tree; and the segment embedding is configured to represent a sentence to which the corresponding word belongs.
[0024] In a possible implementation, the apparatus further comprises:
[0025] a visual matrix construction module, configured to construct a visual matrix based on the text tree before the semantic extraction module performs semantic extraction on the text embedding representation of the input text to obtain semantic features of the input text; the visual matrix is used to indicate distance relationships between each word in the text tree;
[0026] a semantic extraction module, configured to perform semantic extraction on the text embedding representation of the input text based on the visual matrix to obtain semantic features of the input text.
[0027] In a possible implementation, the visual matrix contains distance attribute values between each two words in the text tree;
[0028] The visual matrix construction module is configured to,
[0029] in response to the first word and the second word belonging to the input text, or the first word and the second word belonging to the same knowledge triple, setting the distance attribute value between the first word and the second word to 0; the first word and the second word are any two words in the text tree;
[0030] in response to the first word and the second word not belonging to the input text and not belonging to the same knowledge triple, setting the distance attribute value between the first word and the second word to negative infinity.
[0031] In a possible implementation, the semantic extraction module is configured to,
[0032] obtaining a query vector matrix, a key vector matrix and a value vector matrix based on the text embedding representation of the input text;
[0033] obtaining a self-attention matrix based on the query vector matrix, the key vector matrix and the visual matrix;
[0034] obtaining semantic features of the input text based on the self-attention matrix and the value vector matrix.
[0035] In still another aspect, a computer device is provided, which includes a processor and a memory, and the memory stores at least one computer instruction, which is loaded and executed by the processor to implement the above-mentioned text-based task processing method.
[0036] In still another aspect, a computer readable storage medium is provided, which stores at least one computer instruction, which is loaded and executed by a processor to implement the above-mentioned text-based task processing method.
[0037] In yet another aspect, a computer program product or computer program is provided, which includes computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the above text-based task processing method.
[0038] The technical scheme provided by the embodiments of the present application has at least the following beneficial effects:
[0039] When processing a natural language processing task in a target field, a text word in an input text can be used to query related words in a knowledge graph of the target field, and the related words queried can be fused with the input text by constructing a text tree. Subsequently, semantic features can be extracted and the task can be processed by using the constructed text tree. Since the related words of the target field are fused in the input text, the semantic features extracted subsequently can more accurately represent the semantics of the input text in the target field, thereby improving the accuracy of semantic extraction in the natural language processing task and further improving the accuracy of the natural language processing task.
[0040] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF DRAWINGS
[0041] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.
[0042] Figure 1 is a structural schematic diagram of a text-based task processing system according to an exemplary embodiment;
[0043] Figure 2 is a flowchart of a text-based task processing method according to an exemplary embodiment;
[0044] Figure 3 is a framework diagram of a natural language task processing model generation and natural language task processing according to an exemplary embodiment;
[0045] Figure 4 is a flowchart of a text-based task processing method according to an exemplary embodiment;
[0046] Figure 5 is Figure 4 is a text tree schematic diagram according to the embodiment shown in the figure;
[0047] Figure 6 is Figure 4An embedded layer diagram according to an example embodiment;
[0048] Figure 7 is Figure 4 A model framework diagram according to an example embodiment;
[0049] Figure 8 is a structural block diagram of a text-based task processing apparatus according to an example embodiment;
[0050] Figure 9 is a structural diagram of a computer device according to an example embodiment. DETAILED DESCRIPTION
[0051] The example embodiments will be described in detail with reference to the accompanying drawings. In the following description, same numbers refer to same elements throughout the drawings. The following example embodiments are not representative of all embodiments consistent with the present application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the present application, as detailed in the appended claims.
[0052] Before the various embodiments of the present application are described, several concepts related to the present application are introduced:
[0053] 1) AI (Artificial Intelligence)
[0054] AI is the use of digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, to perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology of computer science, which tries to understand the essence of intelligence and produce a new intelligent machine that can react in a similar way to human intelligence. Artificial intelligence is the design principle and implementation method of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making. Artificial intelligence technology is a comprehensive discipline, involving a wide range of fields, both hardware and software technologies. Artificial intelligence basic technologies generally include technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics, etc. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning, etc.
[0055] 2) NLP (Nature Language Processing)
[0056] NLP is an important direction in the field 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, the research in this field will involve natural language, i.e. the language used in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question and answer, knowledge graph and other technologies.
[0057] 3) ML (Machine Learning, Machine Learning)
[0058] Machine learning is a multi-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It is a subject that studies how computers simulate or implement human learning behavior to acquire new knowledge or skills, reorganize existing knowledge structure to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental approach to making computers intelligent. Its applications are widespread in various fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.
[0059] Figure 1 is a structural schematic diagram of a text-based task processing system according to an exemplary embodiment. The system includes a server 120 and a user terminal 140.
[0060] The server 120 is a server, or includes several servers, or is a virtualization platform, or is a cloud computing service center, etc., which is not limited by the present application.
[0061] The user terminal 140 can be a terminal device with data processing function, for example, the user terminal can be a mobile phone, a tablet computer, a laptop computer and a desktop computer, etc. The number of user terminals 140 is not limited.
[0062] Among them, the user terminal 140 can be installed with a client, which can be an office client, an instant messaging client, a browser client, an education client, etc., a client with voice input function or text input function. The software type of the client is not limited in the embodiment of the present application.
[0063] Optionally, the user can input text information through the text input software in the client in the user terminal 140.
[0064] Optionally, users can also input voice information via the voice acquisition component in user terminal 140. User terminal 140 then calls the corresponding voice recognition function to convert the user's voice information into text information.
[0065] Optionally, the voice recognition function can be implemented by the user terminal 140 calling the voice recognition module in the user terminal 140.
[0066] Optionally, the speech recognition function can be implemented by the user terminal 140 calling the speech recognition module in the server corresponding to the client.
[0067] User terminal 140 and server 120 are connected via a communication network. Optionally, the communication network can be a wired network or a wireless network.
[0068] Optionally, the system may also include a management device ( Figure 1 (Not shown), the management device is connected to the server 120 via a communication network. Optionally, the communication network can be a wired network or a wireless network.
[0069] Optionally, the aforementioned wireless or wired networks use standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to LAN (Local Area Network), MAN (Metropolitan Area Network), WAN (Wide Area Network), mobile, wired or wireless networks, private networks, or any combination of virtual private networks. In some embodiments, technologies and / or formats including HTML (Hypertext Markup Language), XML (Extensible Markup Language), etc., are used to represent data exchanged over the network. Furthermore, conventional encryption technologies such as SSL (Secure Socket Layer), TLS (Transport Layer Security), VPN (Virtual Private Network), and IPsec (Internet Protocol Security) can be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can be used to replace or supplement the aforementioned data communication technologies.
[0070] Optionally, the system according to the embodiments of the present application can be a distributed system formed by a client, a plurality of nodes (any form of computing device in an access network, such as a server, a terminal) connected through network communication.
[0071] Optionally, the distributed system can be a blockchain system.
[0072] Optionally, the text-based task processing method disclosed in the present application, the data involved in the text-based task processing method, and the model for processing the data can be stored in the blockchain system.
[0073] Figure 2 is a flowchart of a text-based task processing method according to an exemplary embodiment. The method can be performed by a computer device. For example, the computer device can be a terminal or a server; or the computer device can include a terminal and a server. The server can be the server 120 in the embodiment shown in Figure 1 , and the terminal can be the user terminal 140 in the embodiment shown in Figure 1 . As shown in Figure 2 , the text-based task processing method can include the following steps:
[0074] Step 21: Based on each text word in the input text, querying related knowledge in the knowledge graph of the target field to obtain related words corresponding to each text word.
[0075] In the embodiments of the present application, when processing a task in a target field (such as a natural language processing task), the computer device can receive an input text and perform word segmentation processing on the input text to obtain each text word therein.
[0076] For each text word, the computer device can query the knowledge graph for knowledge content associated with the text word to obtain related words in the target field corresponding to the text word.
[0077] Step 22: Based on each text word and the related words corresponding to each text word, a text tree is constructed; the text tree is used to indicate the connection relationship between each text word and the related words corresponding to each text word.
[0078] In the embodiments of the present application, after the computer device queries the related words corresponding to each text word in the knowledge graph of the target field, the computer device can insert the queried related words into the positions of the corresponding text words to obtain a text tree after fusing the text words and the related words.
[0079] In the above text tree, there is a connection relationship between each related word and the corresponding text word.
[0080] Step 23, constructing a text embedding representation of the input text based on the text tree.
[0081] In the embodiments of the present application, in order to facilitate subsequent semantic extraction and task processing, the computer device can convert the text into a text embedding representation based on the text tree.
[0082] The text embedding representation can also be implemented as a vector matrix for representing the input text, so as to perform subsequent feature extraction and the like.
[0083] Step 24, performing semantic extraction on the text embedding representation of the input text to obtain semantic features of the input text.
[0084] In one possible implementation, the computer device can perform semantic feature extraction on the text embedding representation of the input text through a trained semantic extraction network (also referred to as an encoder) to obtain semantic features of the input text.
[0085] Step 25, performing target text task processing on the input text based on the semantic features of the input text.
[0086] After obtaining the semantic features of the input text, the computer device can perform subsequent tasks corresponding to the input text based on the extracted semantic features, such as information query and recommendation, dialogue generation, user instruction response, and other natural language processing related tasks.
[0087] To sum up, in the scheme shown in the embodiments of the present application, when the computer device processes natural language processing tasks in a target field, the computer device can query related words in the knowledge graph of the target field through text words in the input text, and fuse the queried related words with the input text through the text tree. Subsequently, the semantic features are extracted and the tasks are processed through the constructed text tree. Since the related words of the target field are fused in the input text, the semantic features extracted subsequently can more accurately represent the semantics of the input text in the target field, thereby improving the accuracy of semantic extraction in natural language processing tasks, and further improving the accuracy of natural language processing tasks.
[0088] In addition, since the above scheme fuses the related words with the input text through the text tree, the corresponding relationship between the related words and the text words in the input text is contained in the obtained text tree. Subsequently, based on the text tree, the accuracy of the extracted semantic features can be further improved.
[0089] In the embodiments of the present application, the computer device can construct a text tree based on the input text, and fuse the related words of the target field into the input text through the text tree. Figure 2The solution in the illustrated embodiment can be implemented by a pre-trained natural language processing model, wherein the natural language processing model at least includes a semantic extraction network (also referred to as an encoder) and a task processing network. The semantic extraction network is used to perform the step 24, and the task processing network is used to perform the step 25.
[0090] The solution of the present application includes a natural language processing model generation stage and a natural language processing stage. Figure 3 is a framework diagram of natural language processing model generation and natural language processing according to an exemplary embodiment, as shown in Figure 3 As shown, in the natural language processing model generation stage, the model generation device 310 trains a machine learning model including a semantic extraction network and a task processing network by using a pre-set training sample data set (including pre-collected corpus and a knowledge graph of a target domain), to obtain a trained natural language processing model. In the natural language processing stage, the task processing device 320 processes an input text based on the natural language processing model and in combination with the knowledge graph, to perform a target text task, such as dialogue generation, information query, instruction control, etc.
[0091] The model generation device 310 and the task processing device 320 can be computer devices, such as personal computers, servers, etc. fixed computer devices, or tablet computers, e-book readers, etc. mobile computer devices.
[0092] Optionally, the model generation device 310 and the task processing device 320 can be the same device, or the model generation device 310 and the task processing device 320 can be different devices. When the model generation device 310 and the task processing device 320 are different devices, the model generation device 310 and the task processing device 320 can be the same type of device, such as the model generation device 310 and the task processing device 320 can both be servers; or the model generation device 310 and the task processing device 320 can be different types of devices, such as the task processing device 320 can be a personal computer or a terminal, and the model generation device 310 can be a server, etc. The specific type of the model generation device 310 and the task processing device 320 is not limited in the present application.
[0093] The solution of the present application includes a natural language processing model generation stage and a natural language processing stage. Figure 2 or Figure 3 The solution in the illustrated embodiment can be applied to natural language processing tasks in any specific field. For example, it can be applied to the medical field, the financial field, the legal field, the Internet Technology (IT) field, etc.
[0094] Taking the medical field as an example, the scheme shown in the above embodiments of the present application can provide a general text encoding technology for various downstream tasks of medical natural language understanding. The encoding technology can be applied to various downstream tasks, such as reading comprehension, text classification, information retrieval, medical navigation, auxiliary diagnosis, and the like. For example, for a text classification task, the text content can be encoded (i.e., semantic extraction) using step 24 in the above embodiments of the present application first, and then a text classification model, such as a linear layer multilayer perceptron (MLP), can be used to classify the encoding result.
[0095] Taking the medical field as an example, the application scenarios of the scheme shown in the above embodiments of the present application can include, but are not limited to, the following scenarios:
[0096] 1) Medical navigation scenario
[0097] The user inputs a query statement through an intelligent navigation system, the intelligent navigation system fuses the relevant words in the medical field corresponding to the text words in the query statement with the query statement, then performs semantic extraction through the semantic extraction network in the natural language task processing model, and obtains the navigation information (such as diseases matching the query statement, recommended departments, and the like) matched with the semantics through the task processing network in the natural language task processing model, and outputs the above navigation information.
[0098] 2) Similar case aggregation scenario
[0099] The user inputs a query statement through a case query system, the case query system fuses the relevant words in the medical field corresponding to the text words in the query statement with the query statement, then performs semantic extraction through the semantic extraction network in the natural language task processing model, and obtains the similar cases (such as the input query statement is the user's symptoms, and the task processing network can output the similar cases matching the symptoms) matched with the semantics through the task processing network in the natural language task processing model.
[0100] 3) Medical retrieval scenario
[0101] The user inputs a query statement through a medical retrieval system, the medical retrieval system fuses the relevant words in the medical field corresponding to the text words in the query statement with the query statement, then performs semantic extraction through the semantic extraction network in the natural language task processing model, and obtains the retrieval results (such as related web pages and the like) matched with the semantics through the task processing network in the natural language task processing model.
[0102] Figure 4is a flowchart of a text-based task processing method according to an exemplary embodiment. The method can be performed by a computer device. For example, the computer device can be a terminal or a server; or the computer device can include a terminal and a server. The server can be the server 120 shown in the above-described Figure 1 embodiment, and the terminal can be the user terminal 140 shown in the above-described Figure 1 embodiment. As shown in the above-described Figure 4 embodiment, the text-based task processing method can include the following steps.
[0103] At step 401, based on each text word in the input text, relevant knowledge is queried in a knowledge graph of a target domain to obtain a relevant word corresponding to each text word.
[0104] A knowledge graph is a data structure containing knowledge of a certain domain. A common representation of a knowledge graph is a knowledge triple, i.e., <entity 1, relationship, entity 2>, which represents that entity 1 and entity 2 have a certain relationship.
[0105] For example, an input text s={w0, w1, w2,..., w n} is given. Where w i represents the i-th word in the text s; w0 is always equal to [CLS], which is a special symbol used to mark the starting position of the text. Each word w i belongs to a vocabulary V, i.e., w i ∈V.
[0106] Meanwhile, the present embodiment also involves a pre-set knowledge graph of a target domain, denoted as K. In the knowledge graph K, each piece of knowledge is represented in the form of a triple ε=(w i , r j , w k ). Where w i and w j are noun entities, and r j is the relationship between the two entities.
[0107] For each text word, the computer device can query the relevant word of the text word in the target domain in the knowledge graph, which can be referred to as a relevant knowledge finding process.
[0108] In a possible implementation, for a target text word, which is any one of the text words of the input text, the computer device can match the target text word with an entity in the knowledge graph of the target domain and an extended word of the entity, and if the target text word matches the entity or the extended word of the entity, the relation and another entity in the knowledge triple in which the entity is located are obtained as the related words of the target text word in the target domain.
[0109] The related words include a relation word and an entity word; the entity word represents an entity corresponding to the text word in the knowledge graph; and the relation word represents the entity relation between the entity word and the text word in the knowledge graph.
[0110] That is, for a knowledge triple, if the target text word or the synonym of the target text word is an entity in the knowledge triple, the relation and another entity in the knowledge triple can be obtained as the related words of the target text word in the target domain.
[0111] The related knowledge search needs to quickly retrieve an entity set related to the current text in the knowledge graph.
[0112] E={(w i ,r i0 ,w i0 ),...,(w i ,r ik ,w k ),...)}
[0113] The difficulty lies in that the expression of an entity in a sentence and the expression of the entity in the knowledge graph may not be completely consistent. For example, in the sentence “Can I eat ice cream if I have stomachache”, “stomachache” is a symptom, which is a colloquial expression of a patient. However, the corresponding standard expression in the knowledge graph should be “abdominal pain”. The two expressions represent the same symptom, but use different expressions. Therefore, if the string in the input text is directly matched in the knowledge graph, the accuracy of the query related words is not high.
[0114] To solve the above problem, the embodiments of the present application expand the expressions of entities in the knowledge graph. For the entity “abdominal pain” in the knowledge graph of the medical field, the possible other expressions of the entity such as “abdominal pain / stomachache / stomach pain / gastric pain” and the like are stored through a dictionary, and then the extended entity expressions are matched in the text, to increase the accuracy of string exact matching.
[0115] In another possible implementation, for a target text word, which is any one of the text words in the input text, the computer device can obtain a synonym of the target text word, and then query related words of the target text word in the knowledge graph of the target domain based on the target text word and the synonym of the target text word.
[0116] In another exemplary scheme, the target text word can also be synonym expanded in the process of querying related words. For example, for the target text word "tummy hurts" in the input text, the computer device can obtain synonyms "abdominal pain / abdominal distress / tummy pain / stomach pain" and the like, and then query related words in the knowledge graph of the medical field through the target text word "tummy hurts" and the synonyms "abdominal pain / abdominal distress / tummy pain / stomach pain", respectively.
[0117] After the related words corresponding to the above text words are queried, a text tree can be constructed based on each text word and the related words corresponding to each text word, respectively. The text tree is used to indicate the connection relationship between each text word and the related words corresponding to each text word, respectively.
[0118] Step 402, based on the order of each text word in the input text and the corresponding relationship between the related words and the text words, a text tree is constructed.
[0119] The related words include relationship words and entity words. The entity words represent entities in the knowledge graph corresponding to the text words. The relationship words represent the entity relationship between the entity words and the text words in the knowledge graph.
[0120] The adjacent text words are directly connected in the text tree. The text words and the corresponding entity words are indirectly connected through the relationship words.
[0121] The scheme shown in the present application can integrate information in the input text s into the knowledge graph K in the knowledge graph K, so as to effectively encode the subsequent output sentence s.
[0122] For the input text s = {w0, w1, w2,..., wn}, the computer device can find related knowledge (i.e. related words) from the knowledge graph K, and construct a text tree that integrates external knowledge. n}, the computer device can find related knowledge (i.e. related words) from the knowledge graph K, and construct a text tree that integrates external knowledge.
[0123] t = {w0, w1, w2,..., wn}, where i (r0, w0), (r1, w1), (r2, w2),..., (rn, wn) i0 , w i0 ),..., (r ik , w ik )},..., w n}
[0124] where (r ij , wij ) is the knowledge (i.e. related words) found from the knowledge graph K related to w i ; w ij is the named entity related to w i ; r ij is the relationship between them.
[0125] In a possible implementation, when the text tree is constructed, the computer device firstly takes the text words in the text s as nodes, and serially connects edges between these text words, i.e. there is an edge between adjacent words. If the related knowledge (w i , r i , w i0 ) of the text word w i0 in the input text s is found, a branch is added in the text tree: w i → r i0 → w i0 .
[0126] Please refer to Figure 5 , which shows a text tree diagram related to an embodiment of the present application. As shown in Figure 5 , assuming that the input text is "Jack Wang is visiting Beijing Now", the knowledge triples <Wang, CEO, Company_A> corresponding to "Wang" and <Beijing, capital, China> and <Beijing, is_a, City> corresponding to "Beijing" are found in the knowledge graph. Then the computer device firstly connects them in order as "[CLS]-Jack-Wang-is-visiting-Beijing-Now", then connects the branch "-CEO-Company_A" with "Wang" in the text tree, and connects the branches "-capital-China" and "-is_a-City" with "Beijing" in the text tree respectively, to obtain the final structured text tree.
[0127] Step 403, constructing the text embedding representation of the input text based on the text tree.
[0128] The text embedding representation contains the embedding of the position of the word in the text tree, and the embedding of the position of the word in the input text in addition to the embedding of the word in the text tree.
[0129] In a possible implementation, the text embedding representation of the input text contains the respective embedding representation of each word in the text tree;
[0130] The embedding representation contains word embedding, position embedding and segment embedding.
[0131] The position embedding is used to represent the level of the corresponding word in the text tree; and the segment embedding is used to represent the sentence to which the corresponding word belongs.
[0132] In the embodiments of the present application, the computer device can convert the structured text tree into a serialized embedding representation processable by the semantic extraction network (i.e., the encoder), including a token embedding layer, a Soft-position embedding layer, and a segment embedding layer.
[0133] Please refer to Figure 6 , which shows an embedding layer diagram related to an embodiment of the present application. As shown in Figure 6 , the acquisition method of each embedding layer is as follows:
[0134] 1) Token embedding layer:
[0135] The computer device can traverse each node in the text tree t in sequence to obtain a word sequence T w = w0, w1, w2,..., w i , r i0 , w i0 ,..., r ik , w ik ,..., w n . Then each word in T w is mapped to an H-dimensional word vector (this mapping process can be completed by maintaining a lookup table), thereby obtaining the final representation of the token embedding layer.
[0136] 2) Position embedding layer:
[0137] In the embodiments of the present application, the position embedding layer is used to mark the position of each word in the text tree. For example, for the text tree t = {w0, w1, w2,..., w i {(r i0 , w i0 ),..., (r ik , w ik )},..., w n}, the position marking method POS is as follows:
[0138] POS(w k ) = k (w k is a word in the original input text);
[0139] POS(r kp ) = k + 1 (r kp is a relationship connected with w k in the knowledge graph);
[0140] POS(w kp )=k+2(w kp It is related to w in knowledge graph k Connected entity nouns).
[0141] For example, for the input text "[CLS]Jack Wangisvisiting Beijing Now", the sentence tree's position marking method is as follows: Figure 5 As shown. For example, Wang is the second word in the sentence, and its position is marked as 2.<Wang,CEO,Company_A> If the knowledge related to “Wang” is in knowledge graph K, then the position labels for CEO and Company_A are 3 and 4, respectively.
[0142] 3) Segment embedding layer:
[0143] Segment embedding layers are used to tag different sentences. For example, when the input text contains two sentences, namely... In the segment embedding layer, words in the two sentences are labeled with different tags, such as {A, A, ..., A, B, B, ..., B}. Optionally, the above tags can also be identified by numbers, such as {0, 0, ..., 0, 1, 1, ..., 1}.
[0144] In this process, for each word in the text tree, the computer concatenates the vectors from the three embedding layers corresponding to that word to obtain the final representation vector of that word (i.e., the word's embedding representation). For example, if a word's word vector is v, which has n-2 dimensions; its position in the text tree is 1; and its segment embedding identifier is 0, then the final representation vector of this word has n dimensions. The first n-2 dimensions are the word vector, the (n-1)th dimension is 1 (corresponding to the position identifier), and the nth dimension is 0 (corresponding to the segment embedding identifier). The final representation vectors of each word can be combined to form the text embedding representation of the input text, for example, forming a vector matrix.
[0145] Step 404: Construct a visual matrix based on the text tree; the visual matrix is used to indicate the distance relationship between each word in the text tree.
[0146] In one possible implementation, the visual matrix contains the distance attribute value between every two words in the text tree;
[0147] Constructing a visual matrix based on a text tree includes:
[0148] In response to the first and second words belonging to the input text, or the first and second words belonging to the same knowledge triple, the distance attribute value between the first and second words is set to 0; the first and second words are any two words in the text tree;
[0149] In response to the first word and the second word not belonging to the input text and not belonging to the same knowledge triple, a distance attribute value between the first word and the second word is set to negative infinity.
[0150] The visual matrix is constructed to solve a problem that if the text embedding representation of the input text is directly transmitted to an encoder, for example, multi-layer attention coding in the form of a Transformer, all words in the original sentence will interact with all external knowledge. For example, in the text tree in FIG. 1, “Beijing” will interact with “Wang”, “CEO”, and “Company_A” in the same way. However, “CEO” and “Company_A” are external knowledge related to “Wang”, and have little relevance to “Beijing”. Figure 5
[0151] To solve this problem, the embodiment of the present application constructs a visual matrix, so that the words introduced from the knowledge graph tend to interact with the words belonging to the same knowledge triple. Optionally, the visual matrix M ij The visual matrix is constructed as follows:
[0152]
[0153] The visual matrix can be used to guide the semantic coding of the encoder, for example, to guide the self-attention interaction of the encoder.
[0154] In step 405, based on the visual matrix, the semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text.
[0155] In one possible implementation, based on the visual matrix, the semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text, including:
[0156] Based on the text embedding representation of the input text, a query vector matrix, a key vector matrix, and a value vector matrix are obtained.
[0157] Based on the query vector matrix, the key vector matrix, and the visual matrix, a self-attention matrix is obtained.
[0158] Based on the self-attention matrix and the value vector matrix, the semantic feature of the input text is obtained.
[0159] In the embodiment of the present application, the computer device can encode the embedding layer representation (i.e., the text embedding representation of the input text) in the form of a Transformer through the encoder, and the self-attention mechanism can be adjusted according to the visual matrix during the encoding.
[0160] For example, in the embodiment of the present application, the self-attention mechanism adjusted by the visual matrix can be represented by the following formula:
[0161]
[0162] where W q ,W k .W v are trainable parameters, h i is the hidden state of the i-th layer self-attention module. Q, K, V are three matrices of d k *n. Where n corresponds to the current hidden state dimension of each word. d k is another dimension of the three matrices. Compared with the original Transformer calculation method, the difference lies in that (1) the denominator of the formula is added with the visual matrix M, so that the words introduced from the knowledge graph only perform self-attention interaction with the words belonging to the same knowledge triple.
[0163] In step 406, the input text is processed based on the semantic features of the input text.
[0164] The encoding result (i.e., semantic features) obtained by the encoder process of the above-mentioned scheme of the embodiment of the present application can be applied to various downstream tasks, such as reading comprehension, text classification, etc. For example, for a text classification task, the text content can be encoded by using the processes of steps 401 to 405 of the embodiment of the present application, and then a classification model (such as a linear layer MLP) is used to classify according to the encoding.
[0165] The above-mentioned steps of the embodiment of the present application can be realized by invoking a natural language task processing model by a computer device. Please refer to Figure 7 , which shows a model framework diagram related to an embodiment of the present application. As Figure 7 shown, the natural language task processing model shown in the embodiment of the present application includes a knowledge fusion network 701, an embedding layer construction network 702, a visual matrix construction network 703, an encoding network 704, and a downstream task network 705.
[0166] The above-mentioned knowledge fusion network 701 is used to perform the above-mentioned steps 401 and 402 to construct a text tree;
[0167] The above-mentioned embedding layer construction network 702 is used to perform the above-mentioned step 403 to construct a text embedding representation of the input text.
[0168] The above-mentioned visual matrix construction network 703 is used to perform the above-mentioned step 404 to construct a visual matrix.
[0169] The above-mentioned encoding network 704 is used to perform the above-mentioned step 405 to perform semantic encoding by using a self-attention mechanism.
[0170] The downstream task network 705 is configured to perform the step 406 to perform a subsequent natural language processing task by using the semantic encoding result.
[0171] The encoding network 704 can be a semantic encoding network such as Bidirectional Encoder Representations from Transformers (BERT), XLNET (an improved BERT), Robustly Optimized BERT (ROBERT), BERT-Whole Word Masking (BERT-WWM), or A Lite BERT (ALBERT).
[0172] In summary, when the computer device processes a natural language processing task in a target field, the computer device can query related words in a knowledge graph of the target field according to text words in an input text, and fuse the related words and the input text by constructing a text tree. Subsequently, semantic features are extracted and the task is processed by using the text tree. Since the related words of the target field are fused in the input text, the semantic features extracted subsequently can more accurately represent the semantics of the input text in the target field, thereby improving the accuracy of semantic extraction in the natural language processing task, and further improving the accuracy of the natural language processing task.
[0173] In addition, the related words and the input text are fused by constructing a text tree, and the text tree contains the corresponding relationship between the related words and the text words in the input text. Subsequently, the accuracy of the extracted semantic features can be further improved when the semantic features are extracted based on the text tree.
[0174] Figure 8 is a structural block diagram of a text-based task processing apparatus according to an example embodiment. The text-based task processing apparatus can implement Figure 2 or Figure 4 The text-based task processing apparatus includes all or part of the steps in the method provided by the embodiments.
[0175] The knowledge query module 801 is configured to query related knowledge in a knowledge graph of a target field based on each text word in an input text, and obtain related words corresponding to the text words, respectively.
[0176] The text tree construction module 802 is configured to construct a text tree based on the text words and the related words corresponding to the text words respectively, and the text tree is used to indicate a connection relationship between the text words and the related words corresponding to the text words.
[0177] The embedding representation construction module 803 is configured to construct a text embedding representation of the input text based on the text tree.
[0178] The semantic extraction module 804 is configured to perform semantic extraction on the text embedding representation of the input text to obtain semantic features of the input text.
[0179] The task processing module 805 is configured to perform a target text task on the input text based on the semantic features of the input text.
[0180] In a possible implementation, the related words include a relationship word and an entity word; the entity word represents an entity corresponding to the text word in the knowledge graph; and the relationship word represents an entity relationship between the entity word and the text word in the knowledge graph.
[0181] The text tree construction module 802 is configured to construct the text tree based on an order of the text words in the input text and a corresponding relationship between the related words and the text words.
[0182] In the text tree, adjacent text words are directly connected, and the text words and the corresponding entity words are indirectly connected through the relationship words.
[0183] In a possible implementation, the text embedding representation of the input text includes respective embedding representations of each word in the text tree.
[0184] The embedding representation includes a word embedding, a position embedding, and a segment embedding.
[0185] The position embedding is used to represent a level of a corresponding word in the text tree, and the segment embedding is used to represent a sentence to which the corresponding word belongs.
[0186] In a possible implementation, the apparatus further includes:
[0187] The visual matrix construction module is configured to construct a visual matrix based on the text tree before the semantic extraction module 804 performs semantic extraction on the text embedding representation of the input text to obtain the semantic features of the input text, and the visual matrix is used to indicate a distance relationship between each word in the text tree.
[0188] The semantic extraction module 804 is configured to perform semantic extraction on the text embedding representation of the input text based on the visual matrix, and obtain semantic features of the input text.
[0189] In a possible implementation, the visual matrix comprises distance attribute values between each two words in the text tree.
[0190] The visual matrix construction module is configured to,
[0191] In response to the first word and the second word belonging to the input text, or the first word and the second word belonging to the same knowledge triple, the distance attribute value between the first word and the second word is set to 0; the first word and the second word are any two words in the text tree.
[0192] In response to the first word and the second word not belonging to the input text and not belonging to the same knowledge triple, the distance attribute value between the first word and the second word is set to negative infinity.
[0193] In a possible implementation, the semantic extraction module 804 is configured to,
[0194] obtain a query vector matrix, a key vector matrix and a value vector matrix based on the text embedding representation of the input text;
[0195] obtain a self-attention matrix based on the query vector matrix, the key vector matrix and the visual matrix;
[0196] obtain semantic features of the input text based on the self-attention matrix and the value vector matrix.
[0197] In summary, the scheme shown in the embodiments of the present application can, when a computer device processes a natural language processing task in a target field, query related words in a knowledge graph of the target field through text words in an input text, and fuse the queried related words with the input text through a text tree, and subsequently extract semantic features and process tasks through the constructed text tree. Since the related words of the target field are fused in the input text, the semantic features extracted subsequently can more accurately represent the semantics of the input text in the target field, thereby improving the accuracy of semantic extraction in the natural language processing task, and further improving the accuracy of the natural language processing task.
[0198] In addition, since the above scheme fuses related words with input text through the construction of a text tree, the text tree obtained comprises the corresponding relationship between the related words and the text words in the input text, and subsequently, based on the text tree, the accuracy of the extracted semantic features can be further improved.
[0199] Figure 9 Fig. 9 is a schematic diagram of a computer device according to an example embodiment. The computer device can be implemented as the model training device and / or the signal processing device in the above-mentioned various method embodiments. The computer device 900 includes a central processing unit (CPU) 901, a system memory 904, and a system bus 905 that couples the system memory 904 to the central processing unit 901. The system memory 904 includes random access memory (RAM) 902 and read-only memory (ROM) 903. The computer device 900 also includes a
[0200] The mass storage device 907 connects to the central processing unit 901 through a mass storage controller (not shown) connected to the system bus 905. The mass storage device 907 and its associated computer readable media provide nonvolatile storage for the computer device 900. That is, the mass storage device 907 can include a computer readable medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
[0201] Without loss of generality, the computer readable media can include computer storage media and communication media. Computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, flash memory or other solid state memory technology, CD-ROM, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Of course, the computer storage media can not be limited to the above-mentioned several types. The system memory 904 and the mass storage device 907 mentioned above can be collectively referred to as memory.
[0202] The computer device 900 can be connected to the Internet or other network devices through a network interface unit 99 connected on the system bus 905.
[0203] The memory further includes one or more programs stored in the memory, and the central processing unit 901 implements the functions of the model training device and / or the signal processing device by executing the one or more programs. Figure 2 orFigure 4 all or part of the steps of any of the methods.
[0204] In an example embodiment, a non-transitory computer readable storage medium is also provided, which includes instructions, such as a memory including a computer program (instructions) executable by a processor of a computer device to perform the methods illustrated by various embodiments of the present application. For example, the non-transitory computer readable storage medium can be a Read-Only Memory (ROM), a Random Access Memory (RAM), a Compact Disc Read-Only Memory (CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0205] In an example embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device performs the methods illustrated by various embodiments described above.
[0206] Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the present application cover any and all variations of the application that come within the scope of the claims and that the claims be given their broadest interpretation and the widest coverage. The specification and examples are illustrative of the application and are not intended to be limiting.
[0207] It should be understood that the application is not limited to the precise construction that has been described above and shown in the accompanying drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the application. The scope of the application is to be defined by the claims appended hereto.
Claims
1. A text-based task processing method, characterized by, The method comprises: Based on each text word in the input text, relevant knowledge query is carried out in the knowledge graph of the target field, and relevant words corresponding to each text word are obtained; Based on the text word and the relevant word corresponding to each text word, a text tree is constructed; wherein the text word is taken as a node, and the text words are sequentially connected; for the relevant word of the text word, a branch is added in the text tree, and the relevant word is inserted into the corresponding text word position; the text tree is used to indicate the connection relationship between the text word and the relevant word corresponding to each text word; constructing a text embedding representation of the input text based on the text tree, the text embedding representation comprising word embeddings, position embeddings, and segment embeddings; the word embeddings are used to represent word vectors mapped from corresponding words, the position embeddings are used to represent levels of corresponding words in the text tree, wherein the kth level is a word in the original input text , the k+1th level comprises a relationship connected with in the knowledge graph , the k+2th level comprises an entity noun connected with in the knowledge graph , and the segment embeddings are used to represent sentences to which corresponding words belong; The semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text; Based on the semantic feature of the input text, the input text is processed by the target text task.
2. The method of claim 1, wherein, The relevant word contains a relationship word and an entity word; the entity word represents an entity corresponding to the text word in the knowledge graph; the relationship word represents the entity relationship between the entity word and the text word in the knowledge graph; The text tree is constructed based on the text word and the relevant word corresponding to each text word, comprising: Based on the order of the text word in the input text and the corresponding relationship between the relevant word and the text word, the text tree is constructed; Wherein, the adjacent text words are directly connected in the text tree; the text word and the corresponding entity word are indirectly connected through the relationship word.
3. The method according to claim 1 or 2, characterized in that, Before the semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text, it further comprises: A visual matrix is constructed based on the text tree; the visual matrix is used to indicate the distance relationship between each word in the text tree; The semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text, comprising: Based on the visual matrix, the semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text.
4. The method of claim 3, wherein, The visual matrix contains the distance attribute value between each two words in the text tree; The visual matrix is constructed based on the text tree, comprising: In response to the first word and the second word belonging to the input text, or the first word and the second word belonging to the same knowledge triple, the distance attribute value between the first word and the second word is set to 0; the first word and the second word are any two words in the text tree; In response to the first word and the second word not belonging to the input text, and not belonging to the same knowledge triple, the distance attribute value between the first word and the second word is set to negative infinity.
5. The method of claim 4, wherein, Based on the visual matrix, the semantic feature of the input text is obtained by performing semantic extraction on the text embedding representation of the input text, comprising: Based on the text embedding representation of the input text, a query vector matrix, a key vector matrix and a value vector matrix are obtained; Based on the query vector matrix, the key vector matrix and the visual matrix, a self-attention matrix is obtained; Based on the self-attention matrix and the value vector matrix, semantic features of the input text are obtained.
6. A text-based task processing apparatus characterized by comprising: The device comprises: A knowledge query module is configured to query related knowledge in a knowledge graph of a target field based on each text word in an input text, and obtain related words corresponding to the each text word respectively. A text tree construction module is configured to construct a text tree based on the each text word and the related words corresponding to the each text word respectively; wherein the each text word is taken as a node, and the each text word is connected in sequence, and for the related words of the text word, branches are added to the text tree, and the related words are inserted into positions corresponding to the text word; the text tree is used to indicate a connection relationship between the each text word and the related words corresponding to the each text word respectively. The embedding representation construction module is configured to construct a text embedding representation of the input text based on the text tree, the text embedding representation comprising word embeddings, position embeddings, and segment embeddings; the word embeddings are configured to represent word vectors mapped from corresponding words, the position embeddings are configured to represent levels of corresponding words in the text tree, wherein the kth level is a word in the original input text , the k+1th level comprises a relationship connected with in the knowledge graph , the k+2th level comprises an entity noun connected with in the knowledge graph , and the segment embeddings are configured to represent sentences to which corresponding words belong. A semantic extraction module is configured to perform semantic extraction on a text embedding representation of the input text, and obtain semantic features of the input text. A task processing module is configured to perform a target text task processing on the input text based on the semantic features of the input text.
7. A computer device, comprising: The computer device comprises a processor and a memory, and the memory stores at least one computer instruction, which is loaded and executed by the processor to implement the text-based task processing method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The storage medium stores at least one computer instruction, which is loaded and executed by the processor to implement the text-based task processing method according to any one of claims 1 to 5.
9. A computer program product, characterised in that, The computer program product comprises computer instructions, which are read and executed by the processor of the computer device, so that the computer device performs the text-based task processing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Natural language processing method, natural language processing device and intelligent question-answering system
CN111026842A
Entity identification method, electronic equipment and storage device
CN112668334A