Sentence processing method, device and electronic device
Through the multi-head attention mechanism model fusion processing and identifying the label information of the statement, the problem of intent in the prior art cannot be accurately determined, and the intelligent control effect of electronic devices is achieved.
Patent Information
- Application Number
- CN202111355670.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2041-11-16
AI Technical Summary
When understanding natural language in the prior art, it is impossible to accurately determine the label information of each word in the sentence, resulting in the intent of the sentence being impossible to accurately determine, affecting the intelligent control effect of the electronic device.
The multi-head attention mechanism model is adopted, by considering the probability between the label information of each word in the statement and the label information of its contextual words, the label information of the entire statement is fused and processed and identified. The multi-head attention mechanism model is used to train the relationship between the label information of each word, and determine the word slot and intention.
It realizes a more accurate determination of the label information and intention of each word in the statement, ensuring that the electronic device can accurately execute the commands indicated by the user, and improves the user experience.
Smart Images

Figure CN114239601B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a sentence processing method, device and electronic device. Background Art
[0002] With the continuous development of science and technology, more and more electronic devices such as mobile phones, computers, and various electrical appliances are equipped with voice dialogue systems, allowing users of electronic devices to control the electronic devices in a "conversational" manner.
[0003] In the prior art, when a user speaks a command to an electronic device, the electronic device can collect the user's voice data through a microphone or other voice collection device, and convert the voice data into a text sentence. It can then determine the words included in the sentence through natural language understanding and other forms, and determine the intention corresponding to the sentence based on the label information of all the words in the sentence. Finally, it can execute the command corresponding to the intention to achieve voice dialogue control.
[0004] However, in the prior art, when natural language understanding is performed, when a sentence includes words that may correspond to multiple label information, it is not possible to completely accurately obtain the label information of each word, and it is also impossible to accurately determine the intention corresponding to the sentence, which results in the inability to accurately execute the command corresponding to the sentence, affecting the electronic device's ability to perform intelligent control based on the user's voice data and reducing the user experience of the electronic device. Summary of the Invention
[0005] The present application provides a sentence processing method, device and electronic device to solve the technical problem in the prior art that natural language understanding cannot fully and accurately determine the intention corresponding to the sentence.
[0006] The first aspect of the present application provides a method for processing sentences, comprising: obtaining a sentence to be processed; wherein the sentence to be processed is obtained by recognizing voice data, and the sentence to be processed includes a plurality of characters arranged in sequence; segmenting the sentence to be processed to obtain a plurality of words, and determining one or more label information corresponding to each word; inputting the plurality of words and the label information corresponding to each word into a multi-head attention mechanism model to obtain a probability matrix; the probability matrix includes a probability value of each label information in the one or more label information corresponding to each word; and determining a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed according to the probability matrix.
[0007] In an embodiment of the first aspect of the present application, the inputting of the multiple words and one or more label information corresponding to each word into the multi-head attention mechanism model includes: obtaining multiple first feature matrices based on the character feature vectors of the multiple characters in the sentence to be processed; obtaining multiple second feature matrices based on the feature vector of the label information corresponding to each character in the sentence; and inputting the multiple first feature matrices and the multiple second feature matrices into the multi-head attention mechanism model.
[0008] In an embodiment of the first aspect of the present application, the multi-head attention mechanism model is configured to determine, based on the historical sentence learning results, the probability value of each character in the first feature matrix and one or more label information corresponding to the words in which they are located in the second feature matrix appearing together, and to form the probability matrix based on the probability values of the multiple words; wherein the historical sentence learning results are obtained by inputting the multi-head attention mechanism model into training based on multiple sentences and a label information corresponding to each character in the sentence.
[0009] In an embodiment of the first aspect of the present application, the formula for obtaining the probability matrix M by the multi-head attention mechanism model includes:
[0010]
[0011] Wherein, Q is the first feature matrix, K and V are the second feature matrices, and dk is the vector dimension when the specified label information is embedded in the second feature matrix.
[0012] In an embodiment of the first aspect of the present application, the sentence to be processed is segmented to obtain multiple words, and one or more label information corresponding to each word is determined, including: the sentence to be processed is subjected to the ANSJ word segmentation algorithm to obtain the multiple words; one or more label information corresponding to each word is determined according to a mapping table, the mapping table including multiple words, and the correspondence between each word and one or more label information.
[0013] In an embodiment of the first aspect of the present application, the label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed are determined based on the probability matrix, including: processing the probability matrix through Transform encoding to obtain a feature matrix; performing slot classification and intention classification on each character in the feature matrix through a fully connected layer to obtain the word slot information and intention information in the sentence to be processed.
[0014] In an embodiment of the first aspect of the present application, the method further includes: obtaining multiple training sentences and determining the label information corresponding to each character in each training sentence; inputting the multiple training sentences and the label information corresponding to each character in each training sentence into the multi-head attention mechanism model, so that the multi-head attention mechanism model is trained to obtain the historical sentence learning results.
[0015] In an embodiment of the first aspect of the present application, after determining a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed, it also includes: storing the correspondence between the label information of each word in the sentence to be processed and the intention information; when a subsequent sentence is received again, and the label information of multiple words in the subsequent sentence is the same as the label information of multiple words in the sentence to be processed, determining the label information corresponding to each word in the subsequent sentence and the intention information of the subsequent sentence according to the correspondence.
[0016] The second aspect of the present application provides a sentence processing device, which can be used to execute the sentence processing method provided in the first aspect of the present application, and the device includes: an acquisition module, used to obtain a sentence to be processed; wherein the sentence to be processed is obtained by recognizing voice data, and the sentence to be processed includes a plurality of characters arranged in sequence; a word segmentation and annotation module, used to segment the sentence to be processed to obtain a plurality of words, and determine one or more label information corresponding to each word; a multi-head attention processing module, used to input the plurality of words and the label information corresponding to each word into a multi-head attention mechanism model to obtain a probability matrix; the probability matrix includes the probability value of each label information in the one or more label information corresponding to each word; a determination module, used to determine a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed according to the probability matrix.
[0017] The third aspect of the present application provides an electronic device comprising: a memory and a processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the processor executes the statement processing method as described in any one of the first aspects of the present application.
[0018] In summary, the sentence processing method and device provided by the present application, when processing the sentence to be processed, considers the probability of the label information of each word in the sentence and the label information of its context words appearing together through a multi-head attention mechanism model, thereby integrating the label information of the entire sentence into the information of each character, and realizing the fusion of the sentence to be processed and the label information for processing and recognition, thereby avoiding the situation where the word slot and the sentence intention cannot be accurately determined when the sentence to be processed includes words corresponding to multiple label information. Therefore, the label information of each word in the sentence can be determined more accurately, that is, the word slot in the sentence can be determined, and the intention corresponding to the sentence can be determined more accurately, thereby ensuring that the command of the sentence can be accurately determined later, and finally the command instructed by the user can be accurately executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only 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 labor.
[0020] Figure 1 A schematic diagram of a dialogue system;
[0021] Figure 2 A flowchart of an embodiment of a method for processing sentences provided in this application;
[0022] Figure 3 A flowchart of another embodiment of the method for processing statements provided in this application;
[0023] Figure 4 A schematic structural diagram of an embodiment of a statement processing device provided by this application;
[0024] Figure 5 This is a schematic structural diagram of an embodiment of an electronic device provided in this application. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0026] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the numbers used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] Before introducing the embodiments of the present application, the following describes the scenarios to which the present application is applied and the problems existing in existing scenarios with reference to the accompanying drawings. Figure 1 A diagram of a dialogue system, where Figure 1 The dialogue system provided in the dialogue scenario shown can be applied to intelligent electronic devices such as mobile phones, computers, and home appliances.
[0028] This application uses an electronic device as the execution subject for explanation. Users can then "speak" commands they wish the electronic device to execute to the electronic device through voice, achieving a more intelligent control method to improve the user experience of the electronic device. For example, if the electronic device is a television, when the user wants the television to play the movie "Infernal Affairs", without using a remote control or other control device, they only need to say "Watch Infernal Affairs" to the electronic device.
[0029] At this time, for an electronic device, after collecting the user's speech data through a speech collection device such as a microphone, first in S10, the user's speech data is converted into a text-form sentence by means of Automatic Speech Recognition (ASR) or the like. Subsequently, in S20, the command corresponding to the sentence is determined to be playing the movie "Shaolin" by means of Natural Language Understanding (NLU) or the like. More specifically, in S20, natural language understanding can, through means such as intention recognition, based on the context information in the sentence, determine the tag information of individual or consecutive words in the sentence. This process can also be called slot filling. For example, it is determined that the tag information of the word "watch" in "watch Infernal Affairs" is the "watch" slot for watching a movie, and the tag information of "Infernal Affairs" is the "VideaName" slot for the movie name, etc. Furthermore, based on the tag information of all the words in the sentence, that is, all the slots, the intention of the entire sentence can be determined. Finally, in S30, the electronic device executes the command to play the movie "Infernal Affairs" to implement the policy execution based on the user's conversation.
[0030] Although the dialogue system as Figure 1 shown can implement intelligent control based on the user's speech data, when the electronic device has various forms of playback functions, and as the data that the electronic device can process and the scale of the fields are becoming more and more abundant, when electronic devices such as speakers and TVs receive a sentence such as "listen to Shaolin Heroes", during the processing by natural language understanding, the tag information of "Shaolin Heroes" may be defined as the "VideaName" slot for the movie name, or the tag information of "Shaolin Heroes" may be defined as the "MusicName" slot for the music name, resulting in an inability to accurately determine the tag information of each word, and thus an inability to determine the intention corresponding to the entire sentence based on all the slots in the sentence, leading to an inability to accurately execute the command corresponding to the sentence subsequently, affecting the electronic device's implementation of intelligent control based on the user's speech data and reducing the user experience of the electronic device.
[0031] Therefore, the present application also provides a sentence processing method, which can be used in the system as Figure 1 shown, enabling the electronic device, when processing a sentence, to more accurately determine the tag information of each word in the sentence, that is, determine the slots in the sentence, by considering the probability of co-occurrence between the tag information of each word in the sentence and the tag information of its context words during natural language understanding, and thus can more accurately determine the intention corresponding to the sentence, and further ensure that the command of the sentence can be accurately determined subsequently, and finally accurately execute the command indicated by the user.
[0032] The following specific embodiments are used to describe the technical solution of the present application in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0033] Figure 2 A flowchart of an embodiment of a method for processing statements provided in this application is shown in FIG. Figure 2 The method shown can be applied in Figure 1 In the illustrated dialogue system, the electronic device executes in S20, specifically, the sentence processing method provided in this embodiment includes:
[0034] S101: The electronic device obtains a statement to be processed.
[0035] In some embodiments, after acquiring user voice data, the electronic device may perform automatic speech recognition processing on the voice data to obtain a sentence to be processed. The multiple characters in the sentence to be processed are arranged in sequence and maintain this arrangement during subsequent processing. For example, when a user says "Listen to Shaolin Heroes," the electronic device collects and recognizes that the sentence to be processed includes the five sequentially arranged characters "Listen to Shaolin Heroes."
[0036] S102: performing word segmentation processing on the sentence to be processed obtained in S101 to obtain multiple words, and determining one or more label information corresponding to each word.
[0037] In some embodiments, the electronic device can specifically use a word segmentation algorithm such as ANSJ to process the sentence to be processed, thereby obtaining multiple words in the sentence to be processed. For example, after the sentence to be processed "Listen to Shaolin Heroes" is segmented, two words "listen" and "Shaolin Heroes" can be obtained in the sentence to be processed. More specifically, ANSJ is an algorithm based on n-Gram+CRF+HMM that is specifically used for word segmentation of Chinese sentences. It currently realizes Chinese word segmentation, part-of-speech recognition, Chinese name recognition, user-defined dictionary, keyword extraction, automatic summary, keyword tagging and other functions. It can be applied to natural language processing and other aspects, and is suitable for scenarios with high requirements for word segmentation effects.
[0038] In some embodiments, after obtaining multiple segmented words, the electronic device further determines the tag information corresponding to each word. The electronic device can obtain the tag information corresponding to each word from a constructed "word-tag" mapping table. For example, tags can include names of people, actions, movie titles, music titles, and so on. For the word "listen," its tag information can be determined to include the action "listen," and for the word "Shaolin Hero," its tag information can be determined to include the movie title "VideoName" and the music title "MusicName."
[0039] In some embodiments, the mapping table for determining tag information may be stored in advance in the electronic device, or may be obtained by the electronic device from a server via the Internet, or may be specified by a user of the electronic device.
[0040] In some embodiments, Figure 3 A flowchart of another embodiment of the method for processing a statement provided in this application is shown as follows: Figure 2 A specific implementation of the sentence processing method shown is as follows, wherein in S102, the sentence to be processed is segmented in turn using the ANSJ word segmentation algorithm, and the label information corresponding to each word is determined according to the mapping table.
[0041] S103: Input the multiple words obtained in S102 and the label information corresponding to each word into the multi-head attention mechanism model, and obtain the probability matrix output by the multi-head attention mechanism model. The probability matrix includes the probability value of each word corresponding to each label information in the one or more label information.
[0042] In some embodiments, in the sentence processing method provided by this embodiment, the word slot and intention information are not directly determined by relying on the label information of the sentence to be processed, but the sentence to be processed and its label information are first processed by a multi-head attention mechanism model, and then the label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed are determined based on the probability matrix obtained after processing. Among them, the multi-head attention mechanism model performs matrix multiplication on the label information of each character and the label information of other characters in the sentence to be processed, so that the relationship between the label of each character and the label of the other characters can be obtained by autonomous training and learning, and then the probability value of the labels that may appear together in the entire sentence to be processed can be determined. That is, the multi-head attention mechanism model will pay more attention to the associated label information or the label information that may appear together, and the larger the probability value corresponding to these label information; while paying less attention to the label information that is not associated or cannot appear together, the smaller the probability value corresponding to these label information.
[0043] In a specific implementation of S103, multiple words and their corresponding label information are input into the multi-head attention mechanism model, specifically including: obtaining multiple first feature matrices based on the character feature vectors of multiple characters in the sentence to be processed, and obtaining multiple second feature matrices based on the feature vector of the label information corresponding to each character in the sentence, and then inputting the above-obtained first feature matrix and second feature matrix into the multi-head attention mechanism model.
[0044] For example, Figure 3As shown in S103, the electronic device can perform word embedding encoding on the characters in the sentence to be processed according to the word embedding matrix of the loaded pre-trained model (such as the Bert model, etc.) to obtain a word embedding encoding matrix E. The word embedding encoding matrix E specifically includes: e0, e2, ... et-1; there are t elements in total, and t is the number of characters in the sentence to be processed. Subsequently, the above-mentioned word embedding encoding matrix E is encoded by a bidirectional long short-term memory network (Long Short-Term Memory, abbreviated as: LSTM) to obtain a first feature matrix U. Among them, LSTM is a recurrent neural network with a chain structure, which can learn the long-term dependencies of text and is suitable for extracting feature information based on the entire sentence to be processed in this application. The first feature matrix U specifically includes: u0, u1... ut-1; there are t elements in total, t is the number of characters in the sentence to be processed, and the dimension of the first feature matrix U is (t, h).
[0045] In some embodiments, when multiple second feature matrices T are obtained based on the feature vectors of the label information corresponding to each word in the sentence in S103, the label information corresponding to each word can be determined based on the label information corresponding to each word determined in S103. For example, taking the sentence to be processed as "listen to Shaolin Heroes," the label information of the word "listen" determined in S102 includes the action "listen," and the label information of the word "Shaolin Heroes" includes the movie name "VideoName" and the music name "MusicName." The second feature matrix T then includes the five-dimensional vectors, based on the five words in the sentence to be processed, as follows: "listen," "VideoName" and "MusicName," "VideoName" and "MusicName," "VideoName" and "MusicName," and "VideoName" and "MusicName." The vector corresponding to each label information can be pre-specified and stored in a mapping table or other form.
[0046] In some embodiments, the calculation principle of the multi-head attention mechanism model provided in this application can be expressed by the following formula 1:
[0047]
[0048] In which, the first characteristic matrix U is used as Q in the formula, and the second characteristic matrix T is used as K and V in the formula and brought into formula 1, d k The vector dimension when the specified label information is embedded in the second feature matrix can ultimately obtain the probability matrix M.
[0049] In some embodiments, the parameters of the multi-head attention mechanism model provided by the embodiments of the present application are set as follows: the dimension of the latent vector of the model is set to h, and the number of "head" parameters of the multi-head attention mechanism model is configured to be 4, and each character corresponds to a maximum of 4 label information. The excess can be discarded, and the part that does not reach 4 is padded with the parameter "padding". Then the vector dimension of the second feature matrix obtained by the embedding matrix of the label information is h / 4. It should be noted that in actual application, the value of the "head" parameter can be other numerical values, such as the maximum number of labels that can be obtained. Based on the calculation process of Formula 1, the first feature matrix U can be split according to the number of heads 4 to obtain Q in the formula, then the dimension of Q is (t, 4, h / 4), and since the number of label information is set to 4, the vector dimension of the second feature matrix T is also (t, 4, h / 4), at this time d k =h / 4.
[0050] More specifically, in the calculation process of the above formula 1, the multi-head attention mechanism model determines the probability value of each character in the first feature matrix appearing together with one or more label information corresponding to the word in the second feature matrix based on its historical sentence learning results, thereby obtaining the probability values of multiple words and then obtaining the probability matrix.
[0051] In some embodiments, in order to obtain historical sentence learning results, the multi-head attention mechanism model can be trained in advance. For example, the electronic device can obtain multiple training sentences specified in advance by the staff, determine the label information corresponding to each word in each training sentence, and then input the multiple training sentences and the label information corresponding to each word in each training sentence into the multi-head attention mechanism model, so that the multi-head attention mechanism model is trained to obtain historical sentence learning results.
[0052] For example, the training sentence can be "listen to Huangmei Opera", etc., then the label information corresponding to each word in the training sentence is: "listen", "MusicName", "MusicName", "MusicName", "MusicName". After sending this training sentence and label information to the multi-head attention mechanism model, it can be learned and given more attention when the label information "listen" and "MusicName" may appear together. Subsequently, when receiving the training sentence "listen to Shaolin Heroes" and its label information "listen", "VideoName" and "MusicName", "VideoName" and "MusicName", "VideoName" and "MusicName", "VideoName" and "MusicName", "VideoName" and "MusicName", the calculation result can be obtained in the output probability matrix that the probability value of the four words "Shaolin Heroes" corresponding to the label information "MusicName" is greater, and the probability value of these four words corresponding to the label information "VideoName" is smaller.
[0053] In some embodiments, in S103 of the present application, for the case where there are words in the sentence corresponding to multiple label information, a judgment can be made before S103. When the text of all words in the sentence to be processed corresponds to only one label information, the judgment of S103 can be omitted and its word slot and intention information can be directly determined. Only when it is determined that the sentence to be processed includes text corresponding to multiple label information, it is processed through the multi-head attention mechanism model in S103.
[0054] S104: Determine the label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed based on the probability matrix obtained in S103.
[0055] In some embodiments, as Figure 3 As shown, in S104, the probability matrix M obtained in S103 that integrates semantic knowledge is firstly subjected to 2-layer Transform encoding to obtain the final feature vector of the sentence to be processed. The 2 layers in this embodiment are only examples and can be flexibly adjusted.
[0056] Subsequently, a general fully connected layer is used to perform intent classification and identification of the entire sentence to be processed and slot classification and filling of the label information of each character in the sentence to be processed on the feature vector of the sentence to be processed, and finally determine the intent information of the sentence to be processed and the slot of each character in the sentence to be processed. Among them, intent recognition is to perform maximum pooling on the matrix M, change the dimension to (1, h), and then connect a fully connected operator to map M to the intent space to obtain an I-dimensional vector, where I is the number of intents, and finally use the intent index with the highest score in the vector as the predicted intent result. Slot filling first connects a fully connected operator to the matrix M, maps M to the slot space, and obtains an S-dimensional matrix, where S is the number of slots, and then obtains the optimal slot combination through methods such as the CRF operator, and finally determines the corresponding intent based on the slot combination. This application does not limit the specific implementation method of slot filling and intent recognition.
[0057] For example, for the sentence to be processed "listen to Shaolin Heroes", its slots include two label information "listen" and "MusicName" corresponding to the words "listen" and "Shaolin Heroes", and the intention of the sentence to be processed is "music search" and the like.
[0058] In summary, the sentence processing method provided in this embodiment, when processing the sentence to be processed, considers the probability of the label information of each word in the sentence and the label information of its context words appearing together through a multi-head attention mechanism model, thereby integrating the label information of the entire sentence into the information of each character, and realizing the fusion of the sentence to be processed and the label information for processing and recognition, thereby avoiding the situation where the word slot and the sentence intention cannot be accurately determined when the sentence to be processed includes words corresponding to multiple label information. Therefore, the label information of each word in the sentence can be determined more accurately, that is, the word slot in the sentence can be determined, and the intention corresponding to the sentence can be determined more accurately, thereby ensuring that the command of the sentence can be accurately determined later, and finally the command instructed by the user can be accurately executed.
[0059] In some embodiments, after the electronic device determines a label information of each word in the sentence to be processed and the intention information of the sentence to be processed through the sentence processing method provided by this embodiment, the correspondence between the sentence to be processed and its corresponding label information and intention information can be stored. When the subsequent electronic device receives the subsequent sentence, if the label information of multiple words in the subsequent sentence is the same as the label information of multiple words in the sentence to be processed, or each word in the subsequent sentence is the same as each word in the sentence to be processed, it is no longer necessary to use the multi-head attention mechanism model to process it. Instead, the label information corresponding to each word in the subsequent sentence and the intention information of the entire subsequent sentence can be determined directly based on the stored correspondence. This can reduce repeated and invalid calculations performed using the multi-head attention mechanism model and improve the processing speed and efficiency of the electronic device for the sentence.
[0060] In the aforementioned embodiments, the statement processing methods provided in the embodiments of the present application are described. In order to implement the various functions of the statement processing methods provided in the aforementioned embodiments of the present application, the electronic device serving as the execution subject may include hardware structures and / or software modules, and the aforementioned functions may be implemented in the form of hardware structures, software modules, or hardware structures and software modules. Whether a particular function is implemented in the form of hardware structures, software modules, or hardware structures and software modules depends on the specific application and design constraints of the technical solution.
[0061] For example, Figure 4 This is a structural diagram of an embodiment of a sentence processing device provided by this application, as shown in FIG. Figure 4 As shown, the present application also provides a sentence processing device, including: an acquisition module 401, a word segmentation and tagging module 402, a multi-head attention processing module 403 and a determination module 404. Among them, the acquisition module 401 is used to obtain a sentence to be processed; wherein, the sentence to be processed is obtained by recognizing voice data, and the sentence to be processed includes a plurality of characters arranged in sequence; the word segmentation and tagging module 402 is used to segment the sentence to be processed, obtain a plurality of words, and determine one or more label information corresponding to each word; the multi-head attention processing module 403 is used to input the plurality of words and the label information corresponding to each word into the multi-head attention mechanism model to obtain a probability matrix; the probability matrix includes the probability value of each label information in the one or more label information corresponding to each word; the determination module 404 is used to determine a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed according to the probability matrix.
[0062] Specifically, the specific principles and implementation methods of the above steps respectively executed by each module in the statement processing device can be referred to the description of the statement processing method in the aforementioned embodiment of this application, and will not be repeated here.
[0063] It should be noted that it should be understood that the division of the various modules of the above device is merely a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. Moreover, these modules can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; some modules can also be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. It can be a separate processing element, or it can be integrated into a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called by a processing element of the above device to perform the functions of the above-mentioned determined module. The implementation of other modules is similar. In addition, these modules can all or partly be integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed by the hardware integrated logic circuit in the processor element or by instructions in the form of software.
[0064] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASICs), one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented by scheduling program code on a processing element, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0065] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)).
[0066] For example, Figure 5 This is a structural diagram of an embodiment of an electronic device provided by this application, such as Figure 5 As shown, the present application further provides an electronic device, comprising: a processor 502 and a memory 503, connected via a bus; wherein the memory 503 stores a computer program, and when the processor 502 executes the computer program, the processor 502 can be used to execute the statement processing method of any of the aforementioned embodiments of the present application. In some embodiments, the processor 502 can also exchange data with other devices via the communication interface 501, for example, to obtain a statement to be processed.
[0067] The present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed, it can be used to execute a statement processing method as described in any of the aforementioned embodiments of the present application.
[0068] An embodiment of the present application further provides a chip for executing instructions, wherein the chip is used to execute a method for processing statements executed by an electronic device as described in any of the aforementioned embodiments of the present application.
[0069] Those skilled in the art will appreciate that all or part of the steps in the above-described method embodiments can be implemented using hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0070] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for processing a statement, characterized in that: include: Obtaining a sentence to be processed; wherein the sentence to be processed is obtained by recognizing voice data, and the sentence to be processed includes a plurality of characters arranged in sequence; Segmenting the sentence to be processed to obtain multiple words, and determining one or more label information corresponding to each word; Obtaining a plurality of first feature matrices according to the character feature vectors of a plurality of characters in the sentence to be processed; Obtaining a plurality of second feature matrices according to the feature vector of the label information corresponding to each word in the sentence; Inputting the multiple first feature matrices and the multiple second feature matrices into a multi-head attention mechanism model to obtain a probability matrix; the probability matrix includes the probability value of each label information in the one or more label information corresponding to each word, and the multi-head attention mechanism model is configured to determine, based on historical sentence learning results, a probability value of each character in the first feature matrix and one or more label information corresponding to the word in which it is located in the second feature matrix appearing together, and composing the probability matrix based on the probability values of the multiple words; wherein the historical sentence learning results are obtained by inputting a plurality of sentences and a label information corresponding to each character in the sentence into the multi-head attention mechanism model for training; According to the probability matrix, a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed are determined.
2. The method according to claim 1, characterized in that The formula for obtaining the probability matrix M from the multi-head attention mechanism model includes: Among them, Q is the first characteristic matrix, K and V are the second characteristic matrices, d k The vector dimension when embedding the specified label information into the second feature matrix.
3. The method according to claim 1 or 2, characterized in that The word segmentation of the sentence to be processed to obtain multiple words and determining one or more label information corresponding to each word includes: The sentence to be processed is subjected to the ANSJ word segmentation algorithm to obtain the multiple words; One or more tag information corresponding to each word is determined according to a mapping table, wherein the mapping table includes a plurality of words and a correspondence between each word and the one or more tag information.
4. The method according to claim 1 or 2, characterized in that Determining, based on the probability matrix, label information corresponding to each word in the sentence to be processed and intention information of the sentence to be processed includes: Processing the probability matrix through Transform coding to obtain a feature matrix; Each word in the feature matrix is subjected to slot classification and intent classification through a fully connected layer to obtain word slot information and intent information in the sentence to be processed.
5. The method according to claim 1, wherein The method further comprises: Obtain multiple training sentences and determine the label information corresponding to each word in each training sentence; The multiple training sentences and the label information corresponding to each word in each training sentence are input into the multi-head attention mechanism model, so that the multi-head attention mechanism model is trained to obtain the historical sentence learning results.
6. The method according to claim 1 or 2, characterized in that After determining the label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed, the method further includes: Storing the corresponding relationship between the label information of each word in the sentence to be processed and the intention information; When a subsequent statement is received again, and the label information of multiple words in the subsequent statement is the same as the label information of multiple words in the statement to be processed, the label information corresponding to each word in the subsequent statement and the intention information of the subsequent statement are determined according to the corresponding relationship.
7. A sentence processing device, characterized in that: include: An acquisition module, configured to acquire a sentence to be processed; wherein the sentence to be processed is obtained by recognizing voice data, and the sentence to be processed includes a plurality of characters arranged in sequence; A word segmentation and tagging module is used to segment the sentence to be processed to obtain multiple words and determine one or more label information corresponding to each word; A multi-head attention processing module is configured to obtain a plurality of first feature matrices based on the character feature vectors of a plurality of characters in the sentence to be processed; obtain a plurality of second feature matrices based on the feature vectors of the label information corresponding to each character in the sentence; input the plurality of first feature matrices and the plurality of second feature matrices into the multi-head attention mechanism model to obtain a probability matrix; the probability matrix includes the probability value of each of the one or more label information corresponding to each word; the multi-head attention mechanism model is configured to determine, based on the historical sentence learning results, the probability value of each character in the first feature matrix and the one or more label information corresponding to the word in which it is located in the second feature matrix appearing together, and form the probability matrix based on the probability values of the multiple words; wherein the historical sentence learning results are obtained by inputting a plurality of sentences and a label information corresponding to each character in the sentence into the multi-head attention mechanism model for training; A determination module is used to determine a label information corresponding to each word in the sentence to be processed and the intention information of the sentence to be processed according to the probability matrix.
8. An electronic device, characterized in that: include: memory and processor; The memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the processor executes the statement processing method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Natural language understanding method based on pre-training model
CN110674639A
Multi-label classification method for obtaining customer intention labels through robot collection
CN112732871A