Text processing, model training method, device, computer equipment and storage medium
By fusing text encoding vectors and knowledge representation vectors, and using correlation relationships to calculate attention weights, the problem of low accuracy of existing text processing models is solved, and the accuracy and semantic understanding of text processing results are improved.
Patent Information
- Application Number
- CN202010881097.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-27
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-08-27
AI Technical Summary
Existing text processing models have low accuracy when processing text, and it is difficult to effectively understand the semantics of the text.
By obtaining the encoding vector of the target text and the association representation vector of the entity, calculating the attention weight, and fusing the text encoding vector and the knowledge representation vector, thereby improving the accuracy of the text processing results.
By fusing semantics and knowledge information, the accuracy of text processing results is improved and the ability to understand text semantics is enhanced.
Smart Images

Figure CN112084331B
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a text processing, model training method, apparatus, computer equipment and storage medium. Background Art
[0002] With the development of computer and Internet technology, text processing is required in many cases, such as text translation or named entity recognition.
[0003] At present, texts can be processed based on artificial intelligence text processing models to obtain text processing results. However, there is often a situation where the accuracy of the text processing results obtained by the text processing model is relatively poor, that is, the text processing accuracy is relatively low. Summary of the invention
[0004] Based on this, it is necessary to provide a text processing, model training method, device, computer equipment and storage medium to address the above technical problems.
[0005] A text processing method, the method comprising: obtaining a target text to be processed, encoding the target text to obtain a target text encoding vector, the target text encoding vector including a target semantic vector corresponding to the target text; obtaining a target entity in the target text, and determining a first associated entity corresponding to the target entity; determining a target knowledge representation vector corresponding to the target entity based on an entity representation vector of the first associated entity and a corresponding attention weight, wherein the attention weight is obtained based on the degree of association between the target semantic vector and an associated relationship representation vector, and the associated relationship representation vector is a vector representing an entity association relationship; fusing the target text encoding vector with a target knowledge representation vector corresponding to the target entity to obtain a target fusion result; and determining a text processing result corresponding to the target text based on the target fusion result.
[0006] A text processing device, the device comprising: a target text encoding module, used to obtain a target text to be processed, encode the target text, and obtain a target text encoding vector, wherein the target text encoding vector includes a target semantic vector corresponding to the target text; a first entity acquisition module, used to obtain a target entity in the target text, and determine a first associated entity corresponding to the target entity; a target knowledge representation vector determination module, used to determine a target knowledge representation vector corresponding to the target entity according to the entity representation vector of the first associated entity and a corresponding attention weight, wherein the attention weight is obtained according to the correlation between the target semantic vector and an associated relationship representation vector, and the associated relationship representation vector is a vector representing an entity association relationship; a first fusion module, used to fuse the target text encoding vector with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result; a text processing result determination module, used to determine a text processing result corresponding to the target text according to the target fusion result.
[0007] In some embodiments, the target knowledge representation vector determination module includes: a relationship network diagram acquisition unit, used to obtain a relationship network diagram consisting of the first associated entity and the target entity; an association relationship representation vector acquisition unit, used to obtain, for a network diagram entity in the relationship network diagram, an association relationship representation vector representing the association relationship between the network diagram entity and an adjacent entity; an attention weight determination unit, used to obtain a vector association degree based on the association relationship representation vector and the target semantic vector, and determine the attention weight corresponding to the adjacent entity based on the vector association degree; a target knowledge representation vector determination unit, used to determine the target knowledge representation vector corresponding to the network diagram entity based on the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity; an extraction unit, used to extract the target knowledge representation vector corresponding to the target entity from the target knowledge representation vectors corresponding to each network diagram entity of the relationship network diagram.
[0008] In some embodiments, the target knowledge representation vector corresponding to the network graph entity is output by a knowledge vector determination model, and the knowledge vector determination model includes at least one target hidden layer. The target knowledge representation vector determination unit is used to: input the entity representation vector of the adjacent entity and the association relationship representation vector into the target hidden layer for processing to obtain the first knowledge representation vector corresponding to the network graph entity; determine the target knowledge representation vector corresponding to the network graph entity based on the first knowledge representation vector corresponding to the network graph entity and the corresponding attention weight of the adjacent entity.
[0009] In some embodiments, the target knowledge representation vector determination unit is used to: determine a target calculation direction based on the entity association relationship between the network graph entity and the adjacent entity, wherein the target calculation direction is addition or subtraction; calculate the entity representation vector of the adjacent entity and the association relationship representation vector according to the target calculation direction to obtain a calculation representation vector corresponding to the network graph entity; and process the calculation representation vector using the hidden layer parameters in the target hidden layer to obtain a first knowledge representation vector corresponding to the network graph entity.
[0010] In some embodiments, the target knowledge representation vector determination unit is used to: obtain the output representation vector corresponding to the adjacent entity of the previous hidden layer output corresponding to the target hidden layer in the knowledge vector determination model; the target hidden layer uses the first hidden layer parameters to process the calculated representation vector and the output representation vector to obtain the first knowledge representation vector corresponding to the network graph entity.
[0011] In some embodiments, the target knowledge representation vector corresponding to the network graph entity is output by the knowledge vector determination model, and the attention weight determination unit is used to: use the second hidden layer parameters in the target hidden layer to process the association relationship representation vector to obtain a key vector; use the third hidden layer parameters in the target hidden layer to process the target semantic vector to obtain a query vector; calculate the vector association degree based on the key vector and the query vector; determine the attention weight corresponding to the adjacent entity based on the vector association degree, and the vector association degree is positively correlated with the attention weight corresponding to the adjacent entity.
[0012] In some embodiments, the target text includes multiple word segments, the target text encoding vector includes a word segment encoding vector sequence, and the word segment encoding vector sequence includes the word segment encoding vector corresponding to each word segment; the first fusion module includes: a knowledge integration encoding vector obtaining unit, which is used to perform knowledge integration processing on the word segment encoding vector corresponding to the target word segment according to the target knowledge representation vector corresponding to the target entity, and obtain the knowledge integration encoding vector corresponding to the target word segment; an updating unit, which is used to use the knowledge integration encoding vector corresponding to the target word segment to update the word segment encoding vector corresponding to the target word segment in the word segment encoding vector sequence, and obtain an updated word segment encoding vector sequence; a fusion unit, which is used to use a fusion model to fuse the updated word segment encoding vector sequence and the target semantic vector, and obtain a fused word segment encoding vector sequence and a fused target semantic vector.
[0013] In some embodiments, the text processing result determination module is used to: input the fused target semantic vector into a trained text classification model to obtain a text classification result corresponding to the target text.
[0014] In some embodiments, the knowledge integration coding vector obtaining unit is used to: perform vector splicing processing according to the target knowledge representation vector corresponding to the target entity and the word segmentation coding vector corresponding to the target word segmentation, so as to obtain the knowledge integration coding vector corresponding to the target word segmentation.
[0015] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps corresponding to the above-mentioned text processing method when executing the computer program
[0016] A computer-readable storage medium stores a computer program, which implements the steps corresponding to the above-mentioned text processing method when executed by a processor.
[0017] In the above-mentioned text processing method, device, computer equipment and storage medium, the target text encoding vector incorporates the target knowledge representation vector, and the target knowledge representation vector is obtained based on the entity representation vector of the first associated entity corresponding to the target entity in the target text and the attention weight. Since the attention weight is obtained based on the correlation between the target semantic vector and the associated relationship representation vector, the importance of the entity representation vector of the associated entity to the representation vector of the target entity can be determined based on the semantics of the target text, and the attention weight is determined based on the importance, so that the target knowledge vector obtained based on the attention weight and the entity representation vector can promote the understanding of the semantics of the target text. Therefore, the text processing result corresponding to the target text is obtained based on the target fusion result, thereby improving the accuracy of the text processing result.
[0018] A text processing model training method, the method comprising: obtaining a training text and a standard text processing result corresponding to the training text; inputting the training text into a text encoding model to obtain a training text encoding vector, the training text encoding vector comprising a training semantic vector corresponding to the training text; obtaining a training entity corresponding to the training text, and determining a second associated entity corresponding to the training entity; inputting an entity representation vector corresponding to the second associated entity into a knowledge vector determination model, and determining a training knowledge representation vector corresponding to the training entity according to the entity representation vector and a corresponding attention weight, the attention weight being obtained according to the degree of association between the training semantic vector and an associated relationship representation vector, the associated relationship representation vector being a vector representing an entity associated relationship; inputting the training text encoding vector and the training knowledge representation vector corresponding to the training entity into a fusion model for fusion processing to obtain a training fusion result; processing the training fusion result according to a task processing model to obtain a training processing result; adjusting the parameters of the task processing model according to the training processing result and the standard text processing result, or adjusting the parameters of the task processing model and a language model, the language model comprising the text encoding model, the knowledge vector determination model and the fusion model.
[0019] A text processing model training device, the device comprising: a training text acquisition module, used to acquire training text and a standard text processing result corresponding to the training text; a training text encoding vector acquisition module, used to input the training text into a text encoding model to obtain a training text encoding vector, wherein the training text encoding vector includes a training semantic vector corresponding to the training text; a second entity acquisition module, used to acquire a training entity corresponding to the training text and determine a second associated entity corresponding to the training entity; a training knowledge representation vector determination module, used to input an entity representation vector corresponding to the second associated entity into a knowledge vector determination model, and determine a training knowledge representation vector corresponding to the training entity according to the entity representation vector and a corresponding attention weight, wherein the attention weight The intention weight is obtained according to the correlation between the training semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing the entity association relationship; a training fusion result obtaining module is used to input the training text encoding vector and the training knowledge representation vector corresponding to the training entity into a fusion model for fusion processing to obtain a training fusion result; a training processing result obtaining module is used to process the training fusion result according to a task processing model to obtain a training processing result; an adjustment module is used to adjust the parameters of the task processing model according to the training processing result and the standard text processing result, or adjust the parameters of the task processing model and the language model, and the language model includes the text encoding model, the knowledge vector determination model and the fusion model.
[0020] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps corresponding to the above-mentioned text processing model training method when executing the computer program
[0021] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps corresponding to the above-mentioned text processing model training method.
[0022] The above-mentioned text processing model training method, device, computer equipment and storage medium, since the language model includes a text encoding model, a knowledge vector determination model and a fusion model, the knowledge vector determination model can determine the training knowledge representation vector corresponding to the training entity according to the entity representation vector and the corresponding attention weight, the attention weight is obtained according to the correlation between the training semantic vector and the association relationship representation vector, the association relationship representation vector is a vector representing the entity association relationship, since the attention weight is obtained according to the correlation between the training semantic vector and the association relationship representation vector, it is possible to determine the importance of the entity representation vector of the associated entity to the representation vector of the training entity according to the semantics of the training text, and determine the attention weight according to the importance, so that the obtained training knowledge vector can better promote the understanding of the semantics of the training text, thereby improving the text comprehension ability of the obtained language model and the task processing model, and improving the accuracy of the text processing results. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 An application environment diagram of a text processing method in an embodiment;
[0024] Figure 2 A flowchart of a text processing method in one embodiment;
[0025] Figure 3A A schematic diagram of an encoding principle of a BERT-based text encoding model in one embodiment;
[0026] Figure 3B A schematic diagram of determining a text processing result corresponding to a target text according to a target fusion result in one embodiment;
[0027] Figure 3C A schematic diagram of determining a text processing result corresponding to a target text according to a target fusion result in one embodiment;
[0028] Figure 3D A schematic diagram of determining a text processing result corresponding to a target text according to a target fusion result in one embodiment;
[0029] Figure 4A schematic diagram of a process of determining a target knowledge representation vector corresponding to a target entity according to an entity representation vector of a first associated entity and a corresponding attention weight in another embodiment;
[0030] Figure 5 A schematic diagram of an encoding principle of a BERT-based text encoding model in one embodiment;
[0031] Figure 6 A flowchart of a text processing model training method in one embodiment;
[0032] Figure 7 This is an interface diagram for performing text translation in one embodiment;
[0033] Figure 8 A schematic diagram of determining a knowledge representation vector based on knowledge in a knowledge graph in one embodiment;
[0034] Fig. 9 A schematic diagram of calculating a knowledge representation vector in one embodiment;
[0035] Fig.10 is a structural block diagram of a text processing device in one embodiment;
[0036] Fig.11 is a structural block diagram of a text processing model training device in an embodiment;
[0037] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0039] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0040] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0041] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between 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 people use 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 answering, knowledge graph and other technologies.
[0042] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0043] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, etc. I believe that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0044] The solution provided in the embodiments of the present application involves artificial intelligence machine learning technology and natural language processing, which is specifically described by the following embodiments:
[0045] The text processing method and text processing model training method provided in this application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. When text processing is required, the terminal 102 can send a text processing request to the server 104. The server 104 can be deployed with a text processing model, which includes a language model and a task processing model. The text processing model can be used to process the target text to be processed to obtain a text processing result. The server 104 can send the text processing result to the terminal 102, and can also store the text processing result. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.
[0046] In one embodiment, Figure 2 As shown, a text processing method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0047] Step S202, obtaining a target text to be processed, encoding the target text, and obtaining a target text encoding vector, wherein the target text encoding vector includes a target semantic vector corresponding to the target text.
[0048] The target text is the text to be processed. The language of the target text can be determined according to actual needs. For example, the target text can be a Chinese sentence or a Japanese sentence. A target text can include multiple tokens. The target text can be segmented to obtain multiple tokens. Multiple means at least two. The segmentation method can adopt a dictionary-based or statistical-based token segmentation method. For example, assuming that the target text is "Today is Sunday", the segmentation sequence obtained by segmentation can be "Today / is / Sunday".
[0049] Encoding refers to converting text into vectors for representation. The target text encoding vector is a vector obtained by encoding the target text. The target semantic vector is a vector that represents the semantics of the target text. The target semantic vector is obtained by encoding each word segment of the target text, integrating the semantic information of each word segment in the text. The target text encoding vector may also include a word segment encoding vector sequence, which includes the word segment encoding vectors corresponding to each word segment. The word segment encoding vector refers to the vector obtained by encoding the word segment. The vectors obtained by encoding the word segment are sorted according to the order of the corresponding word segment in the target text to form a word segment encoding vector sequence.
[0050] Specifically, the server can obtain the target text to be processed, segment the target text, segment the target text into a semantically reasonable word segmentation sequence, encode the target text using a text encoding model, and obtain a target text encoding vector, wherein the target text vector includes a word segmentation encoding vector sequence and a target semantic vector. Among them, the text encoding model can be based on BERT (Bidirectional Encoder Representation from Transformer, a bidirectional encoding model based on a transformer). When a target text is given, the target text includes N word segments, and the formula for obtaining the word segmentation encoding vector sequence can be expressed as formula (1), where T-Encoder is a text encoding model, and j represents the jth word segmentation. Wj represents the jth word segmentation, that is, it can be encoded by the text encoding model, and the word segmentation represented in text form can be represented by a vector.
[0051]
[0052] For example, Figure 3A As shown, a schematic diagram of the encoding principle of a BERT-based text encoding model provided for some embodiments. The server can segment the target text to obtain N tokens, where N is a positive integer, represented as Tok1, Tok2...TokN. A "[CLS]" tag is added before Tok1, where [CLS] represents the "classification" classification, E represents an embedded vector, for example, the embedded vector of [CLS] is E[CLS], T represents the encoded vector obtained by encoding, and C is a semantic vector, which is the semantic expression corresponding to [CLS], i.e., a semantic encoding vector. That is, the server can input the target text including N tokens into the text encoding model, and the text encoding model outputs the semantic expression C (called the target semantic vector) of [CLS] corresponding to the text, as well as the token encoding vector T corresponding to each token.
[0053] Step S204: acquiring a target entity in the target text, and determining a first associated entity corresponding to the target entity.
[0054] Specifically, an entity refers to something with a specific meaning, such as a person's name, a place name, an organization name, or a proper noun. A target entity is an entity in a target text, and a target text may include one or more target entities. For example, if the target text is "Monkeys like to eat bananas", the target entity may include "monkeys" and "bananas".
[0055] The first associated entity refers to an entity that has an associated relationship with the target entity. The associated relationship may be, for example, a subordinate relationship or a dependent relationship. The associated entity corresponding to the target entity may be obtained based on a knowledge graph. The knowledge graph can be used to describe the association relationship between entities, so the associated entity that has an associated relationship with the target entity in the knowledge graph can be obtained. The first associated entity may include at least one of an entity that has a direct association relationship with the target entity and an entity that has an indirect association relationship in the knowledge graph. A direct association relationship refers to an edge connection between the target entity and the first associated entity, and an indirect association relationship refers to an intermediate associated entity between the target entity and the first associated entity. For example, assuming that in the knowledge graph, the target entity is A, A's daughter is B, and B's son is C, that is, there is an edge connection between A and B, and there is an edge connection between B and C, then B is the first associated entity that has a direct association relationship with A, and C is the first associated entity that has an indirect association relationship with A. The "order" can be used to indicate the closeness of the association relationship between entities. An entity that has a direct association relationship with a target entity is called a first-order associated entity of the target entity, and an entity that has a direct association relationship with a first-order associated entity is called a second-order associated entity of the target entity. The first associated entity may be an associated entity whose association order with the target entity is within a preset association order, and the preset order may be set as needed, such as 2.
[0056] Specifically, the server may perform named entity recognition (NER) on the target text to obtain the target entity. The server may obtain, in the knowledge graph, an associated entity whose association degree with the target entity is within a preset degree as the first associated entity.
[0057] Step S206, determine the target knowledge representation vector corresponding to the target entity based on the entity representation vector of the first associated entity and the corresponding attention weight, wherein the attention weight is obtained based on the correlation between the target semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing the entity association relationship.
[0058] Specifically, the entity representation vector refers to the embedding vector used to represent the entity. The embedding vector refers to the mapping result from the semantic space to the vector space, that is, an entity can be represented by a low-dimensional vector, such as [0.2, 0.3, ... 0.6]. The association relationship representation vector is a vector that represents the relationship between entities. The entity representation vector and the association relationship representation vector can be obtained using knowledge representation learning methods, such as the TransE (TranslatingEmbedding) method. Knowledge representation learning is representation learning for entities and relationships in the knowledge base. TransE regards the relationship relation in the triple (head, relation, tail) as a translation from the head entity head to the tail entity tail.
[0059] In the attention mechanism, an output can be obtained based on multiple inputs. The attention weight indicates the amount of attention paid to the input when determining the output. The larger the attention weight corresponding to an input, the more attention is paid to the input when determining the output. That is, the attention weight indicates the influence of the input on the output. The attention weight is positively correlated with the influence. The larger the attention weight corresponding to an input, the greater its influence on the output, and the more critical the input is to the output. On the contrary, the smaller the attention weight corresponding to an input, the weaker the influence of the input on the output, indicating that the input is not so critical. The attention weight can be obtained according to the attention model. The target knowledge representation vector is the output, and the entity representation vector corresponding to the first associated entity can be used as the input, or the input can be obtained according to the entity representation vector corresponding to the first associated entity. For example, the entity representation vector corresponding to the first associated entity can be input into the knowledge vector determination model to obtain the first knowledge representation vector, and the first knowledge representation vector can be used as the input.
[0060] The attention weight is obtained according to the correlation between the target semantic vector and the association relationship representation vector. The attention weight is positively correlated with the correlation. The greater the correlation, the greater the corresponding attention weight. The correlation between the target semantic vector and the association relationship representation vector can be at least one of a direct correlation or an indirect correlation. Direct correlation refers to calculating the correlation between the target semantic vector and the association relationship representation vector, such as similarity, as the correlation between the target semantic vector and the association relationship representation vector. Indirect correlation refers to further processing the target semantic vector, further processing the association relationship representation vector, and obtaining the correlation between the target semantic vector and the association relationship representation vector based on the processed target semantic vector and the processed association relationship representation vector. For example, the target semantic vector and the association relationship representation vector can be input into the trained model, and the target semantic vector can be processed using the model parameters, and the association relationship representation vector can be processed.
[0061] The association relationship representation vector may be a vector representing the association relationship between the first associated entity and the target entity, or may be a vector representing the relationship between the first associated entities. For example, the attention weight corresponding to the first associated entity may be obtained based on the attention weight of the edge of the shortest path from the first associated entity to the target entity, for example, it may be obtained by multiplying the attention weights of the edges of the shortest path. For example, assuming A→B→C, the target entity is A. For the first associated entity C, the corresponding attention weight calculation method is as follows: the attention weight obtained based on the association degree between the association relationship representation vector between B and C and the target semantic vector is multiplied by the attention weight obtained based on the association degree between the association relationship representation vector between A and B and the target semantic vector, to obtain the attention weight corresponding to the first associated entity C.
[0062] The knowledge representation vector refers to a vector obtained based on knowledge and is used to represent knowledge. The associated entities corresponding to the target entity and the association relationship between the target entity and the associated entities are knowledge, which can be obtained based on the knowledge graph. Therefore, the vector obtained based on the entity representation vector of the associated entity corresponding to the target entity and the association relationship representation vector can be called a knowledge representation vector.
[0063] Specifically, the server can input the entity representation vector of the first associated entity, the association relationship representation vector between the first associated entity and the target entity, and the association relationship representation vector between the first associated entities into the knowledge vector determination model. The knowledge vector determination model determines the attention weight corresponding to each first associated entity according to the correlation between the target semantic vector and the association relationship representation vector. That is, the correlation between the target semantic vector and the association relationship representation vector can represent the influence of the relationship between entities on the semantics of the target text. For relationships that are more relevant to semantics, it means that the relationship is more useful knowledge, and it is necessary to focus on the associated entity corresponding to the relationship. Among them, the knowledge vector determination model can be a graph neural network model (Graph Neural Network, GNN).
[0064] In some embodiments, a relationship network diagram consisting of a first associated entity and a target entity can be obtained, and entity representation vectors corresponding to each network diagram entity in the relationship network diagram and an association relationship representation vector representing the association relationship between entities in the network diagram entity can be obtained and input into a graph neural network model. The graph neural network model determines the knowledge representation vector of the network diagram entity in the following manner: for any network diagram entity, based on the model parameters, the entity representation vector of the adjacent entity of the network diagram entity and the association relationship representation vector representing the relationship between the network diagram entity and the adjacent entity are processed to obtain the first knowledge representation vector corresponding to the network diagram entity. When there are multiple adjacent entities, there are also multiple first knowledge representation vectors corresponding to the network diagram entity. Therefore, the attention weights corresponding to each first knowledge representation vector can be obtained, and a weighted calculation is performed based on the first knowledge representation vector and the corresponding attention weight to obtain the target knowledge representation vector corresponding to the network diagram entity. Since the target entity is included in the relationship network diagram, that is, the target entity is also a network diagram entity, the target knowledge representation vector corresponding to the target entity can be obtained. For example, the company that determines the target knowledge representation vector corresponding to the target entity can be expressed as in formula (2). The e on the left side of the equation j represents the target knowledge representation vector of the j-th network graph entity. The e on the right side of the equation j The entity representation vector represents the j-th network graph entity. DK-Encoder (Dynamic Knowledge Context Encoder) represents the knowledge vector determination model. The target text includes N word segments, and M is the number of entities.
[0065]
[0066] Step S208, fusing the target text encoding vector with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result.
[0067] Among them, fusion means combining together, and the fusion method can be set as needed, for example, it can be at least one of splicing or weighted addition. For example, splicing can be performed, and the splicing result is input into a fusion model for processing. The fusion model can be, for example, a multi-layer perceptron model, a recurrent neural network model, or a convolutional neural network model. For example, the fusion model can include P aggregators, each of which uses MLP (multilayer perceptron) to mix two different heterogeneous features, namely, the target text encoding vector and the target knowledge representation vector corresponding to the target entity. The number of P can be set as needed.
[0068] In some embodiments, the target text encoding vector includes a word segmentation encoding vector sequence, and the target text encoding vector is fused with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result, including: performing knowledge integration processing on the word segmentation encoding vector corresponding to the target word segmentation according to the target knowledge representation vector corresponding to the target entity to obtain the knowledge integration encoding vector corresponding to the target word segmentation; using the knowledge integration encoding vector corresponding to the target word segmentation to update the word segmentation encoding vector corresponding to the target word segmentation in the word segmentation encoding vector sequence to obtain an updated word segmentation encoding vector sequence; using the fusion model to fuse the updated word segmentation encoding vector sequence and the target semantic vector to obtain a fused word segmentation encoding vector sequence and a fused target semantic vector.
[0069] Among them, the target word segmentation refers to the word segmentation corresponding to the target entity. Since the word segmentation encoding vector is the encoding vector corresponding to the word segmentation in the target text, and the target entity is the entity in the target text, the word segmentation of the target text includes the word segmentation corresponding to the target entity, so the word segmentation encoding vector corresponding to the target word segmentation can be obtained. For example, for the target text "Monkey likes to eat bananas", the word segmentation includes "monkey", "like", "eat" and "banana". The word segmentation encoding vector sequence includes the word segmentation encoding vector corresponding to "monkey", the word segmentation encoding vector corresponding to "like", the word segmentation encoding vector corresponding to "eat" and the word segmentation encoding vector corresponding to "banana". After obtaining the target knowledge representation vector corresponding to the target entity "monkey", the word segmentation encoding vector corresponding to "monkey" and the target knowledge representation vector corresponding to "monkey" can be processed by knowledge integration.
[0070] Knowledge integration processing refers to integrating the target knowledge representation vector into the word segmentation encoding vector. The knowledge integration processing can be splicing or weighted summation, such as vector addition. For example, the target knowledge representation vector corresponding to the target entity and the word segmentation encoding vector corresponding to the target word segmentation can be spliced. The target knowledge representation vector corresponding to the target entity and the word segmentation encoding vector corresponding to the target word segmentation can be directly spliced to obtain the knowledge integration encoding vector corresponding to the target word segmentation, or further processed and then spliced. For example, the fusion model can include two multi-head self attention models, one of which is used to process the word segmentation encoding vector sequence in the word segmentation encoding vector sequence, and the other multi-head self-attention model is used to process the target knowledge representation vector, and the word segmentation encoding vector obtained by the multi-head self-attention model and the target knowledge representation vector obtained by the multi-head self-attention model are spliced to obtain the knowledge integration encoding vector.
[0071] For example, the splicing method can be horizontal splicing. For example, suppose the word encoding vector corresponding to "monkey" is a k-dimensional vector, represented by (a1, a2...a k ) and the target knowledge representation vector corresponding to the “monkey” is a j-dimensional vector, represented by (b1, b2…bj), then the knowledge integration vector obtained by horizontal splicing is a k+j-dimensional vector, represented by (a1, a2…a k , b1, b2…bj).
[0072] Specifically, after the server obtains the knowledge corresponding to the target word segmentation and integrates it into the encoding vector, it uses the knowledge integrated into the encoding vector to replace the word segmentation encoding vector sequence, and the word segmentation encoding vector corresponding to the target word segmentation, to obtain an updated word segmentation encoding vector sequence. The server can input the updated word segmentation encoding vector sequence and the target semantic vector into the fusion layer of the fusion model for fusion processing to obtain at least one of the fused word segmentation encoding vector sequence and the fused target semantic vector. Among them, the fusion model can be a BERT-based model, and the BERT-based model can continue to be used to process the updated word segmentation encoding vector sequence and the target semantic vector. For example, the fusion model can include a multilayer perceptron (MLP). For example, the formula for obtaining the target fusion result by the fusion model can be expressed as formula (3), K-Encoder (Knowledge Fusion Encoder) represents the fusion model, represents the word segmentation encoding vector after fusion processing, The knowledge representation vector output after the fusion processing is represented. The fused word segmentation encoding vector corresponding to an entity is concatenated with the knowledge representation vector output after the fusion processing as the vector representation corresponding to the entity.
[0073]
[0074] Step S210, determining the text processing result corresponding to the target text according to the target fusion result.
[0075] Among them, the text processing result can be determined according to the application scenario. For example, the text processing result can include at least one of the text annotation result, text classification result, sentence relationship judgment result or text generation result. Text annotation refers to the annotation of text, such as Named Entity Recognition (NER) of text or part-of-speech recognition of word segmentation in text. The text classification result refers to the classification of text, such as sentiment classification or spam classification. Sentiment classification divides text into text expressing positive emotions or text expressing negative emotions. Spam classification divides emails into spam or non-spam. The sentence relationship judgment result can be used to determine the relationship between sentences, and the relationship between sentences can be the relationship between questions and answers, or the relationship between contexts, such as determining whether the second sentence is the next sentence of the first sentence. The text generation result is, for example, translating the text or generating a summary of the text.
[0076] Specifically, the target fusion result can be a word segmentation encoding vector sequence after fusion processing or a target semantic vector after fusion processing. The target fusion result is determined according to the specific scenario. The server can input the target fusion result into the task processing model, and the task processing model processes the target fusion result to obtain a text processing result.
[0077] In some embodiments, for a text classification task, the target semantic vector after fusion processing is the target fusion result, and the target semantic vector after fusion processing can be input into a text classification model to obtain a text classification result. Figure 3B As shown, for general (ordinary) natural language processing tasks, such as text classification tasks, the text processing results can be determined according to the expression of [CLS].
[0078] In some embodiments, for the text generation result, the word segmentation encoding vector sequence after fusion processing can be input into the decoding model to obtain the text generation result.
[0079] In some embodiments, for named entity recognition, the fused word segmentation encoding vector sequence is the target fusion result, and the entity identifier can be used to identify the word segmentation encoding vector corresponding to the entity in the fused word segmentation encoding vector sequence, so as to perform named entity recognition based on the word segmentation encoding vector corresponding to the entity. For example, the [ENT] characters can be added before and after the entity in the target text as entity identifiers. When predicting downstream tasks, the vector marked with [ENT] is used as the entity representation vector of the entity for named entity recognition. For example, Figure 3CAs shown in the figure, assuming that the target text is "Steph Curry and Klay Thompson led the Warriors to the 2015 NBAChampionship", and assuming that the target entity is "Steph Curry", after adding the entity identifier, it is expressed as "[ENT]Steph Curry[ENT]and[ENT]Klay Thompson[ENT]led the Warriors to the 2015 NBAChampionship".
[0080] In some embodiments, for entity relationship extraction, the fused word segmentation encoding vector sequence is the target fusion result. The word segmentation encoding vectors corresponding to the entities in the fused word segmentation encoding vector sequence can be identified using relationship identifiers, so that when extracting entity relationships, the word segmentation encoding vectors corresponding to the head entity (head) and the word segmentation encoding vectors corresponding to the tail entity (tail) can be extracted and concatenated according to the relationship identifiers. The relationship identifiers include a head entity identifier and a tail entity identifier. For each entity, a head entity identifier, such as [HD], can be added before the entity, and a tail entity identifier, such as [TL], can be added after the entity. When making predictions for downstream tasks, the word segmentation encoding vectors corresponding to the head entity [HD] and the word segmentation encoding vectors corresponding to the tail entity [TL] can be extracted and concatenated as the final expression to perform relationship extraction and obtain the relationship between entities. For example, Figure 3D As shown in the figure, assuming that the target text is "Steph Curry and Klay Thompson led the Warriors to the 2015 NBA Championship", after adding the relationship identifier, it is expressed as "[HD]Steph Curry[TL]and[HD]KlayThompson[TL]led the Warriors to the 2015 NBA Championship".
[0081] In the above text processing method, the target knowledge representation vector is integrated into the target text encoding vector, and the target knowledge representation vector is obtained based on the entity representation vector of the first associated entity corresponding to the target entity in the target text and the attention weight. Since the attention weight is obtained based on the correlation between the target semantic vector and the associated relationship representation vector, the importance of the entity representation vector of the associated entity to the representation vector of the target entity can be determined according to the semantics of the target text, and the attention weight is determined according to the importance, so that the target knowledge vector obtained based on the attention weight and the entity representation vector can promote the understanding of the semantics of the target text. Therefore, the text processing result corresponding to the target text is obtained based on the target fusion result, thereby improving the accuracy of the text processing result.
[0082] In some embodiments, Figure 4 As shown, step S206, that is, determining the target knowledge representation vector corresponding to the target entity according to the entity representation vector of the first associated entity and the corresponding attention weight, includes the following steps:
[0083] Step S402: obtaining a relationship network diagram consisting of the first associated entity and the target entity.
[0084] Specifically, the relationship network diagram includes nodes and edges. A node is an entity, and the existence of an edge between entities indicates that there is a direct relationship between the entities.
[0085] For example, suppose the first associated entity is an associated entity whose association degree with the target entity is within a preset degree, and the preset degree is 2. For the target entity A, suppose the daughter of entity A is B, the son of B is C, and B plays for team H. A plays for team E, E also includes player F, team E and H are competitors, and A's friend is D. Then the relationship network diagram can be represented as follows: Figure 5 It can be understood that the edges between the relationship network graphs can also be directional, and the relationship between entities can be represented by a triple (h, r, t), where h is the head entity, r refers to the relationship, and t refers to the tail entity.
[0086] In some embodiments, related entities with a preset association order with the target entity can be obtained from the knowledge graph to form a relationship network diagram. The relationship network diagram can be obtained according to formulas (4), (5), (6), (7) and (8). m Represents the relationship network diagram corresponding to the target entity m, Indicates that the relationship with entity m is the tail entity of order i, Indicates the head entity with an i-order association relationship with entity m. H represents the head entity, t represents the tail entity, r represents the relationship, g represents the knowledge graph, and “∧” represents the logical operator “and”. “∈” means does not belong to, and “∈” means belongs to. Represents the set of related entities from order 0 to order i-1. “∪” represents the union. That is, for entity m in the text, the position of entity m in the knowledge graph can be obtained, and then the server can collect the i-th order neighbor entities of this entity. The i-th order neighbor entity is defined as The server can cyclically obtain the i-th order related entity according to formulas (4) to (6). Since entity m may be the head entity or the tail entity in the triple, Contains two entities with different orientations.
[0087]
[0088]
[0089]
[0090]
[0091]
[0092] Step S404: for a network graph entity in the relationship network graph, obtain an association relationship representation vector representing the association relationship between the network graph entity and an adjacent entity.
[0093] The network graph entity refers to the entity in the relationship network graph, the target entity and the first associated entity are entities in the network graph. The adjacent entity refers to the entity that has an edge connection with the network graph entity. For example, Figure 5 In the relational network diagram, for network graph entity A, its adjacent entities include B.
[0094] Step S406, obtaining a vector association degree according to the association relationship representation vector and the target semantic vector, and determining an attention weight corresponding to the adjacent entity according to the vector association degree.
[0095] The vector correlation refers to the correlation degree of the quantity, which can be similarity. The correlation is positively correlated with the attention weight. That is, the greater the correlation, the greater the attention weight.
[0096] Specifically, the server may use the vector correlation as the attention weight, or may normalize the vector correlation to obtain the attention weight.
[0097] In some embodiments, the knowledge representation vector corresponding to the network graph entity is output by the knowledge vector determination model, and the knowledge vector determination model includes at least one target hidden layer. For different hidden layers, the corresponding attention weights may be constant or variable. For example, the vector association degree is obtained based on the association relationship representation vector and the target semantic vector, and the attention weight corresponding to the adjacent entity is determined based on the vector association degree, including: using the second hidden layer parameter in the target hidden layer to process the association relationship representation vector to obtain a key vector; using the third hidden layer parameter in the target hidden layer to process the target semantic vector to obtain a query vector; calculating the vector association degree based on the key vector and the query vector; determining the attention weight corresponding to the adjacent entity based on the vector association degree, and the vector association degree is positively correlated with the attention weight corresponding to the adjacent entity.
[0098] Among them, the attention mechanism can include a key vector (key) and a query vector (query), and the key vector (key) and the value (first knowledge vector) have a corresponding relationship. The attention weight corresponding to the adjacent entity can be determined based on the correlation between the key vector (key) and the query vector (query). The second hidden layer parameter is a model parameter in the target hidden layer for processing the association relationship representation vector, and the third hidden layer parameter is a model parameter in the target hidden layer for processing the target semantic vector. The second hidden layer parameters and the third hidden layer parameters corresponding to different hidden layers are changing, so the attention weight is also changing, which is equivalent to obtaining the target knowledge vector by integrating the attention weights obtained from different hidden layers, which can improve the accuracy of the obtained target knowledge vector. The vector correlation degree can be a vector similarity, which can be obtained based on a similarity algorithm, such as a cosine similarity algorithm.
[0099] Specifically, the server can input the association relationship representation vector and the target semantic vector into the target hidden layer, calculate the key vector through the second hidden layer parameters of the target hidden layer, calculate the query vector through the third hidden layer parameters of the target hidden layer, calculate the similarity between the query vector and the key vector, normalize the similarity, and obtain the attention weight. The formula for obtaining the query vector q can be expressed as formula (9), and the key vector is calculated The formula can be expressed as formula (10), as well as represents the second hidden layer parameter in the i-th hidden layer, and It indicates that there is a bias in the matrix to be learned in the i-th hidden layer, that is, the third hidden layer parameter in the i-th hidden layer, and σ is the activation function, such as the tanh function.
[0100]
[0101]
[0102] Step S408, determining the target knowledge representation vector corresponding to the network graph entity according to the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity.
[0103] Specifically, there may be one or more adjacent entities corresponding to a network graph entity, and the server may weight the sum of the attention weight and the entity representation vector of the adjacent entity to obtain the knowledge representation vector corresponding to the network graph entity. The entity representation vector of the adjacent entity may also be processed using the model parameters of the trained knowledge vector determination model to obtain a first knowledge vector, and then the first knowledge representation vector and the attention weights corresponding to the adjacent entity are weighted to obtain a target knowledge representation vector corresponding to the network graph entity. The knowledge vector determination model may include one or more hidden layers, and for at least one hidden layer, a step of weighted processing according to the first knowledge representation vector and the attention weights corresponding to the adjacent entity may be performed.
[0104] In some embodiments, the knowledge representation vector corresponding to the network graph entity is output by a knowledge vector determination model, and the knowledge vector determination model includes at least one target hidden layer. According to the attention weights corresponding to the adjacent entities and the entity representation vectors of the adjacent entities, determining the target knowledge representation vector corresponding to the network graph entity includes: inputting the entity representation vector of the adjacent entity and the association relationship representation vector into the target hidden layer for processing to obtain the first knowledge representation vector corresponding to the network graph entity; determining the target knowledge representation vector corresponding to the network graph entity according to the first knowledge representation vector corresponding to the network graph entity and the attention weights corresponding to the corresponding adjacent entities.
[0105] Among them, hidden layer is the abbreviation of hidden layer. The target hidden layer can be one or more. The hidden layer includes model parameters obtained by model training, and the entity representation vector is processed based on the model parameters.
[0106] Specifically, the server can perform weighted processing on the first knowledge representation vector corresponding to the network graph entity and the attention weight corresponding to the corresponding adjacent entity to obtain the knowledge representation vector corresponding to the network graph entity. Since the entity representation vector and the association relationship representation vector of the adjacent entity are input into the hidden layer for processing, the knowledge representation vector is determined by combining the entity representation vector and the association relationship representation vector, so that the obtained knowledge representation vector is more accurate.
[0107] In some embodiments, the target calculation direction can be determined based on the entity association relationship between the network graph entity and the corresponding adjacent entity, and the target calculation direction is addition or subtraction; the entity representation vector and the association relationship representation vector of the adjacent entity are calculated according to the target calculation direction to obtain the calculation representation vector corresponding to the network graph entity; the calculation representation vector is processed using the hidden layer parameters in the target hidden layer to obtain the first knowledge representation vector corresponding to the network graph entity.
[0108] Specifically, when the entity association relationship is that the network graph entity is the head entity and the adjacent entity is the tail entity, the target calculation direction is subtraction. When the entity association relationship is that the network graph entity is the tail entity and the adjacent entity is the head entity, the target calculation direction is addition. When determining the entity representation vector and the association relationship representation vector in the relationship network graph, the relationship of the entities can be regarded as a translation operation from the head entity to the tail entity, that is, according to the head entity and the association relationship, the tail entity can be obtained. Therefore, the entity representation vector of the head entity plus the association relationship representation vector can represent the tail entity. Or the entity representation vector of the tail entity minus the association relationship representation vector can represent the head entity. Therefore, calculating the representation vector refers to calculating the entity representation vector and the association relationship representation vector of the adjacent entity according to the target calculation direction, and the resulting vector represents the network graph entity. Therefore, by processing the calculated representation vector based on the target hidden layer, the first knowledge representation vector corresponding to the network graph entity can be accurately obtained.
[0109] In some embodiments, the server can obtain the output representation vector corresponding to the output of the previous hidden layer corresponding to the target hidden layer in the knowledge vector determination model, and the output representation vector corresponding to the adjacent entity; the target hidden layer uses the first hidden layer parameters to process the calculated representation vector and the output representation vector to obtain the first knowledge representation vector corresponding to the network graph entity.
[0110] Specifically, the output representation vector corresponding to the adjacent entity refers to the knowledge representation vector of the adjacent entity output in the previous hidden layer. The first hidden layer parameter is a parameter in the hidden layer used to determine the first knowledge representation vector. The knowledge vector determination model may include multiple hidden layers. For the target hidden layer, the knowledge representation vector corresponding to the adjacent entity output by the previous hidden layer can be obtained and input into the target hidden layer, so that the target hidden layer continues to process on the basis of the previous hidden layer, which can make the knowledge vector more and more accurate as the depth of the hidden layer gradually increases.
[0111] For example, the knowledge vector determination model may include multiple target hidden layers. For any network graph entity in the relational network graph, in each target hidden layer, the formula for calculating the corresponding first knowledge representation vector may be as shown in formula (11), and the target knowledge representation vector for calculating the network graph entity may be as shown in formula (12). In formula (11), Indicates that in the i-th hidden layer, for the network graph entity e, based on the adjacent entity The first knowledge vector is obtained by the entity representation vector W. i Refers to the model parameters in the target hidden layer, which are obtained by model training. yes The knowledge vector obtained in the i-1 hidden layer, [;] means to connect the expressions horizontally, for example and Perform horizontal splicing. is the head entity of the triple, that is, when When , the first term of formula (11) is used to calculate When adjacent entities is the tail entity of the triple, that is, when When , the second term of formula (11) is used to calculate In formula (12), e i The knowledge representation vector of the network graph entity e representing the output of the i-th hidden layer. N e represents the set of adjacent nodes of e, f i (.) is the aggregation function in the i-th layer, which is used to perform weighted calculation based on the first knowledge vector and the corresponding attention weight, that is, not all knowledge content g m It is effective for understanding the input text. Through the attention mechanism, different weights can be given to the knowledge representation vectors obtained based on adjacent entities to obtain the target knowledge vector. i The formula of (.) can be expressed as formula (13). In formula (13), T represents transposition, express The corresponding key vector, q represents the query vector. Exp represents the exponential function with the natural constant e as the base.
[0112] The meaning of formulas (11), (12) and (13) can be explained as follows: In order to dynamically determine the influence of the adjacent entities corresponding to the network graph entity on the knowledge representation vector of the network graph entity according to the context content of the text, a knowledge vector determination model can be provided, which can be called S-GNN (semantic driven graph neural network). The entity representation vector and the association relationship representation vector obtained based on the TransE algorithm in the relationship network graph can be input into the S-GNN. The S-GNN model determines the importance of the association relationship between the network graph entity and its adjacent entities to the semantics based on the target semantic vector. Therefore, when determining the knowledge representation vector corresponding to the network graph based on the entity representation vector corresponding to the adjacent entity, the more important the relationship is to the target semantics, the greater the importance for determining the knowledge representation vector, so that important knowledge can be selected to determine the knowledge representation vector of the target entity.
[0113]
[0114]
[0115]
[0116] Step S410, extracting the target knowledge representation vector corresponding to the target entity from the target knowledge representation vectors corresponding to each network graph entity of the relationship network graph.
[0117] Specifically, since the relational network graph includes the target entity, that is, the target entity is one of the network graph entities, after obtaining the knowledge representation vector corresponding to the network graph entity, the knowledge representation vector corresponding to the target entity can be extracted.
[0118] In the embodiment of the present application, by forming a relationship network graph, an association relationship representation vector of the association relationship between the network graph entity and the adjacent entity is obtained, and the vector association degree is obtained based on the association relationship representation vector and the target semantic vector, which can indicate whether the association relationship between the network graph entity and its adjacent entity is related to the semantics of the target text or whether it has a positive impact. Therefore, the knowledge representation vector of the network graph entity is obtained by aggregating the attention weight and the entity representation vector of the adjacent entity, so that the aggregation of knowledge can be related to the semantics of the target text. It can be understood that the knowledge representation vector of the network graph entity obtained by aggregating the entity representation vector of the adjacent entity can be performed multiple times. In each aggregation, the knowledge representation vector obtained by the previous aggregation and the entity representation vector of the adjacent entity can be aggregated. For example, the knowledge vector determination model can be used for aggregation. The knowledge vector determination model can include multiple hidden layers. The knowledge representation vector output by the previous hidden layer, such as the second layer, and the entity representation vector of the adjacent entity can be used as the input of the next hidden layer, such as the third layer, to continue processing and obtain the knowledge representation vector output by the next layer.
[0119] In one embodiment, Figure 6 As shown, a text processing model training method is provided, and the method is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0120] Step S602, obtaining the training text and the standard text processing result corresponding to the training text.
[0121] Among them, the standard text processing result refers to the standard processing result of the training text, which can be considered as the correct processing result. For example, assuming that the training task is to predict words in the text, the training text can be a text that has been processed by word masking. For example, the symbol "[mask]" can be used to replace certain words in the complete text to obtain the training text, and the standard text processing result is the masked word. For example, assuming that the complete text is "Today is Friday", and assuming that the symbol "[mask]" replaces "yes", the training text is "Today [mask] Friday", and the standard text processing result is "yes". For another example, assuming that the training task is to classify the text, the standard processing result is the correct classification result of the text.
[0122] Specifically, the server may obtain an initial text, process the initial text, such as performing word masking processing, to obtain a training text, and obtain a standard text processing result corresponding to the training text.
[0123] Step S604: input the training text into the text encoding model to obtain a training text encoding vector, where the training text encoding vector includes a training semantic vector corresponding to the training text.
[0124] Specifically, the text encoding model can encode the training text, for example, segment the training text to obtain the corresponding training word sequence, and then encode the training words corresponding to each training word sequence to obtain the training word encoding vector corresponding to each training word, as well as the training semantic vector representing the semantics of the training text.
[0125] Step S606: Obtain a training entity corresponding to the training text, and determine a second associated entity corresponding to the training entity.
[0126] Specifically, the second associated entity refers to an entity that has an associated relationship with the training entity. The second associated entity may be, for example, an associated entity whose association order with the training entity is within a preset association order. The method for obtaining the training entity and the second associated entity corresponding to the training entity may refer to the method of step S204, which will not be repeated here.
[0127] Step S608, input the entity representation vector corresponding to the second associated entity into the knowledge vector determination model, and determine the training knowledge representation vector corresponding to the training entity based on the entity representation vector and the corresponding attention weight. The attention weight is obtained based on the correlation between the training semantic vector and the association relationship representation vector. The association relationship representation vector is a vector representing the entity association relationship.
[0128] Specifically, the knowledge vector determination model is used to obtain the knowledge representation vector. The method of obtaining the training knowledge representation vector can refer to the method of obtaining the target knowledge representation vector.
[0129] For example, the server can obtain a training network graph composed of training entities and second associated entities, and for the network graph entities in the training network graph, obtain an association relationship representation vector that represents the association relationship between the network graph entity and the adjacent entity; obtain the vector association degree based on the association relationship representation vector and the training semantic vector, and determine the attention weight corresponding to the adjacent entity based on the vector association degree; determine the training knowledge representation vector corresponding to each entity in the training network graph based on the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity; and extract the training knowledge representation vector corresponding to the training entity from the training knowledge representation vector corresponding to each network graph entity in the training network graph.
[0130] For another example, the entity representation vector and the association relationship representation vector of the adjacent entity can be input into the target hidden layer for processing to obtain the first knowledge representation vector corresponding to each network graph entity in the training network graph, and the training knowledge representation vector corresponding to the network graph entity is determined according to the first knowledge representation vector corresponding to the network graph entity and the attention weight corresponding to the corresponding adjacent entity. In the training stage, the parameters of the target hidden layer can be continuously optimized.
[0131] Step S610, input the training text encoding vector and the training knowledge representation vector corresponding to the training entity into the fusion model for fusion processing to obtain a training fusion result.
[0132] Specifically, the training fusion result can be obtained by referring to the method of obtaining the target fusion result, which will not be described in detail here.
[0133] For example, the server can perform knowledge integration processing on the word segmentation coding vector corresponding to the training word segmentation according to the training knowledge representation vector corresponding to the training entity, and obtain the knowledge integration coding vector corresponding to the training word segmentation; use the knowledge integration coding vector corresponding to the training word segmentation to update the word segmentation coding vector sequence, and the word segmentation coding vector corresponding to the training word segmentation to obtain an updated word segmentation coding vector sequence; use the fusion model to fuse the updated word segmentation coding vector sequence and the training semantic vector to obtain a fused word segmentation coding vector sequence and a fused training semantic vector.
[0134] Step S612, processing the training fusion result according to the task processing model to obtain a training processing result.
[0135] Specifically, the task processing model is used to process text, for example, it can be a translation model or a text classification model, and can be set according to different needs.
[0136] In some embodiments, the text processing model processing method provided in the embodiments of the present application may be performed in the pre-training stage of pre-training a pre-trained language model (Pre-trained Model), or may be performed in the fine-tuning stage of fine-tuning the pre-trained language model according to the downstream text processing tasks and the pre-trained language model after the pre-trained language model is trained. The fine-tuning stage refers to adjusting the task processing model according to the downstream tasks based on the pre-trained pre-trained language model. In the pre-training stage, the task processing model may be a model for predicting masked words or a sentence relationship judgment model. In the fine-tuning stage, the task processing in the pre-training task may be replaced with the task processing model in the fine-tuning stage as needed, and then fine-tuned. For example, in the fine-tuning stage, the task processing may be replaced with a summary generation model or a translation model.
[0137] Step S614, adjusting the parameters of the task processing model according to the training processing results and the standard text processing results, or adjusting the parameters of the task processing model and the language model, the language model including the text encoding model, the knowledge vector determination model and the fusion model.
[0138] Specifically, the training processing result refers to the processing result output by the model. A language model (LM) is a probability distribution of a natural language text sequence, which characterizes the possibility of the existence of a text of a specific length and a specific sequence. A pre-trained language model can be trained using a large amount of text data to project the words in the text into a tensor space. The pre-trained language model can be, for example, a pre-trained model such as BERT or RoBERTa. The text processing model includes a language model and a task processing model. Depending on different text processing tasks, the task processing model may be different. For example, the task processing model may be a model for text classification or a model for translation. The language model includes a text encoding model, a knowledge vector determination model, and a fusion model. During model training, if it is in the fine-tuning stage, it is possible to adjust only the model parameters of the task processing model, or it is possible to adjust the model parameters of the task processing model and the language model at the same time. In the pre-training stage, the model parameters of the task processing model and the language model may be adjusted at the same time.
[0139] In some embodiments, the server may obtain a model loss value based on the difference between the training processing result and the standard text processing result. The greater the difference, the greater the model loss value. The parameters of the model are adjusted in a direction that reduces the model loss value until the model converges to obtain a text processing model. The model convergence may mean that the model loss value is less than a preset loss value.
[0140] In the pre-training stage, in order to better integrate knowledge into the pre-trained language model, the entities in the training text can be randomly masked according to the DenoisingEntity Auto-Encoder (DEA) method. The text processing model learns to use the entity representation in the text to predict which entity in the knowledge graph the masked entity is, that is, the probability that the entity in the knowledge graph is the masked entity. The probability that the entity in the knowledge graph is the masked entity is obtained based on the prediction, and the cross-entropy loss value is calculated through the cross-entropy function. The parameters of the model are adjusted according to the cross-entropy loss value.
[0141] In some embodiments, the calculation method of the model loss value can be determined according to the adopted base model, for example, BERT can be used. BASE 、RoBERTa BASE or RoBERTa LARGE As a base model, the task processing model and language model of this application can be built on the base model, and the parameters of the base model are used as initial parameters to initialize the text encoding parameters. Different base models can correspond to different loss functions. For example, when using BERT BASE is the basis model, then the corresponding loss function can be expressed as formula (14). Represents the model loss value, Represents the loss value corresponding to the language model, Represents the loss value of sentence relationship prediction. For example, the expression [CLS] can be used to predict the next sentence (NSP) of a given text. The loss value of sentence relationship prediction is obtained based on the prediction result and the standard result. Represents the loss value obtained based on the DEA algorithm. BASE or RoBERTa LARGE is the basis model, then the corresponding loss function can be expressed as formula (15)
[0142]
[0143]
[0144] In the above-mentioned text processing model training method, since the language model includes a text encoding model, a knowledge vector determination model and a fusion model, the knowledge vector determination model can determine the training knowledge representation vector corresponding to the training entity according to the entity representation vector and the corresponding attention weight. The attention weight is obtained according to the correlation between the training semantic vector and the association relationship representation vector. The association relationship representation vector is a vector representing the entity association relationship. Since the attention weight is obtained according to the correlation between the training semantic vector and the association relationship representation vector, the importance of the entity representation vector of the associated entity to the representation vector of the training entity can be determined according to the semantics of the training text, and the attention weight is determined according to the importance, so that the obtained training knowledge vector can better promote the understanding of the semantics of the training text, thereby improving the text comprehension ability of the obtained language model and the task processing model, and improving the accuracy of the text processing results.
[0145] The text processing method provided in the embodiment of the present application can be applied to tasks such as translating or classifying text. Figure 7 As shown, it is an interface diagram for text translation in some embodiments, which is an interface for translating Chinese into English. The terminal can receive input sentences to be translated. When a translation operation is received, such as clicking the "Translate" control in the interface, a translation request can be sent to the server. The server can input the text to be translated into the language model to obtain the target fusion result corresponding to the language model. The task processing model obtains the translation result based on the target fusion result. The server returns the translation result to the terminal, and the terminal displays the translation result on the interface.
[0146] The text processing method provided in the embodiment of the present application, by using the pre-trained speech model as the basis, can utilize the context of the entity in the target text, capture the subgraph (relationship network diagram) from the knowledge graph, and obtain the knowledge representation vector corresponding to the entity through calculation, and migrate the knowledge representation vector into the pre-trained language model to enhance the language model's ability to understand the language. For example, for the target text "Steph Curry and Klay Thompson led the Warriors to the 2015 NBA Championship", for humans, it can be inferred from the target text that Stephen Curry and Klay Thompson play for the same team, but such information that is intuitive to humans may not be intuitive to the language model. Therefore, it can be obtained based on the knowledge of the knowledge graph. In the knowledge graph, not all information is useful, or even has a negative impact. For example, see Figure 8 ,The size of the circle surrounding the entity represents the importance of the entity to the target text, Figure 8 In the example above, for the target entity "Stephen", the corresponding triple [Rayley, daughter, Stephen] is less important than [Stephen, plays for, Warriors] in the given sentence. Therefore, the attention weights corresponding to the adjacent entities can be determined through the target semantic vector and the association relationship representation vector. The knowledge representation vectors of each entity can be determined based on the entity representation vectors corresponding to the adjacent entities and the attention weights, so that the knowledge that is more important to the target text can be focused on and the knowledge representation vector of the target entity can be obtained. That is, by introducing human knowledge, the necessary knowledge can be screened out according to the context of the text, and different weights can be given through the attention mechanism, and finally aggregated into the knowledge representation vector corresponding to the target entity, and the knowledge representation vector can be embedded in the pre-trained language model, thereby improving the model's ability to understand the text.
[0147] The following combination Fig. 9 , the text processing method provided in the embodiment of the present application is described, comprising the following steps:
[0148] 1. Obtain the target text to be processed, encode the target text, and obtain the target text encoding vector.
[0149] Specifically, the target text can be input into the text encoding model for encoding to obtain the target text encoding vector. The target text encoding vector includes a word segmentation encoding vector sequence and a target semantic vector. For example, assuming that the target text is "Steph Curry and Klay Thompson led the Warriors to the 2015 NBAChampionship", after word segmentation, the word segmentation result obtained is "Steph Curry / and / Klay Thompson / led / the / Warriors / to / the / 2015 NBA Championship / ", and the text encoding model can encode the word segmentation encoding vector corresponding to each word segmentation and the target semantic vector that expresses the semantics of the target text. For example, the target semantic vector can be the semantic representation of [CLS].
[0150] 2. Obtain the target entity in the target text and determine the first associated entity corresponding to the target entity.
[0151] 3. Obtain the relationship network diagram consisting of the first associated entity and the target entity.
[0152] Specifically, the target entity may include, for example, "Steph Curry" and "Klay Thompson". The following is an illustration using "Steph Curry" as an example. According to the knowledge graph, it can be obtained that "Steph Curry" plays for "warriors", and "Riley" is the daughter of "Steph Curry", so the first associated entities "warriors" and "Riley" corresponding to "Steph Curry" can be obtained. Assuming that the preset order is 2, the associated entities A and B corresponding to "warriors" and entities C and D corresponding to "Riley" can be obtained to form a relationship network diagram.
[0153] 4. According to the association relationship representation vector and the target semantic vector, the vector association degree is obtained, and the attention weight corresponding to the adjacent entity is determined according to the vector association degree.
[0154] 5. Determine the target knowledge representation vector corresponding to the network graph entity based on the attention weight corresponding to the adjacent entity and the target entity representation vector of the adjacent entity.
[0155] Specifically, Fig. 9As shown, the expression of [CLS] of the text encoding model is input into the knowledge vector determination model. For each network graph entity in the relationship network graph, the corresponding first knowledge representation vector can be obtained according to the entity representation vector of its adjacent entity, and then the attention weight of the first knowledge representation vector is determined based on the expression of CLS and the association relationship representation vector, and the target knowledge representation vector of the network graph entity is determined based on the first knowledge representation vector and the corresponding attention weight.
[0156] See also Fig. 9 , Fig. 9 In the figure, for the knowledge representation vector of the network graph entity "warriors", two first knowledge representation vectors can be determined according to the entity representation vectors of its adjacent entities A and B, and the attention weights corresponding to the two first knowledge representation vectors can be determined based on the expression of [CLS], and the knowledge representation vector of "warriors" can be obtained according to the first knowledge representation vectors and the corresponding attention weights.
[0157] For the knowledge representation vector of the network graph entity “Steph Curry”, the first knowledge vector a1 can be determined according to the entity representation vector of “warriors” and the first knowledge vector a2 can be determined according to the entity representation vector of “Riley”. The attention weights corresponding to the two first knowledge representation vectors can be determined based on the expression of [CLS], for example, Fig. 9 In the figure, we can get the attention weight corresponding to a1 is 0.9, and the attention weight corresponding to a2 is 0.1. That is, in the knowledge graph, for the text "Steph Curry and Klay Thompson led the Warriors to the 2015 NBA Championship", the knowledge that "Steph Curry" plays for "warriors" is more important than the knowledge that "Steph Curry's daughter is "Riley". Therefore, when determining the knowledge representation vector corresponding to "Steph Curry", more attention is paid to the knowledge that "Steph Curry" plays for "warriors".
[0158] 6. Perform vector concatenation processing based on the target knowledge representation vector corresponding to the target entity and the word segmentation encoding vector corresponding to the target word segmentation, and integrate the knowledge corresponding to the target word segmentation into the encoding vector.
[0159] For example, for the target entity "Steph Curry", the fusion model can concatenate the word segmentation encoding vector of "Steph Curry" encoded by the text encoding model with the target knowledge representation vector of "Steph Curry" to obtain the knowledge corresponding to "Steph Curry" and integrate it into the encoding vector.
[0160] 7. Use the knowledge corresponding to the target word segmentation to integrate into the encoding vector, update the word segmentation encoding vector sequence, and the word segmentation encoding vector corresponding to the target word segmentation to obtain the updated word segmentation encoding vector sequence.
[0161] Specifically, the fusion model can replace the word segmentation encoding vector of "Steph Curry" in the word segmentation encoding vector sequence with the knowledge corresponding to "Steph Curry" and integrate it into the encoding vector.
[0162] 8. Use the fusion model to fuse the updated word segmentation encoding vector sequence and the target semantic vector to obtain the fused word segmentation encoding vector sequence and the fused target semantic vector.
[0163] Specifically, the fusion model can be a BERT-based model, which can obtain the target semantic vector and the updated word segmentation encoding vector sequence, continue encoding, and obtain the fused word segmentation encoding vector sequence and the fused target semantic vector.
[0164] 10. Determine the text processing result corresponding to the target text based on the target fusion result.
[0165] Specifically, the target fusion result can be at least one of the word segmentation encoding vector sequence after fusion processing or the target semantic vector after fusion processing, which can be selected according to actual needs. For example, for a text classification task, the target semantic vector after fusion processing can be used as the target fusion result.
[0166] It should be understood that, although the various steps in the above flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above flowchart may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0167] In one embodiment, Fig.10 As shown, a text processing device is provided, which can adopt a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: a target text encoding module 1002, a first entity acquisition module 1004, a target knowledge representation vector determination module 1006, a first fusion module 1008 and a text processing result determination module 1010, wherein:
[0168] The target text encoding module 1002 is used to obtain the target text to be processed, encode the target text, and obtain a target text encoding vector. The target text encoding vector includes a target semantic vector corresponding to the target text.
[0169] The first entity acquisition module 1004 is used to acquire the target entity in the target text and determine the first associated entity corresponding to the target entity.
[0170] The target knowledge representation vector determination module 1006 is used to determine the target knowledge representation vector corresponding to the target entity based on the entity representation vector of the first associated entity and the corresponding attention weight, wherein the attention weight is obtained based on the correlation between the target semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing the entity association relationship.
[0171] The first fusion module 1008 is used to fuse the target text encoding vector with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result.
[0172] The text processing result determination module 1010 is used to determine the text processing result corresponding to the target text according to the target fusion result.
[0173] In some embodiments, the target knowledge representation vector determination module includes: a relationship network diagram acquisition unit, which is used to obtain a relationship network diagram consisting of a first associated entity and a target entity; an association relationship representation vector acquisition unit, which is used to obtain, for a network diagram entity in the relationship network diagram, an association relationship representation vector representing the association relationship between the network diagram entity and the adjacent entity; an attention weight determination unit, which is used to obtain a vector association degree based on the association relationship representation vector and the target semantic vector, and determine the attention weight corresponding to the adjacent entity based on the vector association degree; a target knowledge representation vector determination unit, which is used to determine the target knowledge representation vector corresponding to the network diagram entity based on the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity; and an extraction unit, which is used to extract the target knowledge representation vector corresponding to the target entity from the target knowledge representation vectors corresponding to each network diagram entity of the relationship network diagram.
[0174] In some embodiments, the target knowledge representation vector corresponding to the network graph entity is output by a knowledge vector determination model, the knowledge vector determination model includes at least one target hidden layer, and the target knowledge representation vector determination unit is used to: input the entity representation vector and the association relationship representation vector of the adjacent entity into the target hidden layer for processing to obtain the first knowledge representation vector corresponding to the network graph entity; determine the target knowledge representation vector corresponding to the network graph entity based on the first knowledge representation vector corresponding to the network graph entity and the attention weight corresponding to the corresponding adjacent entity.
[0175] In some embodiments, the target knowledge representation vector determination unit is used to: determine the target calculation direction according to the entity association relationship between the network graph entity and the adjacent entity, the target calculation direction being addition or subtraction; calculate the entity representation vector and the association relationship representation vector of the adjacent entity according to the target calculation direction to obtain the calculation representation vector corresponding to the network graph entity; use the hidden layer parameters in the target hidden layer to process the calculation representation vector to obtain the first knowledge representation vector corresponding to the network graph entity.
[0176] In some embodiments, the target knowledge representation vector determination unit is used to: obtain the output representation vector corresponding to the adjacent entity of the previous hidden layer output corresponding to the target hidden layer in the knowledge vector determination model; the target hidden layer uses the first hidden layer parameters to process the calculated representation vector and the output representation vector to obtain the first knowledge representation vector corresponding to the network graph entity.
[0177] In some embodiments, the target knowledge representation vector corresponding to the network graph entity is output by the knowledge vector determination model, and the attention weight determination unit is used to: use the second hidden layer parameters in the target hidden layer to process the association relationship representation vector to obtain a key vector; use the third hidden layer parameters in the target hidden layer to process the target semantic vector to obtain a query vector; calculate the vector association degree based on the key vector and the query vector; determine the attention weight corresponding to the adjacent entity based on the vector association degree, and the vector association degree is positively correlated with the attention weight corresponding to the adjacent entity.
[0178] In some embodiments, the target text includes multiple word segments, the target text encoding vector includes a word segment encoding vector sequence, and the word segment encoding vector sequence includes the word segment encoding vectors corresponding to each word segment; the first fusion module includes: a knowledge integration encoding vector obtaining unit, which is used to perform knowledge integration processing on the word segment encoding vector corresponding to the target word segment according to the target knowledge representation vector corresponding to the target entity, and obtain the knowledge integration encoding vector corresponding to the target word segment; an updating unit, which is used to use the knowledge integration encoding vector corresponding to the target word segment to update the word segment encoding vector corresponding to the target word segment in the word segment encoding vector sequence, and obtain an updated word segment encoding vector sequence; a fusion unit, which is used to use the fusion model to fuse the updated word segment encoding vector sequence and the target semantic vector, and obtain the fused word segment encoding vector sequence and the fused target semantic vector.
[0179] In some embodiments, the text processing result determination module is used to: input the fused target semantic vector into a trained text classification model to obtain a text classification result corresponding to the target text.
[0180] In some embodiments, the knowledge integration coding vector obtaining unit is used to: perform vector concatenation processing on the target knowledge representation vector corresponding to the target entity and the word segmentation coding vector corresponding to the target word segmentation to obtain the knowledge integration coding vector corresponding to the target word segmentation.
[0181] In one embodiment, Fig.11 As shown, a text processing model training device is provided, which can adopt a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: a training text acquisition module 1102, a training text encoding vector acquisition module 1104, a second entity acquisition module 1106, a training knowledge representation vector determination module 1108, a training fusion result acquisition module 1110, a training processing result acquisition module 1112 and an adjustment module 1114, wherein:
[0182] The training text acquisition module 1102 is used to acquire the training text and the standard text processing result corresponding to the training text.
[0183] The training text encoding vector obtaining module 1104 is used to input the training text into the text encoding model to obtain the training text encoding vector, and the training text encoding vector includes the training semantic vector corresponding to the training text.
[0184] The second entity acquisition module 1106 is used to acquire the training entity corresponding to the training text and determine the second associated entity corresponding to the training entity.
[0185] The training knowledge representation vector determination module 1108 is used to input the entity representation vector corresponding to the second associated entity into the knowledge vector determination model, and determine the training knowledge representation vector corresponding to the training entity based on the entity representation vector and the corresponding attention weight. The attention weight is obtained based on the correlation between the training semantic vector and the association relationship representation vector. The association relationship representation vector is a vector representing the entity association relationship.
[0186] The training fusion result obtaining module 1110 is used to input the training text encoding vector and the training knowledge representation vector corresponding to the training entity into the fusion model for fusion processing to obtain the training fusion result.
[0187] The training processing result obtaining module 1112 is used to process the training fusion result according to the task processing model to obtain the training processing result.
[0188] The adjustment module 1114 is used to adjust the parameters of the task processing model according to the training processing results and the standard text processing results, or adjust the parameters of the task processing model and the language model. The language model includes a text encoding model, a knowledge vector determination model and a fusion model.
[0189] For the specific definition of the text processing device and the text processing model training device, please refer to the definition of the text processing method above, which will not be repeated here. The various modules in the above-mentioned text processing device and text processing model training device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0190] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store target text. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a text processing method or a text processing model training method is implemented.
[0191] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0192] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0193] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are 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 steps in the above-mentioned method embodiments.
[0194] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0195] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0196] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A text processing method, characterized in that: The method comprises: Obtaining a target text to be processed, encoding the target text to obtain a target text encoding vector, wherein the target text encoding vector includes a target semantic vector corresponding to the target text; Acquire a target entity in the target text, and determine a first associated entity corresponding to the target entity; Determine a target knowledge representation vector corresponding to the target entity according to the entity representation vector of the first associated entity and the corresponding attention weight, wherein the attention weight is obtained according to the degree of association between the target semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing an entity association relationship; The target text encoding vector is fused with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result; The text processing result corresponding to the target text is determined according to the target fusion result.
2. The method according to claim 1, characterized in that The determining, according to the entity representation vector of the first associated entity and the corresponding attention weight, the target knowledge representation vector corresponding to the target entity comprises: Obtaining a relationship network diagram consisting of the first associated entity and the target entity; For a network graph entity in the relationship network graph, obtaining an association relationship representation vector representing an association relationship between the network graph entity and an adjacent entity; Obtaining a vector association degree according to the association relationship representation vector and the target semantic vector, and determining an attention weight corresponding to the adjacent entity according to the vector association degree; Determine the target knowledge representation vector corresponding to the network graph entity according to the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity; From the target knowledge representation vectors corresponding to the network graph entities of the relationship network graph, the target knowledge representation vector corresponding to the target entity is extracted.
3. The method according to claim 2, characterized in that The target knowledge representation vector corresponding to the network graph entity is output by a knowledge vector determination model, the knowledge vector determination model includes at least one target hidden layer, and the determining the target knowledge representation vector corresponding to the network graph entity according to the attention weight corresponding to the adjacent entity and the entity representation vector of the adjacent entity includes: Inputting the entity representation vector of the adjacent entity and the association relationship representation vector into the target hidden layer for processing to obtain a first knowledge representation vector corresponding to the network graph entity; According to the first knowledge representation vector corresponding to the network graph entity and the attention weight corresponding to the corresponding adjacent entity, a target knowledge representation vector corresponding to the network graph entity is determined.
4. The method according to claim 3, characterized in that The step of inputting the entity representation vector of the adjacent entity and the association relationship representation vector into the target hidden layer for processing to obtain the first knowledge representation vector corresponding to the network graph entity comprises: Determine a target calculation direction according to the entity association relationship between the network graph entity and the adjacent entity, the target calculation direction being addition or subtraction; Calculate the entity representation vector of the adjacent entity and the association relationship representation vector according to the target calculation direction to obtain a calculation representation vector corresponding to the network graph entity; The calculated representation vector is processed using the hidden layer parameters in the target hidden layer to obtain a first knowledge representation vector corresponding to the network graph entity.
5. The method according to claim 4, characterized in that The step of processing the calculated representation vector by using the hidden layer parameters in the target hidden layer to obtain the first knowledge representation vector corresponding to the network graph entity comprises: Obtaining, in the knowledge vector determination model, an output representation vector corresponding to the adjacent entity of the previous hidden layer output corresponding to the target hidden layer; The target hidden layer processes the calculation representation vector and the output representation vector using the first hidden layer parameters to obtain a first knowledge representation vector corresponding to the network graph entity.
6. The method according to claim 2, characterized in that The target knowledge representation vector corresponding to the network graph entity is output by a knowledge vector determination model, the knowledge vector determination model includes at least one target hidden layer, the vector association degree is obtained according to the association relationship representation vector and the target semantic vector, and the attention weight corresponding to the adjacent entity is determined according to the vector association degree, including: Processing the association relationship representation vector using the second hidden layer parameter in the target hidden layer to obtain a key vector; Processing the target semantic vector using the third hidden layer parameter in the target hidden layer to obtain a query vector; Calculating a vector association degree according to the key vector and the query vector; The attention weight corresponding to the adjacent entity is determined according to the vector association degree, and the vector association degree is positively correlated with the attention weight corresponding to the adjacent entity.
7. The method according to claim 1, characterized in that The target text includes a plurality of segmented words, the target text encoding vector includes a segmented word encoding vector sequence, and the segmented word encoding vector sequence includes the segmented word encoding vector corresponding to each segmented word; The target text encoding vector is fused with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result, including: Performing knowledge integration processing on the word segmentation encoding vector corresponding to the target word segmentation according to the target knowledge representation vector corresponding to the target entity, so as to obtain the knowledge integration encoding vector corresponding to the target word segmentation; Using the knowledge corresponding to the target word segmentation to integrate into the encoding vector, the word segmentation encoding vector corresponding to the target word segmentation in the word segmentation encoding vector sequence is updated to obtain an updated word segmentation encoding vector sequence; The updated word segmentation coding vector sequence and the target semantic vector are fused using a fusion model to obtain a fused word segmentation coding vector sequence and a fused target semantic vector.
8. The method according to claim 7, characterized in that Determining the text processing result corresponding to the target text according to the target fusion result includes: The fused target semantic vector is input into the trained text classification model to obtain the text classification result corresponding to the target text.
9. The method according to claim 7, characterized in that: The step of performing knowledge integration processing on the word segmentation encoding vector corresponding to the target word segmentation according to the target knowledge representation vector corresponding to the target entity to obtain the knowledge integration encoding vector corresponding to the target word segmentation includes: Vector concatenation processing is performed on the target knowledge representation vector corresponding to the target entity and the word segmentation encoding vector corresponding to the target word segmentation to obtain the knowledge corresponding to the target word segmentation integrated into the encoding vector.
10. A text processing model training method, characterized in that: The method comprises: Obtaining a training text and a standard text processing result corresponding to the training text; Inputting the training text into a text encoding model to obtain a training text encoding vector, wherein the training text encoding vector includes a training semantic vector corresponding to the training text; Acquire a training entity corresponding to the training text, and determine a second associated entity corresponding to the training entity; Inputting the entity representation vector corresponding to the second associated entity into the knowledge vector determination model, and determining the training knowledge representation vector corresponding to the training entity according to the entity representation vector and the corresponding attention weight, wherein the attention weight is obtained according to the degree of association between the training semantic vector and the association relationship representation vector, wherein the association relationship representation vector is a vector representing the entity association relationship; Inputting the training text encoding vector and the training knowledge representation vector corresponding to the training entity into a fusion model for fusion processing to obtain a training fusion result; Processing the training fusion result according to the task processing model to obtain a training processing result; The parameters of the task processing model are adjusted according to the training processing result and the standard text processing result, or the parameters of the task processing model and the language model are adjusted, and the language model includes the text encoding model, the knowledge vector determination model and the fusion model.
11. A text processing device, characterized in that: The device comprises: A target text encoding module is used to obtain a target text to be processed, encode the target text, and obtain a target text encoding vector, wherein the target text encoding vector includes a target semantic vector corresponding to the target text; A first entity acquisition module, used to acquire a target entity in the target text and determine a first associated entity corresponding to the target entity; a target knowledge representation vector determination module, configured to determine a target knowledge representation vector corresponding to the target entity according to the entity representation vector of the first associated entity and a corresponding attention weight, wherein the attention weight is obtained according to the degree of association between the target semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing an entity association relationship; A first fusion module is used to fuse the target text encoding vector with the target knowledge representation vector corresponding to the target entity to obtain a target fusion result; The text processing result determination module is used to determine the text processing result corresponding to the target text according to the target fusion result.
12. The device according to claim 11, characterized in that The target knowledge representation vector determination module includes: A relationship network diagram acquisition unit, used to acquire a relationship network diagram consisting of the first associated entity and the target entity; An association relationship representation vector acquisition unit, used for acquiring, for a network graph entity in the relationship network graph, an association relationship representation vector representing an association relationship between the network graph entity and an adjacent entity; An attention weight determination unit, configured to obtain a vector association degree according to the association relationship representation vector and the target semantic vector, and determine an attention weight corresponding to the adjacent entity according to the vector association degree; A target knowledge representation vector determination unit, configured to determine a target knowledge representation vector corresponding to the network graph entity according to an attention weight corresponding to the adjacent entity and an entity representation vector of the adjacent entity; The extraction unit is used to extract the target knowledge representation vector corresponding to the target entity from the target knowledge representation vectors corresponding to each network diagram entity of the relationship network diagram.
13. A text processing model training device, characterized in that: The device comprises: A training text acquisition module, used to acquire training text and standard text processing results corresponding to the training text; A training text encoding vector obtaining module, used for inputting the training text into a text encoding model to obtain a training text encoding vector, wherein the training text encoding vector includes a training semantic vector corresponding to the training text; A second entity acquisition module, used to acquire a training entity corresponding to the training text, and determine a second associated entity corresponding to the training entity; a training knowledge representation vector determination module, used to input the entity representation vector corresponding to the second associated entity into the knowledge vector determination model, and determine the training knowledge representation vector corresponding to the training entity according to the entity representation vector and the corresponding attention weight, wherein the attention weight is obtained according to the degree of association between the training semantic vector and the association relationship representation vector, and the association relationship representation vector is a vector representing the entity association relationship; A training fusion result obtaining module is used to input the training text encoding vector and the training knowledge representation vector corresponding to the training entity into a fusion model for fusion processing to obtain a training fusion result; A training processing result obtaining module is used to process the training fusion result according to the task processing model to obtain a training processing result; An adjustment module is used to adjust the parameters of the task processing model according to the training processing results and the standard text processing results, or to adjust the parameters of the task processing model and the language model, wherein the language model includes the text encoding model, the knowledge vector determination model and the fusion model.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
15. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
