Domain knowledge-combined text generation method and device, equipment and storage medium
By combining the text generation method of domain knowledge, the problems of data scarcity and semantic understanding ambiguity in domain knowledge representation are solved, the accuracy and efficiency of text generation are improved, and the quality of generated text is ensured.
Patent Information
- Application Number
- CN202411156528.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-27
AI Technical Summary
Domain knowledge representations have problems of data scarcity and semantic understanding ambiguity in applications, which affect the accuracy and efficiency of text generation.
Using a text generation method combining domain knowledge, input the trained domain classification model by preprocessing text data, obtaining text semantic feature vectors and domain classification information, annotating text semantic feature vectors based on the preset domain vocabulary list, and finally the data is Enter the text generation model for semantic prediction and generate the target text.
It improves the accuracy and efficiency of text generation, enhances the understanding and analysis ability of professional text, and ensures that the generated text meets the situation and user needs.
Smart Images

Figure CN119203932A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text generation method, device, equipment and storage medium combining domain knowledge. Background Art
[0002] Domain knowledge representation is the use of computer-understandable forms to capture and express knowledge in a specific field. This is particularly important in knowledge-intensive fields such as finance and medicine. Its applications involve text understanding in the medical field, special question-answering systems in the financial and medical fields, and information retrieval in the financial and medical fields. At present, domain knowledge representation also has many cutting-edge applications:
[0003] 1) Semantic matching: Semantic matching refers to judging the similarity or matching degree between two texts by semantically representing the texts in natural language processing. Semantic matching has a wide range of applications in search engines, recommendation systems, intelligent customer service and other fields.
[0004] 2) Semantic role labeling: Semantic role labeling refers to labeling the semantic roles of each word in a sentence, such as subject, object, predicate, etc. Semantic role labeling has a wide range of applications in natural language understanding, machine translation, question-answering systems, and other fields.
[0005] 3) Semantic dependency analysis: Semantic dependency analysis refers to the analysis of the semantic dependency relationship of each word in a sentence, such as subject-predicate relationship, verb-object relationship, etc. Semantic dependency analysis has a wide range of applications in natural language understanding, machine translation, question-answering systems and other fields.
[0006] 4) Semantic reasoning: Semantic reasoning refers to logical reasoning, inference, and reasoning through semantic representation of text. Semantic reasoning has a wide range of applications in natural language understanding, question-answering systems, intelligent customer service, and other fields.
[0007] At the same time, with the development of domain knowledge representation application areas, there are also problems of data scarcity and ambiguous semantic understanding. Summary of the invention
[0008] The purpose of the embodiments of the present application is to propose a text generation method, device, equipment and storage medium combined with domain knowledge to solve the technical problems of data scarcity and semantic ambiguity in the current application of domain knowledge representation.
[0009] In order to solve the above technical problems, the present application embodiment provides a text generation method combining domain knowledge, which adopts the following technical solutions:
[0010] Acquire query text data, and preprocess the query text data to obtain preprocessed text data;
[0011] Inputting the preprocessed text data into a trained domain classification model to obtain a text semantic feature vector and domain classification information;
[0012] Based on the domain classification information, a corresponding preset domain vocabulary is queried, and the text semantic feature vector is annotated according to the preset domain vocabulary to obtain an enhanced text semantic vector;
[0013] The preprocessed text data, the enhanced text semantic vector and the domain classification information are input into a trained text generation model for semantic prediction to generate a target text.
[0014] In order to solve the above technical problems, the embodiment of the present application further provides a text generation device combining domain knowledge, which adopts the following technical solution:
[0015] A preprocessing module, used to obtain query text data, preprocess the query text data, and obtain preprocessed text data;
[0016] A domain classification module, used to input the pre-processed text data into a trained domain classification model to obtain a text semantic feature vector and domain classification information;
[0017] A labeling module, used for querying a corresponding preset domain vocabulary based on the domain classification information, labeling the text semantic feature vector according to the preset domain vocabulary, and obtaining an enhanced text semantic vector;
[0018] The text generation module is used to input the pre-processed text data, the enhanced text semantic vector and the field classification information into a trained text generation model for semantic prediction to generate a target text.
[0019] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0020] The computer device includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned method for generating text in combination with domain knowledge when executing the computer-readable instructions.
[0021] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0022] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for generating text in combination with domain knowledge as described above are implemented.
[0023] Compared with the prior art, this application has the following beneficial effects:
[0024] The present application proposes a text generation method combining domain knowledge, which pre-processes the acquired query text data and inputs it into a trained domain classification model to obtain a text semantic feature vector and domain classification information, and then annotates the text semantic feature vector according to a preset domain vocabulary to obtain an enhanced text semantic vector. Finally, the pre-processed text data, the enhanced text semantic vector and the domain classification information are input into a trained text generation model for semantic prediction to generate a target text. The present application can perform domain recognition on the query text, recognize it according to its domain, and improve the accuracy of text generation. The text data is pre-processed, and the text semantic feature vector is annotated according to a preset domain vocabulary, which improves the quality of the text to be recognized. The text is generated by a text generation model, which can fully understand the text semantics, thereby improving the efficiency and accuracy of text generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0027] Figure 2 is a flow chart of an embodiment of a method for generating text in combination with domain knowledge according to the present application;
[0028] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S202;
[0029] Figure 4 yes Figure 2 A flowchart of a specific implementation of step S204;
[0030] Figure 5 is a structural schematic diagram of an embodiment of a text generation device combining domain knowledge according to the present application;
[0031] Figure 6 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0033] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0034] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0035] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, 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.
[0036] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0037] This application provides a text generation method combining domain knowledge, involving artificial intelligence, which can be applied to Figure 1 In the system architecture 100 shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0038] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0039] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0040] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0041] It should be noted that the text generation method combined with domain knowledge provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the text generation device combined with domain knowledge is generally set in the server / terminal device.
[0042] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0043] Continue to refer Figure 2 , shows a flowchart of an embodiment of a method for generating text in combination with domain knowledge according to the present application, comprising the following steps:
[0044] Step S201, obtaining query text data, and preprocessing the query text data to obtain preprocessed text data.
[0045] Query text data includes, but is not limited to, texts that require text understanding in the field of pharmaceutical finance, question texts in question-answering applications in the field of pharmaceutical finance, and information retrieval texts in the field of pharmaceutical finance. Among them, the financial field may include sub-fields such as insurance, stock markets, bonds, derivatives, banking, and investment management; the pharmaceutical field may include sub-fields such as drug development, clinical trials, and medical equipment. Specifically, in the pharmaceutical field, query text data includes medical literature queries, symptom and disease consultations, treatment method inquiries, drug information queries, preventive measures queries, medical examination explanations, and nutrition and diet recommendations; in the financial field, query text data includes insurance consultations, investment product consultations, market trend analysis, personal financial advice, financial terminology explanations, risk management queries, financial news interpretations, etc.
[0046] In this embodiment, the text generation method combined with domain knowledge is run on the electronic device (e.g. Figure 1 The server / terminal device shown in the figure can receive the query text data through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0047] Preprocess the query text data. Preprocessing includes data cleaning and text alignment. Data cleaning includes deduplication, special symbol processing, stop word removal, missing text processing, abnormal text processing, erroneous text correction, and text normalization.
[0048] Text alignment includes long text truncation and short text padding. Long text truncation is to truncate text that exceeds a predetermined length; short text padding is to pad text that is less than a predetermined length, using the same special symbol to pad to a fixed length.
[0049] Step S202: input the preprocessed text data into the trained domain classification model to obtain text semantic feature vectors and domain classification information.
[0050] In this embodiment, the text data is preprocessed by a trained domain classification model for domain identification, so as to ensure that the corresponding text is generated in a better combination with the domain knowledge later.
[0051] In some optional implementations, the domain classification model includes an embedding layer, a multi-scale feature extraction layer, at least two feature encoding layers, and a classification layer. After the preprocessed text data is input into the trained domain classification model, it is processed in sequence by the embedding layer, the multi-scale feature extraction layer, at least two feature encoding layers, and the classification layer, and finally the domain classification result is output.
[0052] Among them, see Figure 3 As shown, the above step of inputting the preprocessed text data into the trained domain classification model to obtain the text semantic feature vector and domain classification information includes:
[0053] Step S301, input the preprocessed text data into the embedding layer for position embedding, word embedding and character embedding to obtain a text encoding vector.
[0054] The embedding layer of this embodiment adopts the BERT embedding layer to perform position embedding, word embedding and character embedding on the text data, wherein the position embedding provides information about the position of the word in the sentence, which is crucial for understanding the grammatical structure and contextual relationship of the sentence; the word embedding captures the semantic information of the vocabulary, enabling the model to understand the meaning of the vocabulary in the context; the character embedding captures the information at the character level, and the character embedding helps the model process unknown vocabulary or spelling variants. By incorporating the character-level information into the model, the robustness of the model and its ability to handle unconventional inputs are improved.
[0055] Step S302, extracting features from the text encoding vector through a multi-scale feature extraction layer to obtain multi-scale features of the text.
[0056] By extracting text information of different granularities from the text encoding vector through a multi-scale feature extraction layer, it is possible to enrich semantic information, improve feature complementarity, and facilitate context understanding.
[0057] The multi-scale feature extraction layer can be implemented by constructing a feature pyramid, the encoder part of U-net, or stacking the encoder parts of multiple Transformer models.
[0058] Taking the encoder part of multiple Transformer models stacked as an example, the multi-scale feature extraction layer consists of 6 layers of stacked encoders, where layer 1 is for small-scale feature extraction, such as words; layers 2 to 3 are for medium-scale feature extraction, such as phrases; and layers 4 to 6 are for large-scale feature extraction, such as sentences. Layers 1, 3, and 6 are connected, that is, the input of the 3rd layer network is the output of the 1st layer and the original text encoding vector, and the input of the 6th layer network is the output of the 1st and 3rd layers and the original text encoding vector. The purpose is to perform feature enhancement, which can represent the features of text content at different levels, and help to build a richer and more robust text representation.
[0059] Step S303: input the multi-scale features of the text into at least two layers of feature encoding layers, perform multi-scale multi-head attention calculations in sequence, and obtain multi-scale fusion features.
[0060] In this embodiment, the multi-scale features of the text are fused with attention through the feature encoding layer, which can enhance the ability to capture information at different levels and scales.
[0061] In some optional implementations of this embodiment, at least two feature coding layers include a first coding layer and a second coding layer, the first coding layer includes a first multi-head attention sublayer, a first feature fusion sublayer, a first feedforward sublayer and a first residual connection sublayer, and the second coding layer includes a second multi-head attention sublayer, a second feature fusion sublayer, a second feedforward sublayer and a second residual connection sublayer. Multi-attention calculations are performed on multi-scale features of the text in sequence through different feature coding layers, so that text information flows in the attention calculations between different layers, so that the high layer can directly use the representation information of the low layer.
[0062] The step of inputting the multi-scale features of the text into at least two feature encoding layers and sequentially performing multi-scale multi-head attention calculations to obtain multi-scale fusion features specifically includes:
[0063] Perform multi-scale attention calculation on the multi-scale features of the text through the first multi-head attention sub-layer to obtain the first multi-scale attention feature;
[0064] Input the first multi-scale attention feature into the first feature fusion sublayer for multi-scale fusion to obtain the first fused feature;
[0065] Performing feature enhancement calculation on the first fused feature through the first feed-forward sublayer to obtain a first enhanced feature;
[0066] Performing residual connection on the text multi-scale feature and the first enhanced feature through the first residual connection sublayer to obtain a first splicing feature;
[0067] Input the first concatenated feature into the second multi-head attention sublayer, and perform multi-scale attention calculation on the first concatenated feature and the text multi-scale feature through the second multi-head attention sublayer to obtain a second multi-scale attention feature;
[0068] Input the second multi-scale attention feature into the second feature fusion sublayer for multi-scale fusion to obtain a second fused feature;
[0069] Performing feature enhancement calculation on the second fused feature through the second feed-forward sublayer to obtain a second enhanced feature;
[0070] The first concatenated feature and the second enhanced feature are residually connected through the second residual connection sublayer to obtain a multi-scale fusion feature.
[0071] In this embodiment, each multi-head attention sublayer can implement a multi-scale attention mechanism, and each head can focus on contextual information of different scales. For example, if the multi-head attention sublayer has 8 heads, that is, 8 self-attentions, then 4 heads focus on small scales, 2 heads focus on medium scales, and 2 heads focus on large scales. The self-attention of texts of different scales is calculated by different heads, and then the self-attention is merged through the feature fusion sublayer to obtain multi-head attention. Specifically, the process of multi-scale attention calculation by each multi-head attention sublayer is as follows:
[0072]
[0073] Among them, Q i =H i-1 W q ; K i =H i-1 W k ; V i =H i-1 W v ;Q i represents the query vector of the i-th head, K i represents the key vector of the i-th head, V i H represents the value vector of the i-th head; i represents the mask-self-attention output of the i-th head; d k Indicates the dimension of the key vector.
[0074] The feature fusion sublayer merges the self-attention and obtains the calculation formula of multi-head attention as follows:
[0075] MultiHead=Concat(head1,head2,…,head A )W0;
[0076] Among them, Concat represents the matrix concatenation function; W0 represents the parameter matrix when compressing each self-attention.
[0077] In this embodiment, the feedforward sublayer is a feedforward network layer, which is used to connect and enhance the fused features to prevent insufficient fitting; the residual connection sublayer adds the multi-scale features of the text and the output enhancement features of the previous layer to help the gradient flow and reduce the degradation problem in training.
[0078] In this embodiment, multi-scale attention is implemented within the feature encoding layer, and the multi-scale information is transmitted between feature encoding layers, so that the model can understand the input text more comprehensively and improve the model's ability to understand and process complex data structures.
[0079] Step S304, classify and calculate the multi-scale fusion features through the classification layer to obtain field classification information.
[0080] In this embodiment, the classification layer may adopt a CRF layer, or may adopt a design combining a fully connected layer and a softmax layer.
[0081] When the classification layer uses the CRF layer, the CRF layer can effectively mine the relationship between texts and set constraints to ensure the final prediction is valid. The constraints can be automatically learned by the CRF layer when training data. The CRF layer uses Viterbi decoding to predict the label corresponding to the sequence and uses joint probability to further optimize the overall classification effect.
[0082] When the classification layer uses a fully connected layer + softmax layer, the multi-scale fusion features of the fully connected layer are weighted summed and nonlinearly transformed, and then converted into probability distribution through the softmax layer, and the field classification results are determined according to the probability.
[0083] Step S305: Use the multi-scale fusion features as a text semantic feature vector, and output the text semantic feature vector and domain classification information.
[0084] In this embodiment, the multi-scale fusion features are output and can be used for subsequent text generation to improve the quality and accuracy of text generation.
[0085] By performing domain identification on query text data through domain classification models, we can better understand the context of the problem, collect and organize data in a more targeted manner, and thus generate text that is more in line with the situation and user needs, thereby improving the quality of text generation; by identifying the domain, we can more effectively allocate and utilize domain-specific resources and knowledge bases, improve text generation efficiency, text generation accuracy, and overall quality.
[0086] Step S203 , based on the domain classification information, a corresponding preset domain vocabulary is queried, and the text semantic feature vector is annotated according to the preset domain vocabulary to obtain an enhanced text semantic vector.
[0087] In this embodiment, the preset domain vocabulary is a domain-specific vocabulary pre-constructed for a specific domain task, and the vocabulary contains key terms in the domain. The construction of the preset domain vocabulary includes:
[0088] 1) Field terminology collection: Research and collect key terms and professional vocabulary in the field.
[0089] 2) Corpus analysis: Analyze large corpora in the domain to identify frequently occurring terms and phrases.
[0090] 3) Expert knowledge: Work with domain experts to ensure that the vocabulary contains all important professional terms and excludes irrelevant or erroneous terms.
[0091] 4) Word frequency statistics: Perform word frequency statistics on domain texts and select words with high frequency of occurrence to be included in the vocabulary.
[0092] 5) Word sense disambiguation: Since domain terms may be ambiguous, it is necessary to determine the meaning of words in the vocabulary in a specific domain.
[0093] 6) Contextual relevance: Consider the usage of words in a specific context and ensure that the words in the vocabulary are relevant in the domain.
[0094] 8) Special tags: Mark the words in the vocabulary, including necessary special tags, such as the beginning of a sentence <bos>,Finish <eos>, unknown words <unk>and fill <pad>.
[0095] 9) Vocabulary evaluation: Verify the effectiveness of the vocabulary through experiments and evaluate its impact on the performance of specific domain tasks. After the evaluation is completed, the domain vocabulary is obtained.
[0096] 10) Vocabulary Update: The field is dynamically evolving and the vocabulary needs to be updated regularly to include newly emerging terms.
[0097] In some optional implementations of this embodiment, the step of labeling the text semantic feature vector according to the preset domain vocabulary to obtain the enhanced text semantic vector includes:
[0098] Match the text in the query text data with the preset domain vocabulary to match the domain keywords;
[0099] Query the attribute features of domain keywords in the preset domain vocabulary and convert the attribute features into attribute encoding vectors;
[0100] The attribute encoding vector is concatenated with the text semantic feature vector to obtain an enhanced text semantic vector.
[0101] Among them, attribute features are the definitions, attributes and other related information corresponding to the domain keywords retrieved from the domain vocabulary, and the attributes include part of speech, word frequency, word importance, distribution, etc. After the attribute features are queried, NLP technology (such as BERT embedding layer) is used to convert the attribute features into attribute encoding vectors.
[0102] The method for concatenating the attribute encoding vector and the text semantic feature vector can be direct concatenation, or different weights can be assigned to the attribute encoding vector and the text semantic feature vector, and then the weighted sum can be calculated.
[0103] Feature enhancement through the vocabulary can effectively identify and enhance keywords in the corresponding field from the text, thereby improving the model's ability to understand and analyze professional texts.
[0104] Step S204, inputting the preprocessed text data, enhanced text semantic vectors and domain classification information into the trained text generation model for semantic prediction to generate target text.
[0105] In this embodiment, after the field classification, text generation is performed through a text generation model, which can perform semantic understanding more finely and accurately and generate professional corresponding text, thereby completing the semantic understanding and text generation of query text in a specific field.
[0106] It should be emphasized that in order to further ensure the privacy and security of the target text, the above target text can also be stored in a node of a blockchain.
[0107] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0108] In some optional implementations, the text generation model includes a knowledge layer, an embedding layer, a visible layer, an encoding layer and a BART decoding layer. The preprocessed text data, enhanced text semantic vectors and domain classification information are input into the trained text generation model, and the knowledge layer, embedding layer, visible layer, encoding layer and BART decoding layer are processed in sequence to generate a target text corresponding to the query text.
[0109] Among them, see Figure 4 As shown, the step of inputting the preprocessed text data, enhanced text semantic vector and domain classification information into the trained text generation model for semantic prediction to generate the target text includes:
[0110] Step S401, input the preprocessed text data and domain classification information into the knowledge layer, obtain the corresponding knowledge graph according to the domain classification information, and inject the knowledge in the knowledge graph into the text sentences of the preprocessed text data to form a sentence tree, and input the sentence tree into the embedding layer and the visible layer respectively.
[0111] A knowledge graph is a knowledge base in which data is integrated through a graph-structured data model or topology. It is usually a semantic relationship graph that represents entities and relationships, and is stored in the form of a <head entity, relationship, tail entity> triple. The head and tail entities represent a specific thing that exists in the real world, and the relationship expresses a certain semantic association between entities. For example, in the knowledge graph in the medical field, the triples include <diabetes, manifested as, polyuria>, <aspirin, used to treat, heart disease>, etc.
[0112] The knowledge layer is responsible for injecting the knowledge in the knowledge graph into the preprocessed text data to form a sentence tree. For example, for each input preprocessed text data text sentence s = {w1, w2, w3, ..., w n}, first obtain the named entity from the sentence, then query the corresponding relationship and value (tail entity) of the named entity in the knowledge graph to form a triple of <head entity, relationship, value>, and then return this triple to the corresponding position of the sentence to form a tree structure, called the Sentence Tree. The Sentence Tree completes the background information of the sentence and solves the problem that the word vector deviates from the core semantics due to the lack of knowledge background in a single sentence.
[0113] In this embodiment, forming a sentence tree is divided into two steps: knowledge query (K-Query) and knowledge injection (K-Inject).
[0114] The steps of injecting knowledge in the knowledge graph into the text sentences of the preprocessed text data to form a sentence tree include:
[0115] Call the knowledge query function of the knowledge layer to identify all entities in the preprocessed text data and query the triples corresponding to each entity in the knowledge graph;
[0116] The similarity between the triples and the preprocessed text data is calculated through the attention mechanism to obtain the relevant triples;
[0117] The knowledge injection function of the knowledge layer is called to embed the relevant triples into the corresponding positions of the preprocessed text data to obtain the sentence tree.
[0118] K-Query is responsible for querying the relationship and value corresponding to each entity in each text sentence in the preprocessed text data from the knowledge graph, that is, the triple. The specific query process is as follows:
[0119] E = K_Query(s, K);
[0120] Among them, the function K_Query represents the query of the text sentence s on the knowledge graph K to obtain the triple set E = {(w i , r i0 , w i0 ),……,(w i , r ik , w ik )}.
[0121] Then, the attention mechanism is used to evaluate the relevance of each triple to the input preprocessed text data, and the triples that are highly relevant to the context of the preprocessed text data are selected. The similarity between entities and relations in the context embedding space is calculated to select the triplets with high relevance. The similarity calculation can be implemented by using cosine similarity, Euclidean distance or other similarity measurement methods.
[0122] K-Inject is responsible for embedding the triple set E into the corresponding position in the text sentence s to form a sentence tree. Each triple constitutes a branch. The matrix sentence tree output by the knowledge layer is: t = {w1, w2, w3, ..., w i (r i0 , w i0 ), ..., w i (r ik , w ik ),……,w n }.
[0123] In this embodiment, by calculating the similarity between triples and preprocessed text data through the attention mechanism, unimportant triples can be filtered out, knowledge noise can be reduced, and the accuracy and relevance in the knowledge graph injection process can be improved, thereby improving the quality and accuracy of text generation.
[0124] Step S402, position embedding is performed on the sentence tree through an embedding layer to obtain a text embedding vector.
[0125] The sentence tree cannot be directly used as a sequence input. The sentence tree is converted into a text sequence through the embedding layer. The embedding layer includes the token embedding layer, the soft-position embedding layer, and the segment embedding layer. The token embedding layer maps each token in the sentence into a vector representation with a dimension of H. There is a special token [CLS] at the beginning of each sentence, which is mainly for sentence classification. The soft-position embedding layer uses soft positions to encode embedded values and relationships, which is different from the position encoding of entities. The segment embedding layer is used to distinguish between two sentence fragments.
[0126] Specifically, the sentence tree is input into the embedding layer for segment embedding operation, soft position embedding operation and word embedding operation respectively to obtain the corresponding sentence encoding vector, position encoding vector and word encoding vector; the sentence encoding vector, position encoding vector and word encoding vector are summed to obtain the text embedding vector.
[0127] Through the token embedding layer, each word in the sentence tree is embedded to obtain the sentence encoding vector; through the soft-position embedding layer, each word in the sentence tree is soft-position embedded to obtain the position encoding vector, which retains the main position information of the sentence; through the segment embedding layer, each word in the sentence tree is embedded to obtain the word encoding vector, and the sentence encoding vector, position encoding vector and word encoding vector are summed to obtain the text embedding vector, where the text embedding vector retains the structural information of the tree structure, which can strengthen the feature representation and thus better obtain the semantic features of the text.
[0128] Step S403: construct a text visibility matrix of the sentence tree through the visible layer.
[0129] Since the triples in the sentence tree may affect the meaning of the text sentences in the original preprocessed text data, in order to prevent the influence of knowledge noise on the sentences, a text visible matrix M is constructed to limit each word to only see the context and knowledge related to itself.
[0130] Assume that the two tokens are w i and w j , M ij = 0, indicating that in the text visible matrix w i to w j It is visible, M ij = -∞, indicating that in the text visible matrix w i to w j is invisible.
[0131] Step S404: input the enhanced text semantic vector, text embedding vector and text visibility matrix into the encoding layer for attention calculation, and output the attention enhanced feature vector.
[0132] In this embodiment, the use of the encoding layer can limit the visible area of the self-attention mechanism, thereby capturing the deep bidirectional structure in the text sentence. The encoding layer is composed of multiple mask-self-attention layers, and the text visible matrix M is added on the basis of mask-self-attention to perform attention calculation on the enhanced text semantic vector and text embedding vector.
[0133] Furthermore, the step of inputting the enhanced text semantic vector, the text embedding vector and the text visibility matrix into the encoding layer for attention calculation and outputting the attention enhanced feature vector includes:
[0134] Determine a query vector parameter matrix, a key vector parameter matrix, and a value vector parameter matrix of the encoding layer;
[0135] Calculate self-attention based on the query vector parameter matrix, key vector parameter matrix, value vector parameter matrix, enhanced text semantic vector, text embedding vector and text visibility matrix;
[0136] Multi-head attention calculation is performed based on self-attention to obtain the attention enhanced feature vector.
[0137] The result information of the sentence tree is obtained through the text visibility matrix, and the attention calculation is performed based on the text visibility matrix, which achieves the purpose of not adding noise while embedding knowledge and ensures the accuracy of the output attention enhanced feature vector.
[0138] Step S405, performing autoregression on the attention enhancement feature vector through the BART decoding layer to obtain the target text.
[0139] In this embodiment, the BART decoding layer uses BART's decoder, which is an autoregressive model. When generating text, each step is based on the previously generated text. BART's decoder also uses a multi-head self-attention mechanism, allowing the decoder to consider the entire input sequence when generating each word.
[0140] By generating text through a text generation model and introducing knowledge graphs, the text semantics is enriched, the problems of inconsistent encoding space of diversified word vectors and deviation of sentences from core semantics are avoided, the effect of text information extraction is improved, and the quality of text generation is improved.
[0141] Through the domain classification model, the present application can perform domain identification on the query text, identify it according to the domain it belongs to, and improve the accuracy of text generation; pre-process the text data, and annotate the text semantic feature vector according to the preset domain vocabulary, strengthen the attention to the text keywords, improve the quality of the text to be identified, and improve the accuracy of text generation; generate text through the text generation model, which can fully understand the text semantics, thereby improving the efficiency and accuracy of text generation.
[0142] In some optional implementations, before the step of inputting the preprocessed text data, the enhanced text semantic vector and the domain classification information into the trained text generation model for semantic prediction, the method further includes:
[0143] Obtain a historical question-answering text dataset, where the historical question-answering text dataset carries real generated text labels;
[0144] Preprocess the historical question-answer text dataset to obtain a preprocessed dataset;
[0145] Perform domain classification annotation and expand sample data on the question and answer text data in the preprocessed data set to obtain an expanded text data set;
[0146] The expanded text dataset is randomly divided into a training set and a validation set, and the training set is input into the pre-built neural network model to obtain the predicted generated text;
[0147] Calculate the loss value between the predicted generated text and the actual generated text label based on the preset loss function;
[0148] Adjust the model parameters of the neural network model according to the loss value, continue iterative training until convergence, and obtain the model to be verified;
[0149] The verification set is input into the model to be verified to obtain the verification result. When the verification result meets the preset conditions, the model to be verified is determined to be the final text generation model.
[0150] Among them, historical question-and-answer text datasets can be obtained through public datasets, professional platforms, open source libraries, crawling with crawler technology, etc. The data in the historical question-and-answer text dataset is preprocessed, including data cleaning and text alignment. Data cleaning includes deduplication, special symbol processing, stop word removal, missing text processing, abnormal text processing, error text correction, and text normalization.
[0151] The question and answer text data in the preprocessed data set is divided into corresponding fields, and then the field classification and annotation are performed. The expanded sample data is to expand the question and answer text data in the preprocessed data set. The expansion method includes EDA data enhancement. EDA data enhancement is to perform synonym replacement, random insertion, random exchange, random deletion, etc. on the question and answer text data.
[0152] The expanded text dataset after domain classification annotation and sample data expansion can also be used to train domain classification models.
[0153] The expanded text data set is randomly divided into a training set and a validation set according to a preset ratio. The preset ratio can be set according to actual conditions, for example, training set: validation set = 8:2.
[0154] The training set is input into the pre-built neural network model, which includes a knowledge layer, an embedding layer, a visible layer, an encoding layer, and a BART decoding layer, and outputs the predicted generated text.
[0155] In this embodiment, the preset loss function may be a cross entropy loss function, a sequence generation loss function, etc. The model parameters are adjusted according to the loss value, and iterative training is continued until the model converges. The convergence condition may be that the loss value does not change significantly, or the number of iterations reaches a preset number.
[0156] The verification set is input into the model to be verified to obtain the verification generated text. The prediction accuracy of the model is calculated based on the verification generated text, and the prediction accuracy is used as the verification result.
[0157] When the prediction accuracy is greater than or equal to the preset threshold, the model to be verified is output as the final text generation model; if the prediction accuracy is less than the preset threshold, it means that the prediction accuracy of the model is not high, and it is necessary to increase the number of samples, or modify the model parameters and retrain to improve the prediction accuracy.
[0158] By preprocessing the data, annotating domain classifications, and expanding sample data, the size of the data set is increased, the quality of data preparation is effectively improved, the robustness of model learning and vocabulary prediction can be increased, the model's anti-interference ability and generalization ability can be enhanced, and the quality of the generated text can be improved.
[0159] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0160] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0161] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0162] Further references Figure 5 , as a response to the above Figure 2 The present application provides an embodiment of a text generation device combining domain knowledge, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0163] like Figure 5 As shown, the text generation device 500 combined with domain knowledge described in this embodiment includes: a preprocessing module 501, a domain classification module 502, a labeling module 503 and a text generation module 504.
[0164] in:
[0165] The preprocessing module 501 is used to obtain query text data, preprocess the query text data, and obtain preprocessed text data;
[0166] The domain classification module 502 is used to input the pre-processed text data into a trained domain classification model to obtain a text semantic feature vector and domain classification information;
[0167] The annotation module 503 is used to query the corresponding preset domain vocabulary based on the domain classification information, and annotate the text semantic feature vector according to the preset domain vocabulary to obtain an enhanced text semantic vector;
[0168] The text generation module 504 is used to input the pre-processed text data, the enhanced text semantic vector and the field classification information into the trained text generation model to perform semantic prediction and generate the target text.
[0169] It should be emphasized that in order to further ensure the privacy and security of the target text, the above target text can also be stored in a node of a blockchain.
[0170] Based on the above-mentioned text generation device 500 combined with domain knowledge, through the domain classification model, it is possible to perform domain identification on the query text, identify it according to the domain it belongs to, and improve the accuracy of text generation; pre-process the text data, and annotate the text semantic feature vector according to the preset domain vocabulary, strengthen the attention to the text keywords, improve the quality of the text to be identified, and improve the accuracy of text generation; generate text through the text generation model, which can fully understand the text semantics, thereby improving the efficiency and accuracy of text generation.
[0171] In some optional implementations, the domain classification model includes an embedding layer, a multi-scale feature extraction layer, at least two feature encoding layers and a classification layer, and the domain classification module 502 includes an embedding submodule, a multi-scale feature extraction submodule, a multi-scale fusion submodule, a classification submodule and an output submodule, wherein:
[0172] An embedding submodule, used for inputting the preprocessed text data into the embedding layer to perform position embedding, word embedding and character embedding to obtain a text encoding vector;
[0173] A multi-scale feature extraction submodule, used for performing feature extraction on the text encoding vector through the multi-scale feature extraction layer to obtain text multi-scale features;
[0174] A multi-scale fusion submodule, used for inputting the multi-scale features of the text into the at least two feature encoding layers, performing multi-scale multi-head attention calculations in sequence, and obtaining multi-scale fusion features;
[0175] A classification submodule, used to perform classification calculation on the multi-scale fusion features through the classification layer to obtain field classification information;
[0176] The output submodule is used to use the multi-scale fusion feature as a text semantic feature vector, and output the text semantic feature vector and the field classification information.
[0177] By performing domain identification on query text data through domain classification models, we can better understand the context of the problem, collect and organize data in a more targeted manner, and thus generate text that is more in line with the situation and user needs, thereby improving the quality of text generation; by identifying the domain, we can more effectively allocate and utilize domain-specific resources and knowledge bases, improve text generation efficiency, text generation accuracy, and overall quality.
[0178] In some optional implementations of this embodiment, the at least two feature coding layers include a first coding layer and a second coding layer, the first coding layer includes a first multi-head attention sublayer, a first feature fusion sublayer, a first feedforward sublayer and a first residual connection sublayer, and the second coding layer includes a second multi-head attention sublayer, a second feature fusion sublayer, a second feedforward sublayer and a second residual connection sublayer; the multi-scale fusion submodule includes a first attention unit, a first fusion unit, a first feedforward unit, a first residual unit, a second attention unit, a second fusion unit, a second feedforward unit and a second residual unit, wherein:
[0179] A first attention unit, configured to perform multi-scale attention calculation on the multi-scale feature of the text through the first multi-head attention sub-layer to obtain a first multi-scale attention feature;
[0180] A first fusion unit, configured to input the first multi-scale attention feature into the first feature fusion sublayer for multi-scale fusion to obtain a first fused feature;
[0181] A first feedforward unit, configured to perform feature enhancement calculation on the first fused feature through the first feedforward sublayer to obtain a first enhanced feature;
[0182] A first residual unit, configured to perform a residual connection on the text multi-scale feature and the first enhanced feature through the first residual connection sublayer to obtain a first splicing feature;
[0183] A second attention unit is used to input the first splicing feature into the second multi-head attention sublayer, and perform multi-scale attention calculation on the first splicing feature and the text multi-scale feature through the second multi-head attention sublayer to obtain a second multi-scale attention feature;
[0184] A second fusion unit, configured to input the second multi-scale attention feature into the second feature fusion sublayer for multi-scale fusion to obtain a second fused feature;
[0185] A second feed-forward unit, configured to perform feature enhancement calculation on the second fused feature through the second feed-forward sublayer to obtain a second enhanced feature;
[0186] The second residual unit is used to perform residual connection on the first splicing feature and the second enhanced feature through the second residual connection sublayer to obtain a multi-scale fusion feature.
[0187] Implementing multi-scale attention within the feature encoding layer and transferring this multi-scale information between feature encoding layers enables the model to understand the input text more comprehensively and improves the model's ability to understand and process complex data structures.
[0188] In some optional implementations, the labeling module 503 includes a matching submodule, a vector conversion submodule, and a splicing submodule, wherein:
[0189] A matching submodule, used to match the text in the query text data with the preset domain vocabulary to match domain keywords;
[0190] A vector conversion submodule, used to query the attribute features of the domain keyword in the preset domain vocabulary, and convert the attribute features into an attribute coding vector;
[0191] The concatenation submodule is used to concatenate the attribute encoding vector with the text semantic feature vector to obtain an enhanced text semantic vector.
[0192] Feature enhancement through the vocabulary can effectively identify and enhance keywords in the corresponding field from the text, thereby improving the model's ability to understand and analyze professional texts.
[0193] In some optional implementations, the text generation model includes a knowledge layer, an embedding layer, a visible layer, an encoding layer, and a BART decoding layer; the text generation module 504 includes:
[0194] An injection submodule, for inputting the preprocessed text data and the domain classification information into the knowledge layer, acquiring a corresponding knowledge graph according to the domain classification information, and injecting the knowledge in the knowledge graph into the text sentences of the preprocessed text data to form a sentence tree, and inputting the sentence tree into the embedding layer and the visible layer respectively;
[0195] A position embedding submodule, used for performing position embedding on the sentence tree through the embedding layer to obtain a text embedding vector;
[0196] A matrix construction submodule, used for constructing a text visible matrix of the sentence tree through the visible layer;
[0197] An attention calculation submodule, used for inputting the enhanced text semantic vector, the text embedding vector and the text visibility matrix into the encoding layer to perform attention calculation, and output an attention enhancement feature vector;
[0198] A generation submodule is used to perform autoregression generation on the attention-enhanced feature vector through the BART decoding layer to obtain a target text.
[0199] By generating text through a text generation model and introducing knowledge graphs, the text semantics is enriched, the problems of inconsistent encoding space of diversified word vectors and deviation of sentences from core semantics are avoided, the effect of text information extraction is improved, and the quality of text generation is improved.
[0200] In some optional implementations of this embodiment, the injection submodule includes:
[0201] A query unit, used to call the knowledge query function of the knowledge layer, identify all entities in the preprocessed text data, and query the triples corresponding to each of the entities in the knowledge graph;
[0202] An attention unit, used for calculating the similarity between the triple and the preprocessed text data through an attention mechanism to obtain a related triple;
[0203] The injection unit is used to call the knowledge injection function of the knowledge layer to embed the relevant triples into the positions corresponding to the preprocessed text data to obtain a sentence tree.
[0204] By calculating the similarity between triples and preprocessed text data through the attention mechanism, unimportant triplets can be filtered out, knowledge noise can be reduced, and the accuracy and relevance in the knowledge graph injection process can be improved, thereby improving the quality and accuracy of text generation.
[0205] In some optional implementations, the text generation device 500 incorporating domain knowledge further includes a training module for:
[0206] Obtain a historical question-and-answer text dataset, wherein the historical question-and-answer text dataset carries a real generated text label;
[0207] Preprocessing the historical question-and-answer text dataset to obtain a preprocessed dataset;
[0208] Performing domain classification annotation and expanding sample data on the question and answer text data in the preprocessed data set to obtain an expanded text data set;
[0209] The expanded text data set is randomly divided into a training set and a validation set, and the training set is input into a pre-built neural network model to obtain predicted generated text;
[0210] Calculate the loss value between the predicted generated text and the real generated text label based on a preset loss function;
[0211] Adjusting the model parameters of the neural network model according to the loss value, continuing iterative training until convergence, and obtaining a model to be verified;
[0212] The verification set is input into the model to be verified to obtain a verification result, and when the verification result meets a preset condition, the model to be verified is determined to be the final text generation model.
[0213] By preprocessing the data, annotating domain classifications, and expanding sample data, the size of the data set is increased, the quality of data preparation is effectively improved, the robustness of model learning and vocabulary prediction can be increased, the model's anti-interference ability and generalization ability can be enhanced, and the quality of the generated text can be improved.
[0214] To solve the above technical problems, the present application also provides a computer device. Figure 6 , Figure 6 This is a basic structural block diagram of the computer device in this embodiment.
[0215] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 6 with components 61-63, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0216] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0217] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 61 can be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 can also be an external storage device of the computer device 6, such as a plug-in hard disk equipped on the computer device 6, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 61 can also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as computer-readable instructions of a text generation method combined with domain knowledge, etc. In addition, the memory 61 can also be used to temporarily store various types of data that have been output or are to be output.
[0218] The processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run the computer-readable instructions stored in the memory 61 or process data, such as computer-readable instructions for running the text generation method combined with domain knowledge.
[0219] The network interface 63 may include a wireless network interface or a wired network interface. The network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
[0220] This embodiment implements the steps of the text generation method combined with domain knowledge as in the above embodiment when the processor executes computer-readable instructions stored in the memory. Through the domain classification model, the query text can be identified according to the domain to which it belongs, thereby improving the accuracy of text generation; the text data is preprocessed, and the text semantic feature vector is annotated according to the preset domain vocabulary, so as to strengthen the attention to the text keywords, improve the quality of the text to be identified, and improve the accuracy of text generation; the text is generated through the text generation model, so that the text semantics can be fully understood, thereby improving the efficiency and accuracy of text generation.
[0221] The present application also provides another implementation mode, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor, so that the at least one processor executes the steps of the text generation method combined with domain knowledge as described above, and through the domain classification model, the query text can be identified according to the domain to which it belongs, thereby improving the accuracy of text generation; preprocessing the text data, and annotating the text semantic feature vector according to the preset domain vocabulary, strengthening the attention to the text keywords, improving the quality of the text to be identified, and improving the accuracy of text generation; generating the text through the text generation model, which can fully understand the text semantics, thereby improving the efficiency and accuracy of text generation.
[0222] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0223] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.< / pad> < / unk> < / eos> < / bos>
Claims
1. A text generation method combining domain knowledge, characterized in that: The steps include: Acquire query text data, and preprocess the query text data to obtain preprocessed text data; Inputting the preprocessed text data into a trained domain classification model to obtain a text semantic feature vector and domain classification information; Based on the domain classification information, a corresponding preset domain vocabulary is queried, and the text semantic feature vector is annotated according to the preset domain vocabulary to obtain an enhanced text semantic vector; The preprocessed text data, the enhanced text semantic vector and the domain classification information are input into a trained text generation model for semantic prediction to generate a target text.
2. The method for generating text in combination with domain knowledge according to claim 1, characterized in that: The domain classification model includes an embedding layer, a multi-scale feature extraction layer, at least two feature encoding layers and a classification layer. The step of inputting the pre-processed text data into the trained domain classification model to obtain a text semantic feature vector and domain classification information includes: Inputting the preprocessed text data into the embedding layer for position embedding, word embedding and character embedding to obtain a text encoding vector; Performing feature extraction on the text encoding vector through the multi-scale feature extraction layer to obtain text multi-scale features; Inputting the multi-scale features of the text into the at least two feature encoding layers, and sequentially performing multi-scale multi-head attention calculations to obtain multi-scale fusion features; Classify and calculate the multi-scale fusion features through the classification layer to obtain field classification information; The multi-scale fusion feature is used as a text semantic feature vector, and the text semantic feature vector and the field classification information are output.
3. The method for generating text in combination with domain knowledge according to claim 2, characterized in that: The at least two feature coding layers include a first coding layer and a second coding layer, the first coding layer includes a first multi-head attention sublayer, a first feature fusion sublayer, a first feedforward sublayer and a first residual connection sublayer, and the second coding layer includes a second multi-head attention sublayer, a second feature fusion sublayer, a second feedforward sublayer and a second residual connection sublayer; the step of inputting the multi-scale features of the text into the at least two feature coding layers, performing multi-scale multi-head attention calculations in sequence, and obtaining multi-scale fusion features specifically includes: Performing multi-scale attention calculation on the multi-scale feature of the text through the first multi-head attention sub-layer to obtain a first multi-scale attention feature; Inputting the first multi-scale attention feature into the first feature fusion sublayer for multi-scale fusion to obtain a first fused feature; Performing feature enhancement calculation on the first fused feature through the first feed-forward sublayer to obtain a first enhanced feature; Performing a residual connection on the text multi-scale feature and the first enhanced feature through the first residual connection sublayer to obtain a first splicing feature; Inputting the first concatenation feature into the second multi-head attention sublayer, and performing multi-scale attention calculation on the first concatenation feature and the text multi-scale feature through the second multi-head attention sublayer to obtain a second multi-scale attention feature; Inputting the second multi-scale attention feature into the second feature fusion sublayer for multi-scale fusion to obtain a second fused feature; Performing feature enhancement calculation on the second fused feature through the second feed-forward sublayer to obtain a second enhanced feature; The first splicing feature and the second enhanced feature are residually connected through the second residual connection sublayer to obtain a multi-scale fusion feature.
4. The method for generating text in combination with domain knowledge according to claim 1, characterized in that: The step of labeling the text semantic feature vector according to the preset domain vocabulary to obtain an enhanced text semantic vector comprises: Matching the text in the query text data with the preset domain vocabulary to match domain keywords; Querying the attribute features of the domain keyword in the preset domain vocabulary, and converting the attribute features into an attribute coding vector; The attribute encoding vector is concatenated with the text semantic feature vector to obtain an enhanced text semantic vector.
5. The method for generating text in combination with domain knowledge according to claim 1, characterized in that: The text generation model includes a knowledge layer, an embedding layer, a visible layer, an encoding layer and a BART decoding layer; the step of inputting the preprocessed text data, the enhanced text semantic vector and the field classification information into the trained text generation model for semantic prediction to generate the target text includes: Input the preprocessed text data and the domain classification information into the knowledge layer, obtain a corresponding knowledge graph according to the domain classification information, and inject the knowledge in the knowledge graph into the text sentences of the preprocessed text data to form a sentence tree, and input the sentence tree into the embedding layer and the visible layer respectively; Performing position embedding on the sentence tree through the embedding layer to obtain a text embedding vector; Constructing a text visible matrix of the sentence tree through the visible layer; Inputting the enhanced text semantic vector, the text embedding vector and the text visibility matrix into the encoding layer for attention calculation, and outputting an attention enhanced feature vector; The attention-enhanced feature vector is autoregressively generated through the BART decoding layer to obtain the target text.
6. The method for generating text in combination with domain knowledge according to claim 5, characterized in that: The step of injecting the knowledge in the knowledge graph into the text sentences of the preprocessed text data to form a sentence tree comprises: Calling the knowledge query function of the knowledge layer to identify all entities in the preprocessed text data, and querying the triples corresponding to each of the entities in the knowledge graph; Calculate the similarity between the triple and the preprocessed text data through an attention mechanism to obtain a related triple; The knowledge injection function of the knowledge layer is called to embed the relevant triples into the positions corresponding to the preprocessed text data to obtain a sentence tree.
7. The method for generating text in combination with domain knowledge according to claim 1, characterized in that: Before the step of inputting the preprocessed text data, the enhanced text semantic vector and the field classification information into the trained text generation model for semantic prediction, the step further includes: Obtain a historical question-and-answer text dataset, wherein the historical question-and-answer text dataset carries a real generated text label; Preprocessing the historical question-and-answer text dataset to obtain a preprocessed dataset; Performing domain classification annotation and expanding sample data on the question and answer text data in the preprocessed data set to obtain an expanded text data set; The expanded text data set is randomly divided into a training set and a validation set, and the training set is input into a pre-built neural network model to obtain predicted generated text; Calculate the loss value between the predicted generated text and the real generated text label based on a preset loss function; Adjusting the model parameters of the neural network model according to the loss value, continuing iterative training until convergence, and obtaining a model to be verified; The verification set is input into the model to be verified to obtain a verification result, and when the verification result meets a preset condition, the model to be verified is determined to be the final text generation model.
8. A text generation device combining domain knowledge, characterized in that: include: A preprocessing module, used to obtain query text data, preprocess the query text data, and obtain preprocessed text data; A domain classification module, used to input the pre-processed text data into a trained domain classification model to obtain a text semantic feature vector and domain classification information; A labeling module, used for querying a corresponding preset domain vocabulary based on the domain classification information, labeling the text semantic feature vector according to the preset domain vocabulary, and obtaining an enhanced text semantic vector; The text generation module is used to input the pre-processed text data, the enhanced text semantic vector and the field classification information into a trained text generation model for semantic prediction to generate a target text.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the method for generating text in combination with domain knowledge as claimed in any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for generating text in combination with domain knowledge according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Scientific and technical literature semantic novelty search method and system based on large-scale pre-training model
CN121301542A
