A bart-based multi-task semantic parsing model
By using a BART-based multi-task semantic parsing model, natural language is directly converted into the knowledge graph query language SPARQL, which solves the problem of error accumulation in traditional multi-step semantic parsing and achieves high-efficiency question answering accuracy and domain recognition.
Patent Information
- Application Number
- CN202210936486.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-05
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2042-08-05
AI Technical Summary
Traditional knowledge graph question answering algorithms employ a multi-step pipeline approach for semantic parsing, leading to error accumulation and performance degradation, especially when designing multiple entities and relationships.
A BART-based multi-task semantic parsing model is adopted, including a word embedding layer, a BART encoding layer, a domain classifier, a BART decoding layer, a probabilistic decoder, a SPARQL decoder, and a syntax checker. Through word embedding, bidirectional multi-head attention mechanism, self-attention mechanism, and language model, natural language is directly converted into SPARQL query statements, and syntax checking is performed to improve accuracy.
It simplifies the question-and-answer process, reduces error accumulation, and improves the accuracy of question-and-answer, especially performing well in domain recognition and knowledge base queries.
Smart Images

Figure CN115309879B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of natural language processing, and particularly relates to a multi-task semantic parsing model based on BART. BACKGROUND
[0002] In traditional knowledge graph question answering, a semantic parsing algorithm adopts a multi-step pipeline mode, first identifies the intention of a user and the type of a question, then performs entity relation extraction, and finally fills slots according to a pre-defined query template to form a complete SPARQL query statement to retrieve a database and return an answer to the user. The multi-step pipeline semantic parsing mode divides a task into different stages, decomposes the task, is flexible in operation, and has strong interpretability, but the cascading decomposition of the task leads to accumulation and amplification of errors; when multiple entities and relations or reasoning question answering are designed, the model performs poorly, thereby affecting the performance of the question answering task. SUMMARY
[0003] To solve the above problems, the application provides a multi-task semantic parsing model based on BART, which comprises a word embedding layer, a BART encoding layer, a domain classifier, a BART decoding layer, a probability decoder, a SPARQL decoder and a syntax checker; the word embedding layer converts each character in an input question into a vector representation and inputs the vector representation into the BART encoding layer; the BART encoding layer learns semantic information of a deep character vector and encodes the semantic information, and inputs a vector representation of a hidden layer of the last layer of encoding into the domain classifier and the BART decoding layer respectively; the domain classifier performs text classification on the vector representation of the last layer of the hidden layer to obtain a domain to which the question belongs; the BART decoding layer generates complete decoding information through a language model according to question encoding information and previous decoding information; the probability decoder module performs semantic information enhancement decoding on a vector output by the last layer of the BART decoder, and inputs the decoding information into the SPARQL decoder module; the SPARQL decoder module cyclically generates a SPARQL query statement according to a decoding strategy and domain information, and inputs the statement into the syntax checker module; and the syntax checker is used to check a syntax error of the SPARQL query statement.
[0004] In a possible design, the word embedding layer converts each character in an input question into a vector representation, specifically as follows:
[0005] Input data is composed of [CLS], a question, [SEP] characters by splicing, the maximum length of the data is 512 characters, and if the length is too long, the data is truncated, and if the length is too short, the data is filled with [PAD] characters;
[0006] Special characters "?x", "?y" and special characters in the SPARQL syntax are added in the dictionary table;
[0007] The vector representation of each input character is obtained by adding the word embedding and the position embedding, and the calculation formula is as follows:
[0008] E embedding = E word + E position (1)
[0009] Wherein, E word is the word embedding vector of the character, E position is the position embedding vector, and E embedding is the vector representation of the input character.
[0010] In one possible design, the BART uses a standard Transformer model, including 6 layers of Transformer encoder and 6 layers of Transformer decoder, the BART encoding layer learns the features in different subspaces through bidirectional multi-head attention mechanism, and captures deeper semantic information, specifically:
[0011] The multi-head attention sublayer of the Transformer encoder adopts the self-attention mechanism, creates three vectors Query, Key and Value for each word to calculate the self-attention score, and the calculation formula is as follows:
[0012]
[0013] head_i=Attention(QW i Q , KW i K , VW i V ) (3)
[0014] Multihead(Q, K, V)=Concat(head1, head2, …, head h )W O (4)
[0015] Wherein, Softmax is a logistic regression function, the Attention function calculates the self-attention by using the Softmax function, and a plurality of self-attention head_i is calculated by combining different QW i Q , KW i K , VW i V Multihead(Q, K, V) connects multiple self-attentions by using the Concat function to combine into multi-head attention;
[0016] Layer normalization of the Transformer encoder is performed to prevent covariance shift problems and residual connections are used to prevent gradient vanishing, and the calculation formula is as follows:
[0017] SubLayer=Layer_Normalization(x+(sublayer(x))) (5)
[0018] x is the current layer double-headed attention operation result, Sublayer(x) is the double-headed attention operation result of the next layer, the two operation results are directly added to perform residual connection, and layer normalization is performed through Layer_Normalization;
[0019] Through the feedforward network layer and the nonlinear activation function ReLU, the nonlinear fitting effect of the network is improved.
[0020] The calculation result is input into the next layer of the Transformer encoder, and a total of 6 layers of Transformer encoders are executed, and the weights are not shared between layers.
[0021] In one possible design, the domain classifier takes the hidden layer vector representation of the last layer of the BART encoding layer as input of the layer, and outputs the domain to which the problem belongs through text classification.
[0022] In one possible design, the BART encoding layer generates SPARQL text from left to right through a language model according to the problem encoding information and the previous decoding information, specifically:
[0023] The multi-head attention sublayer of the Transformer decoder adopts a self-attention mechanism, creates Query, Key and Value three vectors for each character vector to calculate self-attention scores, and the calculation formula is shown in the above formula (2), formula (3) and formula (4);
[0024] The upper triangular MASK matrix is used to mask the subsequent information, so that each word can only focus on the previous information, preventing the model from using future input words during training.
[0025] Layer normalization of the Transformer decoder is performed to prevent covariance shift problems and residual connections are used to prevent gradient vanishing, and the calculation formula is as follows:
[0026] According to the problem encoding information and the previous decoding information, SPARQL text is generated from left to right through a language model, and the language model calculation is as follows:
[0027] p(y1,y2,y3,...,y n )=p(y1|Eo p(y2|E o , y1)p(y3|E o , y1, y2)...p(y n |E o , y1,..., y n-1 ) (6)
[0028] The above formula is a Markov model calculation formula, E o represents the starting character, and the formula calculates the probability of the occurrence of subsequent characters from the 1st character, p(y i |E o , y1,..., y i-1 ) represents the probability that the next character is y o when E i , y i-1 to y i occurs.
[0029] In a possible design, the probability decoder fuses a vector output by a last layer of a BART encoding layer and a classification label [CLS] vector of the last layer of the BART encoding layer, implements semantic information enhanced decoding, and calculates a probability of each word in a word table.
[0030] In a possible design, the SPARQL decoder selects a word from a dictionary distribution as a result generated at each time according to a decoding strategy and domain information, and completes SPARQL query statement generation.
[0031] In a possible design, the grammar checker corrects simple grammar errors output by the model to improve the accuracy of the question and answer.
[0032] The second aspect of the present application also provides a multi-task semantic parsing device applied to a knowledge graph question and answer system, the device comprising at least one processor and at least one memory, the processor and the memory being coupled; the memory stores the computer program of the parsing model according to the first aspect; and the processor executes the computer program stored in the memory, so that the device realizes the multi-task semantic parsing function.
[0033] The third aspect of the present application also provides a computer readable storage medium, the computer readable storage medium stores the program or instructions of the parsing model according to the first aspect, and the program or instructions are executed by the processor, so that the computer realizes the multi-task semantic parsing function.
[0034] Beneficial effects: the application provides a BART-based multi-task semantic parsing model, which can directly convert natural language into knowledge graph query language SPARQL, simplify the question and answer steps to reduce error accumulation, and identify the domain of the question, query the corresponding professional domain knowledge base according to the domain, thereby improving the accuracy of question and answer. The BART model is based on the Encoder-Decoder model architecture of the Transformer, increases the text noise through word deletion, sentence permutation transformation, document rotation, word filling and other means, and maps the noisy input decoding to the original text, obtains the sequence-to-sequence encoder through training, and achieves better results in generation tasks such as question and answer, translation, and summary. BRIEF DESCRIPTION OF DRAWINGS
[0035] Figure 1 It is a BART-based multi-task semantic parsing model architecture of the application.
[0036] Figure 2 It is a simple structure diagram of the multi-task semantic parsing device applied in the knowledge graph question and answer system of the application. DETAILED DESCRIPTION
[0037] The knowledge graph question and answer system can generate corresponding SPARQL (a kind of database query language) query statements according to the natural language question input by the user and query in the knowledge base, so as to obtain the answer. The question and answer system semantic parsing algorithm converts the user question into a knowledge graph query statement through different subtasks, which can be used as a text translation task in the NLP field, automatically infers the corresponding relationship between multiple entities according to the user question, directly outputs the SPARQL statement corresponding to the user question through text generation technology, thereby reducing the question and answer steps. The BART model (an abbreviation of Bidirectional and Auto-Regressive Transformers, which is a sequence-to-sequence model) is based on the Encoder-Decoder model architecture of the Transformer, increases the text noise through word deletion, sentence permutation transformation, document rotation, word filling and other means, and maps the noisy input decoding to the original text, obtains the sequence-to-sequence encoder through training, and achieves better results in generation tasks such as question and answer, translation, and summary.
[0038] The application can directly convert natural language into knowledge graph query language SPARQL, simplify the question and answer steps to reduce error accumulation, identify the domain of the question, query the corresponding professional domain knowledge base according to the domain, and improve the accuracy of question and answer.
[0039] The application will be further described below in conjunction with specific embodiments.
[0040] Example 1:
[0041] like Figure 1 As shown, the Multi-task Semantic Parsing Model for BART (MSP-BART) directly converts natural language into the knowledge graph query language SPARQL. The BART-based multi-task semantic parsing model comprises seven parts: a word embedding layer, a BART encoding layer, a domain classifier, a BART decoding layer, a probabilistic decoder, a SPARQL decoder, and a syntax checker. The word embedding layer obtains the vector representation of each input character by adding word embeddings and position embeddings. The BART encoding layer comprehensively learns features from different subspaces through a bidirectional multi-head attention mechanism, capturing deeper semantic information. The domain classifier uses the hidden layer vector representation of the last layer of the BART encoding layer as the basis for its function. The input is text classification, and the output is the domain of the question. The BART decoding layer generates SPARQL autoregressive text from left to right based on the question encoding information and the preceding text decoding information through a language model. The probabilistic decoder fuses the vector output from the last layer of the BART decoder with the classification label [CLS] vector from the last layer of the BART encoding layer to achieve semantic information enhancement decoding. The SPARQL decoder iteratively selects a word from the dictionary distribution as the result generated at each time step based on the decoding strategy and domain information to complete the generation of the SPARQL query statement. The syntax checker corrects simple grammatical errors in the model output to improve the accuracy of question answering.
[0042] The process involves several key layers: a word embedding layer transforms each character in the input question into a vector representation, which is then fed into the BART encoding layer. The BART encoding layer learns and encodes the deep semantic information of the character vectors, inputting the hidden layer vector representation from the final encoding layer into both the domain classifier and the BART decoding layer. The domain classifier performs text classification on the hidden layer vector to determine the domain to which the question belongs. The BART decoding layer generates complete decoding information using a language model based on the question encoding information and the preceding decoding information. The probabilistic decoder module enhances the semantic information of the vector output from the final layer of the BART decoder and inputs the decoded information into the SPARQL decoder module. The SPARQL decoder module generates SPARQL query statements iteratively based on the decoding strategy and domain information, and then inputs these statements into the syntax checker module. The syntax checker checks for grammatical errors in the SPARQL query statements, correcting simple grammatical errors in the model output to improve question-answering accuracy.
[0043] This example uses the question "Who is Yao Ming's wife?" as an example, and combines it with... Figure 1 The specific workflow of the BART-based multi-task semantic parsing model of this invention is described below:
[0044] S1, the word embedding layer obtains the vector representation of each input character in the question "Who is Yao Ming's wife?" by adding word embeddings and position embeddings, and inputs it into the BART encoding layer;
[0045] S2, the BART encoding layer uses a bidirectional multi-head attention mechanism to comprehensively learn the features in different subspaces of the vector representation of each character in the question "Who is Yao Ming's wife?", captures deeper semantic information, and inputs the hidden layer vector representation of the last layer into the domain classifier and the BART decoding layer respectively.
[0046] S3, the domain classifier takes the hidden layer vector representation of the last layer of the BART coding layer as the input of this layer, and outputs the domain to which the question belongs through text classification. The domain to which this question belongs is "common sense".
[0047] S4, the BART decoding layer, uses a self-attention mechanism and a Markov language model to generate SPARQL text from left to right based on the question encoding information and the preceding text decoding information. For example, by using "Select? x where{<Yao Ming>", we know that the next character generated is "<".
[0048] S5, the probabilistic decoder fuses the vector output from the last layer of the BART decoding layer with the classification label [CLS] vector from the last layer of the BART encoding layer to achieve semantic information enhancement decoding, calculates the probability of each word in the vocabulary, and inputs the decoded information into the SPARQL decoder module;
[0049] S6, the SPARQL decoder, based on the decoding strategy and domain information, iteratively selects a word from the dictionary distribution as the result generated at each time step, completes the generation of the SPARQL query statement, and inputs the statement into the syntax checker module. Here, the generated statement is "Select?x where{<Yao Ming><wife>?x.}";
[0050] S7, the syntax checker, corrects simple syntax errors in the model's output, improving the accuracy of question answering.
[0051] In step S1, the word embedding layer obtains a vector representation of each input character by adding the word embedding and the position embedding, mainly including:
[0052] S11, the input data is composed of characters such as [CLS], the question "Who is Yao Ming's wife?", and [SEP]. The maximum length of the data is 512 characters. If it is too long, it will be truncated. If it is too short, it will be filled with the character [PAD].
[0053] S12, the vector representation of each input character is obtained by adding the word embedding and the position embedding.
[0054] In step S2, the BART coding layer uses a bidirectional multi-head attention mechanism to comprehensively learn features from different subspaces of the character's vector representation, capturing deeper semantic information, mainly including:
[0055] S21, the multi-head attention sublayer of the Transformer encoder employs a self-attention mechanism, creating three vectors (Query, Key, and Value) for each character of [CLS], the question "Who is Yao Ming's wife?", and [SEP]. Self-attention scores are calculated using the Attention(Q, K, V) formula, and multi-head self-attention is calculated using the Multihead(Q, K, V) formula. The calculation formulas are shown below:
[0056]
[0057] head_i = Attention(QW i Q KW i K VW i V )
[0058] Multihead(Q,K,V)=Concat(head1,head2,...,head h W O
[0059] Here, Softmax is the logistic regression function, and the Attention function uses the Softmax function to calculate self-attention, through different QW... i Q KW i K VW i V Multiple self-attention heads_i are combined and computed. Multihead(Q, K, V) connects multiple self-attention heads using the Concat function to combine them into multi-head attention.
[0060] S22, perform layer normalization of the Transformer encoder using the Layer_Normalization formula; the calculation formula is shown below;
[0061] SubLayer=Layer_Normalization(x+(sublayer(x)))
[0062] x is the result of the dual-head attention operation of the current layer, and Sublayer(x) is the result of the dual-head attention operation of the next layer. The two results are directly added together to perform residual linking, and layer normalization is performed through Layer_Normalization.
[0063] S23, through a feedforward network layer and the nonlinear activation function ReLU;
[0064] S24. Input the calculation result of S23 into the next layer of Transformer encoder, and execute a total of 6 Transformer encoders.
[0065] In step S3, the domain classifier takes the hidden layer vector representation of the last layer of the BART coding layer as the input of the layer, and outputs the domain to which the question belongs through text classification. The question should belong to the "general knowledge" category.
[0066] In step S4, the BART decoding layer, based on the question encoding information and the preceding text decoding information, uses a language model to generate SPARQL autoregressive text from left to right, mainly including:
[0067] S41, calculate the self-attention score using the Attention(Q, K, V) formula, and calculate the multi-head self-attention using the Multihead(Q, K, V) formula;
[0068] S42 uses an upper triangular MASK matrix to mask the following information;
[0069] S43, perform layer normalization of the Transformer decoder using the Layer_Normalization formula;
[0070] S44, based on the question encoding information and the preceding decoded information, uses a language model to achieve SPARQL autoregressive text generation from left to right. For example, given "Select? x where {<Yao Ming>", the next character generated is "<". The language model calculation is as follows: p(y1, y2, y3, ..., y n )=p(y1|E o )p(y2|E o ,y1)p(y3|E o y1, y2)...p(y n |E o y1, ...,y n-1 )
[0071] The above formula is the calculation formula for the Markov model, E o This represents the starting character. The formula calculates the probability of subsequent characters appearing starting from the first character, p(y). i |Eo , y1,..., y i-1 ) represents the probability of the occurrence of E o , y i ,..., y i-1 , and the next character is y i .
[0072] In step S5, the probability decoding layer fuses the vector output by the last layer of the BART decoding layer and the classification label [CLS] vector of the last layer of the BART encoding layer to realize semantic information enhanced decoding and calculate the probability of each character in the word table, for example, when the classification label [CLS] represents the vector of a symbol, the probability of the next character belonging to the characters "{", "<", etc. is calculated.
[0073] In step S6, the SPARQL decoder module selects a word from the dictionary distribution according to the decoding strategy to complete the generation of the SPARQL query statement, and the generated statement is "Select?x where { <Yao Ming> <wife>?x.}"; when the calculation formula p(y1, y2, y3,..., y n ) is calculated, if the decoded character before y i is "Select?x", the probability of y i being "where" is calculated.
[0074] In step S7, the grammar checker corrects the simple syntax errors output by the model.
[0075] The application can directly convert natural language into a knowledge graph query language SPARQL, simplify the question and answer steps to reduce error accumulation, recognize the domain of the question, query the corresponding professional domain knowledge base according to the domain, and improve the accuracy of question and answer.
[0076] Embodiment 2:
[0077] As Figure 2As shown, the application also provides a multi-task semantic parsing device applied in a knowledge graph question answering system, the device comprising at least one processor and at least one memory, the processor and the memory being coupled; the memory stores the computer program of the parsing model as described in Embodiment 1; the processor executes the computer program stored in the memory, so that the device realizes the multi-task semantic parsing function. The internal bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component (PCI) bus, or an Xtended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, the bus in the drawings of the present application does not limit to only one bus or one type of bus. The memory can include a high-speed RAM memory, and can also include a non-volatile storage NVM, for example, at least one disk memory, and can also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0078] The device can be provided as a terminal, a server or other forms of devices.
[0079] Figure 2 is a block diagram of a device shown by way of example. The device can include one or more of the following components: a processing component, a memory, a power supply component, a multimedia component, an audio component, an input / output (I / O) interface, a sensor component, and a communication component. The processing component generally controls the overall operation of the electronic device, such as operations associated with display, phone calls, data communications, camera operations and recording operations. The processing component can include one or more processors to execute instructions to complete all or part of the steps of the above methods. In addition, the processing component can include one or more modules to facilitate the interaction between the processing component and other components. For example, the processing component can include a multimedia module to facilitate the interaction between the multimedia component and the processing component.
[0080] The memory is configured to store various types of data to support the operation of the electronic device. Examples of these data include instructions for any application or method operating on the electronic device, contact data, phonebook data, messages, pictures, videos, etc. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0081] The power component provides power to various components of the electronic device. The power component can include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the electronic device. The multimedia component includes a screen to provide an output interface between the electronic device and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, swiping, and gestures on the touch panel. The touch sensors can not only sense a boundary of a touch or swiping action, but also detect duration and pressure associated with the touch or swiping action. In some embodiments, the multimedia component includes a front camera and / or a rear camera. The front camera and / or the rear camera can receive external multimedia data when the electronic device is in an operation mode, such as a shooting mode or a video mode. Each of the front and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0082] The audio component is configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) to receive an external audio signal when the electronic device is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory or transmitted via the communication component. In some embodiments, the audio component further includes a speaker to output audio signals.
[0083] The sensor component includes one or more sensors to provide various state assessments for the electronic device. For example, the sensor component can detect an open / closed position of the electronic device, relative positioning of components, such as a display and a keypad of the electronic device, a change in position of the electronic device or a component of the electronic device, presence or absence of user contact with the electronic device, a direction or acceleration / deceleration of the electronic device, and a change in temperature of the electronic device. The sensor component can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component can further include a light sensor, such as a CMOS or CCD image sensor, for use in an imaging application. In some embodiments, the sensor component can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0084] The communication component is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as WiFi, 2G, or 3G, or a combination thereof. In an example embodiment, the communication component receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component also includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra-WideBand (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0085] In an example embodiment, the electronic device can be implemented with one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors, or other electronic elements to perform the above-described methods.
[0086] Embodiment 3:
[0087] The present application also provides a computer readable storage medium, wherein a program or instruction of the parsing model according to Embodiment 1 is stored, and the program or instruction is executed by a processor to enable a computer to implement a multi-task semantic parsing function.
[0088] Specifically, a system, device or apparatus equipped with a readable storage medium can be provided, wherein a software program code for implementing the functions of any of the above embodiments is stored on the readable storage medium, and a computer or processor of the system, device or apparatus reads and executes the instructions stored in the readable storage medium. In this case, the program code read from the readable medium itself can implement the functions of any of the above embodiments, and therefore the machine readable code and the readable storage medium storing the machine readable code constitute part of the present application.
[0089] The storage medium described above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk (such as CD-ROM, CD-R, CD-RW, DVD-20ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tape, etc. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0090] It is to be understood that the above-mentioned processor can be a central processing unit (CPU), but can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the application can be directly embodied as hardware processor execution, or executed by a combination of hardware and software modules in the processor.
[0091] It should be understood that the storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in the terminal or server.
[0092] The computer readable program instructions described herein can be downloaded from a computer readable storage medium to each of the various computing / processing devices, or to external computers or external storage devices through a network, for example, the Internet, a local area network, a wide area network and / or a wireless network. The network can include copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and / or edge servers. The network adapter card or network interface in each computing / processing device receives computer readable program instructions from the network and forwards the computer readable program instructions to the computer readable storage medium in each computing / processing device for storage.
[0093] Computer readable program instructions for carrying out operations of the present disclosure can be assembly instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++ or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer readable program instructions can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) can execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present disclosure.
[0094] The specific implementation described above is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0095] Although the above describes the specific embodiments of the present application, it is not intended to limit the protection scope of the present application. Those skilled in the art should understand that various modifications or changes made on the basis of the technical solutions of the present application without creative labor are still within the protection scope of the present application.
Claims
1. A method for constructing a BART-based multi-task semantic parsing model, characterized in that: The model comprises a word embedding layer, a BART encoding layer, a domain classifier, a BART decoding layer, a probability decoder, a SPARQL decoder and a grammar checker; The word embedding layer converts each character in the input question into a vector representation and inputs the BART encoding layer; the BART encoding layer learns the semantic information of the character vector deep layer and encodes, and inputs the last layer of the encoded implicit layer vector representation into the domain classifier and the BART decoding layer respectively; The domain classifier performs text classification on the last layer of the implicit layer vector to obtain the domain to which the question belongs; the BART decoding layer generates complete decoding information through a language model according to the question encoding information and the previous decoding information; The probability decoder performs semantic information enhancement decoding on the vector output by the last layer of the BART decoder, and inputs the decoding information into the SPARQL decoder module; The SPARQL decoder module generates SPARQL query statements in cycles according to the decoding strategy and domain information, and inputs the statements into the grammar checker module; the grammar checker is used to check the syntax error of the SPARQL query statement; The BART uses a standard Transformer model, including 6 layers of Transformer encoder and 6 layers of Transformer decoder, the BART encoding layer learns the features in different subspaces through a bidirectional multi-head attention mechanism, and captures deeper semantic information, specifically: The multi-head attention sublayer of the Transformer encoder adopts a self-attention mechanism, creates three vectors Query, Key and Value for each word to calculate the self-attention score, and the calculation formula is as follows: (2) (3) (4) wherein, is a logistic regression function, The function is used The function calculates self-attention, and different Multiple sets of self-attention are calculated by combination , The multiple sets of self-attention are connected by The function combines multiple sets of self-attention into multi-head attention; Perform layer normalization of the Transformer encoder to prevent covariance shift problems, and use residual connection to prevent gradient disappearance, and the calculation formula is as follows: (5) x is the result of the bi- head attention operation for the current layer, is the result of the bi- head attention operation for the next layer, the two results are directly added, that is, residual connection is performed, and is normalized by layer normalization is performed; Through the feedforward network layer and the nonlinear activation function ReLU, the nonlinear fitting effect of the network is improved; The calculation result is input into the next layer of the Transformer encoder, and a total of 6 layers of the Transformer encoder are executed, and the weights are not shared between layers; The BART encoding layer realizes SPARQL left-to-right autoregressive text generation through a language model according to the question encoding information and the previous decoding information, specifically: The multi-head attention sublayer of the Transformer decoder adopts a self-attention mechanism, creates three vectors Query, Key and Value for each character vector to calculate the self-attention score, and the calculation formula is as follows: Use the upper triangular MASK matrix to mask the subsequent information, so that each word can only focus on the previous information, and prevent the model from using future input words during training; Perform layer normalization of the Transformer decoding to prevent covariance shift problems, and use residual connection to prevent gradient disappearance, and the calculation formula is as follows: According to the problem coding information and the above decoding information, SPARQL is generated from left to right by a language model, and the language model is calculated as shown below: (6) The above formula is the Markov model calculation formula, Indicates the starting character, and the formula calculates the probability of the occurrence of the subsequent character from the 1st character, Indicates the probability of the occurrence of the subsequent character from the 1st character, , to , the probability of the next character being is how much.
2. The method of claim 1, wherein the BART-based multi-task semantic parsing model is constructed by: The word embedding layer converts each character in the input question into a vector representation, specifically: The input data is composed of [CLS], question, [SEP] characters, and the maximum length of the data is 512 characters. If the length is too long, it will be truncated, and if the length is too short, it will be filled with [PAD] characters. Special characters "?x” and "?y” and special characters in the SPARQL grammar are added to the dictionary table. The vector representation of each input character is obtained by adding the word embedding and the position embedding, and the calculation formula is as shown below: (1) wherein, is a word embedding vector for a character, is a position embedding vector, is a vector representation of an input character.
3. The method of claim 1, wherein the BART-based multi-task semantic parsing model is constructed by: The domain classifier takes the hidden layer vector representation of the last layer of the BART encoding layer as the input of the layer, and outputs the domain to which the question belongs through text classification.
4. The method of claim 1, wherein the BART-based multi-task semantic parsing model is constructed by: The probability decoder fuses the vector output by the last layer of the BART encoding layer with the classification label [CLS] vector of the last layer of the BART encoding layer to achieve semantic information enhanced decoding, and calculates the probability of each word in the word table.
5. The method of claim 1, wherein the BART-based multi-task semantic parsing model is constructed by: The SPARQL decoder selects a word from the word dictionary distribution according to the decoding strategy and domain information to complete the generation of the SPARQL query statement.
6. The method of claim 1, wherein the BART-based multi-task semantic parsing model is constructed by: The syntax checker corrects the simple syntax errors output by the model to improve the accuracy of the question and answer. 7.A multi-task semantic parsing device applied in a knowledge graph question answering system, characterized in that: The device includes at least one processor and at least one memory, and the processor and the memory are coupled; the memory stores the computer program of the parsing model according to any one of claims 1 to 6; and the processor executes the computer program stored in the memory, so that the device realizes the multi-task semantic parsing function.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores the program or instructions of the parsing model according to any one of claims 1 to 6, and the program or instructions are executed by the processor to make the computer realize the multi-task semantic parsing function.