Speech recognition method, device, computer equipment and storage medium
By calculating the cosine weight and similarity of the initial query feature and key feature of the speech sequence, the attention feature of speech recognition is directly determined, which solves the problem of large calculation amount of multiplication of multiple attention matrices in the existing technology, and improves speech recognition speed and accuracy.
Patent Information
- Application Number
- CN202210446103.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-26
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-04-26
AI Technical Summary
In existing speech recognition technology, multiple attention matrices are directly multiplied to calculate the weighting matrix, which results in a large amount of calculation and affects the recognition speed. Especially when processing long speech sequences, the computing pressure and time increase, which affects the recognition efficiency.
The cosine weight of the initial query feature and key feature is determined based on the number of voice features of the voice sequence, and the similarity is calculated to determine the attention feature, which reduces the amount of calculation and improves the recognition speed.
It reduces the recognition time of long speech sequences, improves the recognition speed and efficiency, reduces the computing pressure, and enhances the accuracy of speech recognition.
Smart Images

Figure CN114913848B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of speech recognition technology, and in particular to a speech recognition method, apparatus, computer device and storage medium. Background Art
[0002] Automatic Speech Recognition (ASR) is an important technology in the field of artificial intelligence that can convert human speech sequences into accurate text. The speech recognition process is usually implemented based on the self-attention mechanism. Specifically, multiple attention matrices corresponding to the speech features in the acquired speech sequence can be directly multiplied to obtain a weighted weight matrix. The weighted weight matrix is used for weighted processing to obtain the attention feature corresponding to each speech feature. Based on the feature processing of each attention feature, the speech recognition text corresponding to the speech sequence is determined.
[0003] However, directly multiplying multiple attention matrices to obtain a weighted weight matrix requires a large amount of calculation, which affects the speed of speech recognition. In addition, as the length of the speech sequence increases, the number of features in the attention matrix will increase, and the amount of calculation will also increase. This not only increases the calculation pressure, but also causes the time to recognize long speech sequences to increase further, which seriously affects the recognition speed of long speech sequences. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a speech recognition method, apparatus, computer device and storage medium.
[0005] In a first aspect, an embodiment of the present disclosure provides a speech recognition method, comprising:
[0006] Based on the number of speech features in the speech sequence to be recognized, determining a first cosine weight of each initial query feature in the query matrix corresponding to the speech sequence, and a second cosine weight of each initial key feature in the key matrix corresponding to the speech sequence;
[0007] Based on the first cosine weight and the second cosine weight, determining the similarity between each of the initial query features and each of the initial key features;
[0008] For each speech feature in the speech sequence, based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, determine the attention feature corresponding to the speech feature;
[0009] Based on the attention features respectively corresponding to the various speech features in the speech sequence, a speech recognition result corresponding to the speech sequence is determined.
[0010] This implementation method uses the calculated first cosine weight corresponding to each initial query feature and the second cosine weight corresponding to each initial key feature to determine the similarity between each initial query feature and each initial key feature, and then determines the attention feature corresponding to each voice feature based on each similarity and each target value feature in the value matrix; compared to directly multiplying multiple attention matrices to obtain a weighted weight matrix, and then using the weighted weight matrix to weight the voice feature to obtain the attention feature corresponding to each voice feature, the disclosed embodiment determines the attention feature corresponding to each voice feature based on the cosine weight, which reduces the amount of calculation and improves the speed of voice recognition. In this way, the calculation pressure when recognizing long voice sequences will be reduced, and the time for recognizing long voice sequences will also be reduced, effectively improving the recognition speed of recognizing long voice sequences.
[0011] In a possible implementation, determining the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight includes:
[0012] Using any one of the preset multiple kernel functions as the target kernel function, each of the initial query features is converted into a non-negative target query feature, and each of the initial key features is converted into a non-negative target key feature;
[0013] Determine a first weighted result corresponding to each of the initial key features based on a second cosine weight corresponding to each of the initial key features and a target key feature corresponding to the initial key feature;
[0014] For each of the initial query features, based on the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature, determine the second weighted result corresponding to the initial query feature; and based on the second weighted result and the first weighted result corresponding to each of the initial key features, determine the similarity between the initial query feature and each of the initial key features.
[0015] This implementation uses a target kernel function to convert the initial query features into non-negative target query features, and converts the initial key features into non-negative target key features, thereby avoiding directly using the originally negative initial query features and / or the originally negative initial key features for calculation, which affects the accuracy of the obtained similarity, and ensures the accuracy of the calculated similarity.
[0016] In a possible implementation, determining the similarity between the initial query feature and each of the initial key features based on the second weighted result and the first weighted result corresponding to each of the initial key features includes:
[0017] Determine a first sinusoidal weight corresponding to the initial query feature based on a first ranking value of the initial query feature in the query matrix and the number of the speech features, and determine a second sinusoidal weight corresponding to each initial key feature based on a second ranking value of each initial key feature in the key matrix;
[0018] Determining a third weighted result corresponding to the initial query feature based on the first sinusoidal weight and a target query feature corresponding to the initial query feature;
[0019] For each of the initial key features, based on the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature, determine a fourth weighted result corresponding to the initial key feature;
[0020] Based on the second weighted result, the third weighted result, the first weighted result corresponding to each of the initial key features, and the fourth weighted result, the similarity between the initial query feature and each of the initial key features is determined.
[0021] This implementation uses the determined first sinusoidal weight corresponding to each initial query feature and the determined second sinusoidal weight corresponding to each initial key feature to determine the similarity between each initial query feature and each initial key feature, which can further improve the accuracy of the determined similarity.
[0022] In a possible implementation, determining the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, includes:
[0023] For each of the initial key features, based on the first weighted result corresponding to the initial key feature and the target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature, determine the first intermediate result corresponding to the initial key feature;
[0024] Determine a second intermediate result corresponding to the initial key feature based on a fourth weighted result corresponding to the initial key feature and a target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature;
[0025] Multiplying the second weighted result corresponding to the initial query feature and the first intermediate result corresponding to each of the initial key features to obtain a fifth weighted result;
[0026] Multiplying the third weighted result corresponding to the initial query feature and the second intermediate result corresponding to each of the initial key features to obtain a sixth weighted result;
[0027] Based on the sum of the similarities between the initial query feature corresponding to the voice feature and each of the initial key features, the sum of the fifth weighted results, and the sum of the sixth weighted results, the attention feature corresponding to the voice feature is determined.
[0028] In this implementation, through the third sort value and the second sort value, it is possible to find the target value feature that matches each initial key feature in the value matrix, that is, to determine each key-value pair. Based on the weighted results corresponding to the initial key features in the key-value pair, and the target key features of the key-value pair, the first intermediate result and the second intermediate result corresponding to each key-value pair can be accurately obtained. Furthermore, based on the accurate first intermediate result and the second intermediate result, an accurate attention feature can be determined.
[0029] In a possible implementation, before determining the first cosine weight of each of the initial query features in the query matrix corresponding to the speech sequence based on the number of speech features in the speech sequence to be recognized, the method further includes:
[0030] Acquire the speech sequence to be recognized, and perform a spatial mapping operation on the speech sequence to obtain the mapped speech sequence;
[0031] Performing sequence fusion on the speech sequence and the mapped speech sequence to obtain a fused speech sequence;
[0032] The fused speech sequence is subjected to feature mapping processing using the target feature matrix to obtain a query matrix, a key matrix and a value matrix corresponding to the speech sequence; wherein the query matrix, the key matrix and the value matrix correspond to different target feature matrices respectively.
[0033] In this implementation, through the spatial mapping operation, the speech sequence to be recognized can be converted in the spatial dimension to obtain the mapped speech sequence in different spatial dimensions, and then the speech sequence and the mapped speech sequence are sequence-fused to obtain a fused speech sequence that incorporates more spatial information. The fused speech sequence is used for feature mapping processing, which improves the richness of the feature information contained in each of the query matrix, key matrix and value matrix.
[0034] In a possible implementation, determining the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to the speech features in the speech sequence includes:
[0035] Fusing each speech feature in the fused speech sequence with the attention feature corresponding to the speech feature to obtain each fused attention feature;
[0036] Perform convolution operation on each fused attention feature to obtain each convolved attention feature, and perform feature fusion on each convolved attention feature and the fused attention feature corresponding to the attention feature to obtain the initial attention feature corresponding to each convolved attention feature;
[0037] Performing a spatial mapping operation on each of the initial attention features to obtain each mapped initial attention feature, and performing feature fusion on each of the initial attention features and the mapped initial attention feature corresponding to the initial attention feature to obtain each fused initial attention feature;
[0038] A normalization operation is performed on each fused initial attention feature to obtain an intermediate attention feature corresponding to each speech feature, and based on each intermediate attention feature, a speech recognition result corresponding to the speech sequence is determined.
[0039] This implementation method, through the fusion operation, convolution operation, spatial mapping operation and normalization operation performed on the attention features, can obtain the intermediate attention features corresponding to each speech feature, which are rich in meaning information and can more accurately reflect the speech recognition results. Furthermore, based on each accurate intermediate attention feature, the speech recognition results can be accurately determined.
[0040] In a possible implementation, determining the speech recognition result corresponding to the speech sequence based on each intermediate attention feature includes:
[0041] Using a sequence composed of each intermediate attention feature as a new speech sequence to be recognized, and using each intermediate attention feature as each speech feature in the new speech sequence to be recognized;
[0042] Returning to the step of performing a spatial mapping operation on the speech sequence to obtain the mapped speech sequence, until the number of loops reaches a preset number, and obtaining each target attention feature corresponding to the speech sequence to be recognized;
[0043] Based on each of the target attention features, the speech recognition result is determined.
[0044] This implementation method can fully extract the information represented by each speech feature through multiple cycles of operation, thereby obtaining a target attention feature containing rich information. Using each target attention feature for speech recognition can improve the accuracy of the determined speech recognition result.
[0045] In a possible implementation, determining the speech recognition result based on each of the target attention features includes:
[0046] Using at least one preset decoding module, feature decoding is performed on each of the target attention features to obtain the speech recognition result; wherein, the input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the last decoding module in the decoding order is the speech recognition result.
[0047] This implementation utilizes multiple decoding modules for decoding, which can fully decode the information represented by each target attention feature, thereby obtaining accurate speech recognition results.
[0048] In a possible implementation, the speech recognition method is performed using a pre-trained speech recognition neural network; the speech recognition neural network is trained according to the following steps:
[0049] Obtaining a sample speech sequence to be recognized;
[0050] Inputting the sample speech sequence into a speech recognition neural network to be trained, and using the speech recognition neural network to be trained to perform recognition processing on the sample speech sequence, and determining each of the target prediction attention features corresponding to the sample speech sequence;
[0051] Determining a predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0052] Based on the predicted speech result and the standard speech result corresponding to the sample speech sequence, the prediction loss corresponding to the speech recognition neural network to be trained is determined, and the speech recognition neural network to be trained is iteratively trained using the prediction loss until a training cutoff condition is met, thereby obtaining a trained speech recognition neural network.
[0053] In this implementation mode, the trained speech recognition neural network has reliable recognition accuracy, and accurate speech recognition results can be obtained by using the trained speech recognition neural network for speech recognition. By iteratively training the speech recognition neural network to be trained using the prediction loss determined according to the test speech result and the standard speech result, the prediction accuracy of the speech recognition neural network can be effectively improved, and finally a speech recognition neural network with reliable accuracy can be obtained through training.
[0054] In a possible implementation, the predicted speech result includes a first predicted speech result, and the prediction loss includes a temporal classification loss;
[0055] The step of determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features includes:
[0056] Determine a first predicted speech result corresponding to the sample speech sequence by using each of the target predicted attention features;
[0057] The step of determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result includes:
[0058] The neural network connection temporal classification CTC algorithm is used to determine the temporal classification loss based on the first predicted speech result and the standard speech result.
[0059] This implementation method directly uses each target prediction attention feature to determine a first predicted speech result, and then uses the temporal classification loss determined based on the first predicted speech result and the standard speech result to iteratively train the speech recognition neural network to be trained, which can not only improve the network prediction accuracy, but also improve the network prediction speed.
[0060] In a possible implementation, the predicted speech result includes a second predicted speech result, and the prediction loss includes a cross entropy loss;
[0061] The step of determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features includes:
[0062] Using at least one decoding module preset in the speech recognition neural network to be trained, feature decoding is performed on each of the target predicted attention features to obtain the second predicted speech result;
[0063] The step of determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result includes:
[0064] The cross entropy loss is determined based on the second predicted speech result and the standard speech result.
[0065] In this implementation, a decoding module is used to perform feature decoding on each target predicted attention feature to obtain a second predicted speech result, and then the temporal classification loss and the cross entropy loss determined based on the second predicted speech result and the standard speech result are used to iteratively train the speech recognition neural network to be trained, which can further improve the recognition accuracy of the trained speech recognition neural network.
[0066] In a second aspect, the present disclosure also provides a speech recognition device, including:
[0067] A first determination module is used to determine, based on the number of speech features in the speech sequence to be recognized, a first cosine weight of each initial query feature in the query matrix corresponding to the speech sequence, and a second cosine weight of each initial key feature in the key matrix corresponding to the speech sequence;
[0068] A second determination module, configured to determine the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight;
[0069] A third determination module is used to determine, for each speech feature in the speech sequence, an attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence;
[0070] The fourth determination module is used to determine the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to each of the speech features in the speech sequence.
[0071] In a possible implementation manner, the second determination module, when determining the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight, is used to convert each of the initial query features into a non-negative target query feature and convert each of the initial key features into a non-negative target key feature using any target kernel function among a plurality of preset kernel functions;
[0072] Determine a first weighted result corresponding to each of the initial key features based on a second cosine weight corresponding to each of the initial key features and a target key feature corresponding to the initial key feature;
[0073] For each of the initial query features, based on the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature, determine the second weighted result corresponding to the initial query feature; and based on the second weighted result and the first weighted result corresponding to each of the initial key features, determine the similarity between the initial query feature and each of the initial key features.
[0074] In a possible implementation, the second determination module, when determining the similarity between the initial query feature and each of the initial key features based on the second weighted result and the first weighted result corresponding to each of the initial key features, is used to determine the first sinusoidal weight corresponding to the initial query feature based on the first ranking value of the initial query feature in the query matrix and the number of the speech features, and to determine the second sinusoidal weight corresponding to each of the initial key features based on the second ranking value of each of the initial key features in the key matrix;
[0075] Determining a third weighted result corresponding to the initial query feature based on the first sinusoidal weight and a target query feature corresponding to the initial query feature;
[0076] For each of the initial key features, based on the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature, determine a fourth weighted result corresponding to the initial key feature;
[0077] Based on the second weighted result, the third weighted result, the first weighted result corresponding to each of the initial key features, and the fourth weighted result, the similarity between the initial query feature and each of the initial key features is determined.
[0078] In a possible implementation, the third determination module, when determining the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, is used to determine, for each of the initial key features, the first intermediate result corresponding to the initial key feature based on the first weighted result corresponding to the initial key feature and the target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature;
[0079] Determine a second intermediate result corresponding to the initial key feature based on a fourth weighted result corresponding to the initial key feature and a target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature;
[0080] Multiplying the second weighted result corresponding to the initial query feature and the first intermediate result corresponding to each of the initial key features to obtain a fifth weighted result;
[0081] Multiplying the third weighted result corresponding to the initial query feature and the second intermediate result corresponding to each of the initial key features to obtain a sixth weighted result;
[0082] Based on the sum of the similarities between the initial query feature corresponding to the voice feature and each of the initial key features, the sum of the fifth weighted results, and the sum of the sixth weighted results, the attention feature corresponding to the voice feature is determined.
[0083] In a possible implementation, the device further includes a mapping module, which is used to obtain the speech sequence to be recognized, and perform a spatial mapping operation on the speech sequence to obtain the mapped speech sequence before determining the first cosine weight of each of the initial query features in the query matrix corresponding to the speech sequence based on the number of speech features in the speech sequence to be recognized;
[0084] Performing sequence fusion on the speech sequence and the mapped speech sequence to obtain a fused speech sequence;
[0085] The fused speech sequence is subjected to feature mapping processing using the target feature matrix to obtain a query matrix, a key matrix and a value matrix corresponding to the speech sequence; wherein the query matrix, the key matrix and the value matrix correspond to different target feature matrices respectively.
[0086] In a possible implementation, the fourth determination module, when determining the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to the respective speech features in the speech sequence, is used to fuse each speech feature in the fused speech sequence with the attention feature corresponding to the speech feature to obtain each fused attention feature;
[0087] Perform convolution operation on each fused attention feature to obtain each convolved attention feature, and perform feature fusion on each convolved attention feature and the fused attention feature corresponding to the attention feature to obtain the initial attention feature corresponding to each convolved attention feature;
[0088] Performing a spatial mapping operation on each of the initial attention features to obtain each mapped initial attention feature, and performing feature fusion on each of the initial attention features and the mapped initial attention feature corresponding to the initial attention feature to obtain each fused initial attention feature;
[0089] A normalization operation is performed on each fused initial attention feature to obtain an intermediate attention feature corresponding to each speech feature, and based on each intermediate attention feature, a speech recognition result corresponding to the speech sequence is determined.
[0090] In a possible implementation, the fourth determination module, when determining the speech recognition result corresponding to the speech sequence based on each intermediate attention feature, is used to use the sequence composed of each intermediate attention feature as a new speech sequence to be recognized, and use each intermediate attention feature as each speech feature in the new speech sequence to be recognized;
[0091] Returning to the step of performing a spatial mapping operation on the speech sequence to obtain the mapped speech sequence, until the number of loops reaches a preset number, and obtaining each target attention feature corresponding to the speech sequence to be recognized;
[0092] Based on each of the target attention features, the speech recognition result is determined.
[0093] In one possible implementation, the fourth determination module, when determining the speech recognition result based on each of the target attention features, is used to use at least one preset decoding module to perform feature decoding on each of the target attention features to obtain the speech recognition result; wherein the input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the decoding module located last in the decoding order is the speech recognition result.
[0094] In a possible implementation, the speech recognition method is performed using a pre-trained speech recognition neural network;
[0095] The device further comprises: a training module, configured to train the speech recognition neural network according to the following steps:
[0096] Obtaining a sample speech sequence to be recognized;
[0097] Inputting the sample speech sequence into a speech recognition neural network to be trained, and using the speech recognition neural network to be trained to perform recognition processing on the sample speech sequence, and determining each of the target prediction attention features corresponding to the sample speech sequence;
[0098] Determining a predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0099] Based on the predicted speech result and the standard speech result corresponding to the sample speech sequence, the prediction loss corresponding to the speech recognition neural network to be trained is determined, and the speech recognition neural network to be trained is iteratively trained using the prediction loss until a training cutoff condition is met, thereby obtaining a trained speech recognition neural network.
[0100] In a possible implementation, the predicted speech result includes a first predicted speech result, and the prediction loss includes a temporal classification loss;
[0101] The training module is used to determine the first predicted speech result corresponding to the sample speech sequence by using each of the target predicted attention features when determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0102] And when determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result, it is used to use the neural network connection temporal classification CTC algorithm to determine the temporal classification loss based on the first predicted speech result and the standard speech result.
[0103] In a possible implementation, the predicted speech result includes a second predicted speech result, and the prediction loss includes a cross entropy loss;
[0104] The training module is used to perform feature decoding on each of the target predicted attention features to obtain the second predicted speech result by using at least one decoding module preset in the speech recognition neural network to be trained when determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0105] And when determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result, it is used to determine the cross entropy loss based on the second predicted speech result and the standard speech result.
[0106] In a third aspect, an optional implementation of the present disclosure further provides a computer device, a processor, and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the processor is used to execute the machine-readable instructions stored in the memory, and when the machine-readable instructions are executed by the processor, the machine-readable instructions perform the steps of the above-mentioned first aspect, or any possible implementation of the first aspect.
[0107] In a fourth aspect, an optional implementation of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed, the steps of the above-mentioned first aspect, or any possible implementation of the first aspect are executed.
[0108] For a description of the effects of the above-mentioned speech recognition apparatus, computer device, and computer-readable storage medium, please refer to the description of the above-mentioned speech recognition method, which will not be repeated here.
[0109] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0110] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0111] Figure 1A flow chart of a speech recognition method provided by an embodiment of the present disclosure is shown;
[0112] Figure 2 A schematic diagram of the structure of a speech recognition neural network provided by an embodiment of the present disclosure is shown;
[0113] Figure 3 A flow chart of a method for training a speech recognition neural network to be trained provided by an embodiment of the present disclosure is shown;
[0114] Figure 4 A schematic diagram of determining a prediction loss corresponding to a speech recognition neural network to be trained provided by an embodiment of the present disclosure is shown;
[0115] Figure 5 A schematic diagram of a speech recognition device provided by an embodiment of the present disclosure is shown;
[0116] Figure 6 A schematic diagram of the structure of a computer device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0117] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure is not intended to limit the scope of the present disclosure claimed for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0118] In addition, the terms "first", "second", etc. in the description and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein.
[0119] The "multiple or several" mentioned in this article refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0120] According to research, when using ASR technology to perform speech recognition on the acquired speech sequence, three different preset feature matrices are usually used to map the speech sequence respectively to obtain the query matrix, key matrix and value matrix, and then the transposed matrix of the query matrix and the key matrix is directly multiplied to obtain the weighted weight matrix. The weighted weight matrix is used to weight the value matrix to obtain the attention feature corresponding to each speech feature.
[0121] The amount of calculation required for the above operation of directly multiplying the transposed matrices of the query matrix and the key matrix will increase as the size of the query matrix and the key matrix increases. For example, the query matrix and the key matrix are both T times d matrices, where T represents the number of features in the matrix and d represents the feature dimension of a single feature in the matrix. The amount of calculation required for directly multiplying the transposed matrices of the query matrix and the key matrix is T^2×d. On the basis that the size of the query matrix and the key matrix is determined by the length of the speech sequence, the longer the speech sequence is, the greater the amount of calculation required, the greater the calculation pressure, the longer the calculation time, and the longer the speech recognition time. Therefore, the above speech recognition process seriously affects the recognition speed and recognition effect of long speech sequences.
[0122] Based on the above research, the present disclosure provides a speech recognition method, apparatus, computer equipment and storage medium, which uses the calculated first cosine weight corresponding to each initial query feature and the second cosine weight corresponding to each initial key feature to determine the similarity between each initial query feature and each initial key feature, and then determines the attention feature corresponding to each speech feature based on each similarity feature and each target value feature in the value matrix; compared to directly multiplying multiple attention matrices to obtain a weighted weight matrix, and then using the weighted weight matrix to weight the speech feature to obtain the attention feature corresponding to each speech feature, the embodiment of the present disclosure directly determines the attention feature corresponding to each speech feature based on the cosine weight, which reduces the amount of calculation and improves the speed of speech recognition. In this way, the calculation pressure when recognizing long speech sequences will be reduced, and the time for recognizing long speech sequences will also be reduced, effectively improving the recognition speed of recognizing long speech sequences.
[0123] The defects existing in the above solutions are the results obtained by the inventor after practice and careful research. Therefore, the discovery process of the above problems and the solutions proposed by the present disclosure for the above problems below should be the contributions made by the inventor to the present disclosure during the disclosure process.
[0124] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0125] To facilitate understanding of this embodiment, a speech recognition method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the speech recognition method provided in the embodiment of the present disclosure is generally a terminal device or other processing device with certain computing capabilities, wherein the terminal device can be a mobile device, a computer device, etc.; in some possible implementations, the speech recognition method can be implemented by a processor calling a computer-readable instruction stored in a memory. The speech recognition method provided in the embodiment of the present disclosure is described below by taking the execution subject as a computer device as an example.
[0126] like Figure 1 As shown, it is a flowchart of a speech recognition method provided by an embodiment of the present disclosure, which may include the following steps:
[0127] S101: Based on the number of speech features in a speech sequence to be recognized, determine a first cosine weight of each initial query feature in a query matrix corresponding to the speech sequence, and a second cosine weight of each initial key feature in a key matrix corresponding to the speech sequence.
[0128] Here, the speech sequence to be recognized may include multiple speech features, and the speech sequence may be determined according to the acquired speech segments, and different speech segments correspond to different speech sequences. The number of speech features included in the speech sequence is determined by the length of the speech segment, and the longer the speech segment, the more speech features included in the speech sequence.
[0129] For example, the speech sequence to be recognized is X={x1, x2, x3, ... x T}, where x represents the speech feature, x1 represents the first speech feature in the speech sequence X, x2 represents the second speech feature in the speech sequence X, x3 represents the third speech feature in the speech sequence X, and so on. T It represents the Tth speech feature in the speech sequence X, where T is determined by the length of the speech segment.
[0130] In order to improve the recognition accuracy of the speech recognition of the speech sequence to be recognized, before executing S101, the following steps need to be performed:
[0131] Step 1: Obtain a speech sequence to be recognized, and perform a spatial mapping operation on the speech sequence to obtain a mapped speech sequence.
[0132] Here, for any speech sequence that needs to be recognized, it is necessary to first obtain the speech sequence to be recognized. Specifically, the speech sequence to be recognized can be directly generated and can be directly obtained when recognition is required. Alternatively, a speech segment to be recognized can be first obtained, and features of the speech segment can be extracted to obtain multiple speech features corresponding to the speech segment, and then a speech sequence to be recognized composed of multiple speech features can be obtained. Among them, the order of each speech feature in the multiple speech features in the speech sequence to be recognized is determined by the position of the speech feature corresponding to the speech segment.
[0133] The mapped speech sequence includes a plurality of mapped speech features, and the number of speech features in the speech sequence to be recognized is consistent with and corresponds one to one to the number of mapped speech features in the mapped speech sequence.
[0134] The speech recognition method provided in the embodiments of the present disclosure can be executed using a pre-trained speech recognition neural network, and the speech recognition neural network can be deployed in a computer device.
[0135] After obtaining the speech sequence to be recognized, the first feedforward network layer module (Feed Forward Module) in the speech recognition neural network can be used to perform a spatial mapping operation on the speech sequence to be recognized to obtain a mapped speech sequence.
[0136] Exemplarily, the first feedforward network layer module can be used to perform feature mapping processing on each speech feature in the speech sequence to be recognized, to obtain the mapped speech features corresponding to each speech feature, and each mapped speech feature constitutes a mapped speech sequence.
[0137] Step 2: Fusing the speech sequence and the mapped speech sequence to obtain a fused speech sequence.
[0138] In a specific implementation, for each speech feature in the speech sequence, the speech feature and the mapped speech feature corresponding to the speech feature in the mapped speech sequence can be fused to obtain a fused speech feature corresponding to the speech feature. Furthermore, the fused speech sequence can be formed by the fused speech features corresponding to each speech feature in the speech sequence.
[0139] For example, the speech sequence to be recognized is X = {x1, x2, x3, ... x T}, the mapped speech sequence X'={x'1,x'2,x'3,……x' T}, where x'1 is the mapped speech feature corresponding to x1, x'2 is the mapped speech feature corresponding to x2, x'3 is the mapped speech feature corresponding to x3, and so on. TFor x T After the sequence fusion, x1 and x'1 can be fused to obtain the fused speech feature x"1 corresponding to x1, x2 and x'2 can be fused to obtain the fused speech feature x"2 corresponding to x2, x3 and x'3 can be fused to obtain the fused speech feature x"3 corresponding to x3, and so on. T and x' T Fusion, get x T The corresponding fused speech feature x" T . Then, the obtained fused speech sequence X”={x”1,x”2,x”3,……x” T}.
[0140] Step 3: Use the target feature matrix to perform feature mapping processing on the fused speech sequence to obtain the query matrix, key matrix and value matrix corresponding to the speech sequence; wherein the query matrix, key matrix and value matrix correspond to different target feature matrices respectively.
[0141] Here, the number of features included in each of the query matrix, the key matrix, and the value matrix is consistent with the number of fused speech features in the fused speech sequence. Exemplarily, the number of fused speech features in the fused speech sequence is T, and the number of features included in each of the query matrix, the key matrix, and the value matrix is also T.
[0142] Specifically, the query matrix is a matrix obtained by performing feature mapping processing on the fused speech sequence using the preset first target feature matrix corresponding to the matrix. The query matrix can be represented by Query, and the initial query features in Query are used to represent the feature information of the fused speech features themselves.
[0143] The key matrix is a matrix obtained by performing feature mapping processing on the fused speech sequence using the preset second target feature matrix corresponding to the matrix. The key matrix can be represented by Key, and the initial key features in Key are used to characterize the feature information after feature extraction in a feature direction of the fused speech features. The initial key features in Key are used to match the initial query features.
[0144] The value matrix is a matrix obtained by performing feature mapping processing on the fused speech sequence using the preset third target feature matrix corresponding to the matrix. The value matrix can be represented by Value, and the target value feature in Value is used to characterize the feature information after feature extraction of the fused speech features in another feature direction. The target value feature in Value is used to determine the attention feature corresponding to each speech feature in the speech sequence to be recognized.
[0145] In a specific implementation, after obtaining the fused speech sequence, the fused speech sequence can be input into a cosine-based self-attention module (hereinafter referred to as CBSA module) in a speech recognition neural network. The CBSA module executes the steps of performing feature mapping processing on the fused speech sequence using a preset target feature matrix, and finally obtains a query matrix, a key matrix and a value matrix corresponding to the speech sequence.
[0146] Optionally, after obtaining the speech sequence to be recognized, the speech sequence to be recognized can also be directly input into the CBSA module, and the CBSA module executes the steps of performing feature mapping processing on the speech sequence to be recognized using a preset target feature matrix, and finally obtains the query matrix, key matrix and value matrix corresponding to the speech sequence.
[0147] The first cosine weight is used to perform weighted processing on the target query feature corresponding to the initial query feature in the query matrix. The target query feature is obtained by converting the initial query feature using a preset target kernel function. The first cosine weight of each initial query feature is used to perform weighted processing on the target query feature corresponding to the initial query feature. The second cosine weight is used to perform weighted processing on the target key feature corresponding to the initial key feature in the key matrix. The target key feature is obtained by converting the initial key feature using a preset target kernel function. The second cosine weight of each initial key feature is used to perform weighted processing on the target key feature corresponding to the initial key feature.
[0148] In a specific implementation, the first cosine weight corresponding to the initial query feature can be determined according to the number of speech features in the speech sequence to be recognized and the first ranking value of the initial query feature in the query matrix. Specifically, the first cosine weight corresponding to each initial query feature can be determined according to the following formula 1:
[0149]
[0150] Here, i represents the first ranking value corresponding to the initial query feature in the query matrix, for example, the first ranking value of the initial query feature 1 in the query matrix is 1, the first ranking value of the initial query feature 2 in the query matrix is 2, etc. M represents the number of speech features.
[0151] Based on the above formula 1, the first cosine weight corresponding to each initial query feature can be determined respectively.
[0152] Similarly, the second cosine weight corresponding to the initial key feature can be determined according to the number of speech features and the second ranking value of the initial key feature in the key matrix. Specifically, the second cosine weight corresponding to each initial key feature can be determined according to the following formula 2:
[0153]
[0154] Wherein, j represents the second ranking value corresponding to the initial key feature in the key matrix, for example, the second ranking value of the initial key feature 1 in the key matrix is 1, the second ranking value of the initial key feature 2 in the key matrix is 2, etc. M represents the number of speech features.
[0155] Based on the above formula 2, the second cosine weight corresponding to each initial key feature can be determined respectively.
[0156] In addition, for the step of determining the first cosine weight of each initial query feature, after determining the query matrix, the first cosine weight corresponding to each initial query feature can be directly determined according to the number of speech features in the speech sequence and the first ranking value of each initial query feature in the query matrix. That is, the first cosine weight corresponding to each initial query feature is uniformly determined after determining the query matrix, and is directly obtained when used later. Alternatively, before specifically calculating the similarity between an initial query feature and each initial key feature, the first cosine weight corresponding to the initial query feature can be determined based on the first ranking value of the initial query feature in the query matrix and the number of speech features. That is, the first cosine weight corresponding to each initial query feature can be determined when it is used, and is not uniformly determined in advance. The timing of determining each first cosine weight can be set according to the actual needs of speech recognition, and is not limited here.
[0157] Regarding the step of determining the second cosine weight of each initial key feature, after determining the key matrix, the second cosine weight corresponding to each initial key feature can be directly determined according to the number of speech features in the speech sequence and the second ranking value of each initial key feature in the key matrix. That is, the second cosine weight corresponding to each initial key feature is uniformly determined after determining the key matrix, and directly obtained for subsequent use. Alternatively, when the second cosine weight corresponding to an initial key feature is specifically used, the second cosine weight corresponding to the initial key feature can be determined and used according to the number of speech features and the second ranking value of the initial key feature in the key matrix, without being uniformly determined in advance. The timing of determining each first cosine weight can be set according to the actual needs of speech recognition, and is not limited here.
[0158] S102: Determine the similarity between each initial query feature and each initial key feature based on the first cosine weight and the second cosine weight.
[0159] Here, similarity is used to characterize the matching degree between the initial query features and the initial key features.
[0160] In specific implementation, when determining the similarity between the initial query feature and the initial key feature, the first cosine weight corresponding to the initial query feature can be used to weight the target query feature corresponding to the initial query feature to obtain a weighted result. At the same time, the second cosine weight corresponding to the initial key feature can be used to weight the target key feature corresponding to the initial key feature to obtain a weighted result. Afterwards, based on the two weighted results, the similarity between the initial query feature and the initial key feature is determined.
[0161] In this way, based on the first cosine weight and the target query feature corresponding to each initial query feature, and the second cosine weight and the target key feature corresponding to each initial key feature, the similarity between each initial query feature and each initial key feature can be determined.
[0162] In one embodiment, S102 may be implemented according to the following steps:
[0163] S102-1: using any target kernel function among a plurality of preset kernel functions, convert each initial query feature into a non-negative target query feature, and convert each initial key feature into a non-negative target key feature.
[0164] Here, the preset multiple kernel functions may include the following three kernel functions:
[0165] (Kernel function 1)
[0166] in,
[0167] (Kernel function 2)
[0168] (Kernel function three)
[0169] in,
[0170] Above Represents the kernel function, and x represents the initial query feature or the initial key feature. Kernel function one corresponds to the fastest speech recognition speed, kernel function three corresponds to the best speech recognition effect, and kernel function two corresponds to the slowest recognition speed. Any of the above three kernel functions can be used as the target kernel function. Specifically, regarding the use of the target kernel function, it can be selected according to the actual needs of speech recognition. For example, when it is necessary to increase the recognition speed, kernel function one can be selected as the target kernel function. When it is necessary to ensure the best recognition effect, kernel function three can be selected as the target kernel function. When the recognition speed is not considered, kernel function two can be selected as the target kernel function.
[0171] According to the function characteristics corresponding to the above three kernel functions, each kernel function does not have negative values. Therefore, when any of the above kernel functions is selected as the target kernel function and the initial query feature and the initial key feature are transformed using the target kernel function, the target query feature and the target key feature obtained are both non-negative. Subsequently, the matrix composed of each target query feature obtained by the transformation will also be a non-negative matrix, and the matrix composed of each target key feature obtained by the transformation will also be a non-negative matrix.
[0172] Exemplarily, when the target kernel function is the kernel function 1, each initial query feature in the query matrix can be substituted into the kernel function 1 to obtain the target query feature corresponding to each initial query feature. At the same time, each initial key feature in the key matrix can be substituted into the kernel function 1 to obtain the target key feature corresponding to each initial key feature.
[0173] S102-2: Determine a first weighted result corresponding to each initial key feature based on the second cosine weight corresponding to each initial key feature and the target key feature corresponding to the initial key feature.
[0174] Exemplarily, for each initial key feature, the second cosine weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature may be multiplied together, and the result obtained after the multiplication is used as the first weighted result corresponding to the initial key feature.
[0175] S102-3: For each initial query feature, based on the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature, determine the second weighted result corresponding to the initial query feature; and based on the second weighted result and the first weighted result corresponding to each initial key feature, determine the similarity between the initial query feature and each initial key feature.
[0176] In specific implementation, for each initial query feature, the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature may be multiplied together, and the result obtained after the multiplication is used as the second weighted result corresponding to the initial query feature.
[0177] Afterwards, for the initial query feature and any initial key feature, the second weighted result corresponding to the initial query feature and the transpose of the first weighted result corresponding to the initial key feature may be multiplied together, and based on the result obtained after the multiplication, the similarity between the initial query feature and the initial key feature may be determined.
[0178] In one embodiment, the step of determining the similarity between the initial query feature and each initial key feature based on the second weighted result and each initial key feature corresponding to the first weighted result in S102-3 can be implemented according to the following steps:
[0179] S102-3-1: Determine the first sinusoidal weight corresponding to the initial query feature based on the first ranking value of the initial query feature in the query matrix and the number of speech features, and determine the second sinusoidal weight corresponding to each initial key feature based on the second ranking value of each initial key feature in the key matrix.
[0180] Here, the first ranking value is determined by the position of the initial query feature in the query matrix. For example, if the initial query feature is the first element in the query matrix, the first ranking value corresponding to the initial query feature is 1. For another example, if the initial query feature is the i-th element in the query matrix, the first ranking value corresponding to the initial query feature is i. The second ranking value is determined by the position of the initial key feature in the key matrix.
[0181] The first sinusoidal weight is used to perform weighted processing on the target query feature corresponding to the initial query feature. The second sinusoidal weight is used to perform weighted processing on the target key feature corresponding to the initial key feature.
[0182] In specific implementation, the first sinusoidal weight corresponding to each initial query feature can be determined according to the following formula 3:
[0183]
[0184] Wherein, i represents the first ranking value corresponding to the initial query matrix, and M represents the number of speech features in the speech sequence to be recognized.
[0185] Based on the above formula 3 and the first ranking value corresponding to each initial query feature, the first sinusoidal weight corresponding to each initial query feature can be determined.
[0186] At the same time, the second sinusoidal weight corresponding to each initial key feature can be determined according to the following formula 4:
[0187]
[0188] Among them, j represents the second sort value corresponding to the initial key feature.
[0189] Based on the above formula 4, the second sinusoidal weights corresponding to the respective initial key features can be determined respectively.
[0190] S102-3-2: Determine a third weighted result corresponding to the initial query feature based on the first sinusoidal weight and the target query feature corresponding to the initial query feature.
[0191] For each initial query feature, the first sinusoidal weight corresponding to the initial query feature and the target query feature corresponding to the initial query feature may be multiplied together to obtain a third weighted result corresponding to the initial query feature.
[0192] S102-3-3: For each initial key feature, based on the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature, determine a fourth weighted result corresponding to the initial key feature.
[0193] Here, for the initial key feature, the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature may be multiplied together to obtain a fourth weighted result corresponding to the initial key feature.
[0194] S102-3-4: Determine the similarity between the initial query feature and each initial key feature based on the second weighted result, the third weighted result, the first weighted result corresponding to each initial key feature, and the fourth weighted result.
[0195] Here, for each initial query feature and any initial key feature, the second weighted result corresponding to the initial query feature and the transpose of the first weighted result corresponding to the initial key feature can be multiplied, and the third weighted result corresponding to the initial query feature and the transpose of the fourth weighted result corresponding to the initial key feature can be multiplied, and the results of the two multiplications can be added to obtain the similarity between the initial query feature and the initial key feature.
[0196] In specific implementation, the similarity between any initial query feature and any initial key feature can be determined according to the following formula 5:
[0197]
[0198] Among them, i represents the first ranking value, j represents the second ranking value, and Q i represents the i-th initial query feature in the query matrix Q, K j represents the jth initial bond feature in the bond matrix K, represents the transpose of the jth initial key feature, represents the similarity between the i-th initial query feature and the j-th initial key feature. The maximum values of i and j are the number of speech features in the speech sequence to be recognized. Q' i It represents the i-th target query feature obtained by transforming the i-th initial query feature using the target kernel function. represents the first cosine weight corresponding to the i-th initial query feature, Indicates the second weighted result corresponding to the i initial query features, K' j It means the jth target key feature obtained by transforming the jth initial key feature using the target kernel function. represents the second cosine weight corresponding to the jth initial key feature, represents the first weighted result corresponding to the jth initial key feature, Represents the transpose of the first weighted result. represents the first sine weight corresponding to the i-th initial query feature, represents the third weighted result corresponding to the i-th initial query feature, represents the second sine weight corresponding to the jth initial key feature, represents the fourth weighted result corresponding to the j-th initial key feature, Represents the transpose of the fourth weighted result.
[0199] In specific implementation, the above formula 5 and the target kernel function can be used to determine the similarity between any initial query feature and any initial key feature.
[0200] Regarding the above formula 5, it can be calculated according to the following process:
[0201] First, the attention feature corresponding to each speech feature can be obtained according to the following formula 6:
[0202]
[0203] Among them, K j represents the jth initial bond feature in the bond matrix, V j represents the jth target value feature in the value matrix, where the initial key feature and the target value feature can form a key-value pair and be used in pairs. For example, in the above formula 6, K j When V is the fifth initial bond feature in the bond matrix, j It is also the fifth target value feature in the value matrix. represents the transpose of the jth initial key feature, O in O T The number of is consistent with the number of speech features in the speech sequence to be recognized. i Represents the attention feature corresponding to the i-th speech feature in the speech sequence to be recognized. represents the similarity between the i-th initial query feature and the j-th initial key feature.
[0204] Will Expressed as That is, another Then Formula 6 can be rewritten as the following Formula 7:
[0205]
[0206] Furthermore, in order to avoid the problem of large amount of calculation caused by directly multiplying the query matrix and the key matrix, the query matrix and the key matrix can be processed separately by using the target kernel function to avoid directly multiplying the query matrix and the key matrix. Specifically, the target kernel function can be used to process Decompose it and get the following formula eight:
[0207]
[0208] in, represents the target kernel function, It represents the target query feature obtained after transforming the i-th initial query feature using the target kernel function. It represents the target key feature obtained after transforming the j-th initial key feature using the target kernel function. Represents the transpose of the target key features corresponding to the j initial key features.
[0209] Furthermore, according to Formula 8 and Formula 7, Formula 7 is rewritten to obtain Formula 9:
[0210]
[0211] The normalization operation (softmax) plays an important role in the attention mechanism, which ensures that the query matrix and the key matrix are non-negative and provides a nonlinear reweighting mechanism to describe the global context information corresponding to each speech feature. i Approximate to the similarity O determined by softmax i , can be achieved by introducing the cosine function in formula eight. Specifically, by introducing the cosine function in calculating the similarity O i When introducing nonlinear re-weighting, the calculated similarity O i Approximate to the similarity O determined by softmax i , after introducing the cosine function, Formula 8 can be converted into the following Formula 10:
[0212]
[0213] Afterwards, any target kernel function selected from the above kernel function one, kernel function two or kernel function three can be substituted into the above formula ten.
[0214] For example, taking the target kernel function as kernel function 1 as an example, after substituting kernel function 1 into the above formula 10, the following formula 11 can be obtained:
[0215]
[0216] Let ReLU(Q i )=Q' i , ReLU(K j )=K' j , T=M, and the cosine function is split, formula 11 can be converted into the following formula 12:
[0217]
[0218] By transforming the formula 12, we can get the following conclusion:
[0219]
[0220] That is, based on Formula 6 to Formula 12, the above Formula 5 is converted. Based on the above Formula 5 and the target kernel function, the similarity between each initial query feature and each initial key feature can be calculated.
[0221] In addition, when the target kernel function is kernel function 2, you can set When the target kernel function is kernel function 3, sigmoid(Q i )=Q' i Regarding the subsequent process of obtaining the above formula 5, reference can be made to the description of the target kernel function being the kernel function 1, which will not be repeated here.
[0222] S103: For each speech feature in the speech sequence, determine the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each initial key feature, and each target value feature in the value matrix corresponding to the speech sequence.
[0223] For example, for each speech feature in the speech sequence, the initial query feature Q corresponding to the speech feature may be i With each initial bond feature K j Similarity between The target query feature corresponding to the speech feature and the transpose of each target key feature And each target value feature V j , Substitute into the above formula 9 to obtain the attention feature corresponding to the speech feature.
[0224] In one embodiment, S103 may be implemented as follows:
[0225] S103-1: For each initial key feature, based on the first weighted result corresponding to the initial key feature and the target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature, determine the first intermediate result corresponding to the initial key feature.
[0226] S103-2: Determine a second intermediate result corresponding to the initial key feature based on the fourth weighted result corresponding to the initial key feature and a target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature.
[0227] S103-3: multiplying the second weighted result corresponding to the initial query feature and the first intermediate result corresponding to each of the initial key features to obtain a fifth weighted result;
[0228] S103-4: multiplying the third weighted result corresponding to the initial query feature and the second intermediate result corresponding to each of the initial key features to obtain a sixth weighted result;
[0229] S103-5: Determine the attention feature corresponding to the voice feature based on the sum of the similarities between the initial query feature corresponding to the voice feature and each of the initial key features, the sum of the fifth weighted results, and the sum of the sixth weighted results.
[0230] Here, the third ranking value is determined by the position of the target value feature in the value matrix. For example, if the target value feature is the first element in the value matrix, the third ranking value corresponding to the target value feature is 1.
[0231] In specific implementation, for the above S103-1 to S103-5, after obtaining the above formula 5, the formula 5 can be replaced by make make make Then Formula 5 can be simplified to Formula 13:
[0232]
[0233] After that, based on Formula 13 and Formula 7, we can get Formula 14 corresponding to the attention function:
[0234]
[0235] in, represents the first weighted result corresponding to the jth initial key feature, represents the transpose of the first weighted result corresponding to the jth initial key feature, V j represents the jth target value feature, represents the fourth weighted result corresponding to the j-th initial key feature, represents the transpose of the fourth weighted result corresponding to the j-th initial key feature, represents the first intermediate result corresponding to the jth initial key feature, represents the second weighted result corresponding to the i-th initial query feature,
[0236] represents the third weighted result corresponding to the i-th initial query feature, represents the fifth weighted result corresponding to the i-th initial query feature, represents the sixth weighted result corresponding to the i-th initial query feature. represents the i-th initial query feature Q i The sum of similarities with each initial key feature, represents the sum of the fifth weighted results corresponding to the i-th initial query feature, represents the sum of the sixth weighted results corresponding to the i-th initial query feature. In this way, based on the above formula 14, each speech feature x can be determined separately. i The corresponding attention feature O i .
[0237] For example, the speech sequence to be recognized is X={x1, x2, x3, ... x T}, the speech features are x1~x T , then the attention feature corresponding to x1 is O1, the attention feature corresponding to x2 is O2, and so on. T The corresponding attention feature is O T .
[0238] Furthermore, the above formula 14 can be simplified by the following formula 15:
[0239]
[0240] For example, if the query matrix and the key matrix are both T times d matrices, the amount of calculation required to directly multiply the transpose matrix of the query matrix and the key matrix is T^2×d, and the amount of calculation required to calculate the attention feature based on the above formula 14 will be reduced to T×d^2. Therefore, when recognizing long speech sequences based on formula 14, the calculation pressure will be reduced, the recognition time will also be reduced, and the recognition speed will be effectively improved.
[0241] In specific implementation, the steps of determining the attention features corresponding to each speech feature can be performed using the CBSA module in the trained speech recognition neural network, and finally the CBSA module outputs the attention features corresponding to each speech feature.
[0242] S104: Determine a speech recognition result corresponding to the speech sequence based on the attention features corresponding to each speech feature in the speech sequence.
[0243] Here, the speech recognition result is the text result output after the speech sequence to be recognized is recognized. For example, the speech sequence to be recognized X = {x1, x2, x3, ... x T}, the speech recognition result corresponding to the speech sequence can be Y = {y1, x2, x3, ... y U}, where T>>U. Here, y1~y UThey represent different recognized text results. One text result can be determined by multiple speech features. Therefore, Y is much larger than U, that is, the number of speech features is much larger than the number of text results. In addition, due to the influence of speech speed, there is no strict quantitative mapping relationship between text results and speech features.
[0244] In specific implementation, after obtaining the attention features corresponding to each speech feature, the speech recognition neural network can further perform feature analysis on each attention feature, thereby determining the speech recognition result corresponding to the speech sequence.
[0245] The speech recognition method in the embodiment of the present disclosure can be applied in multiple scenarios such as smart cabin scenarios, voice customer service scenarios, and audit scenarios. For example, in the smart cabin scenario, the smart cabin can obtain the voice clip narrated by the driver, and use the above-mentioned speech recognition method to recognize the voice clip, and determine that the speech recognition result corresponding to the voice clip indicates to stop driving after driving 500 meters, then the smart cabin can control the vehicle to stop driving after controlling the vehicle to drive 500 meters. For another example, in the voice customer service scenario, a speech recognition robot deployed with the above-mentioned speech recognition method can be used to obtain the customer's voice clip, and use the above-mentioned speech recognition method to recognize the voice clip, and determine that the speech recognition result corresponding to the voice clip is: I want to query the bill information of this account, then the speech recognition robot can broadcast the bill information to the customer according to the speech recognition result. For another example, in the audit scenario, an audit robot deployed with the above-mentioned speech recognition method can be used to obtain the customer's voice clip, and use the above-mentioned speech recognition method to recognize the voice clip, and determine that the voice recognition result corresponding to the voice clip indicates that the voice verification code is 1234, then the voice verification code can be used to determine whether the user has the authority to enter the target area. The disclosed embodiment directly determines the attention feature mode corresponding to each speech feature based on the cosine weight, omitting the step of directly multiplying multiple attention matrices, reducing the amount of calculation and improving the speed of speech recognition. In addition, the reduction in the amount of calculation will reduce the calculation pressure when recognizing long speech sequences, and the time for recognizing long speech sequences will also be reduced, effectively improving the recognition speed of recognizing long speech sequences.
[0246] In one embodiment, S104 may be implemented according to the following steps:
[0247] S104-1: Fusing each speech feature in the fused speech sequence with the attention feature corresponding to the speech feature to obtain each fused attention feature.
[0248] Here, the fused speech sequence is a speech sequence obtained by sequentially fusion of the speech sequence to be recognized and the mapped speech sequence output by the first feedforward network layer module.
[0249] After obtaining the attention features corresponding to each speech feature, for the attention features corresponding to each speech feature, the attention features corresponding to the speech feature and the fused speech features corresponding to the speech feature in the fused speech sequence can be fused to obtain each fused attention feature. The number of fused attention features is consistent with the number of speech features in the speech sequence to be recognized, and the fused attention features correspond one-to-one to the speech features in the speech sequence to be recognized.
[0250] S104-2: Perform convolution operation on each fused attention feature to obtain each convolved attention feature, and perform feature fusion on each convolved attention feature and the fused attention feature corresponding to the attention feature to obtain the initial attention feature corresponding to each convolved attention feature.
[0251] In specific implementation, each fused attention feature can be input into the convolution module in the speech recognition neural network, and the convolution module is used to perform convolution operation on each fused attention feature to obtain each convolved attention feature. Then, each convolved attention feature and the fused attention feature corresponding to the attention feature are subjected to feature fusion to obtain the initial attention feature corresponding to each convolved attention feature.
[0252] The number of the initial attention features is consistent with the number of speech features in the speech sequence to be recognized, and the initial attention features correspond one-to-one to the speech features in the speech sequence to be recognized.
[0253] S104-3: Perform a spatial mapping operation on each initial attention feature to obtain each mapped initial attention feature, and perform feature fusion on each initial attention feature and the mapped initial attention feature corresponding to the initial attention feature to obtain each fused initial attention feature.
[0254] In specific implementation, each initial attention feature can be input into the second feedforward network layer module (Feed Forward Module) in the speech recognition neural network, and the second feedforward network layer module can be used to perform spatial mapping operations on each initial attention feature to obtain each mapped initial attention feature. Afterwards, each initial attention feature and the mapped initial attention feature corresponding to the initial attention feature can be feature fused to obtain each fused initial attention feature.
[0255] S104-4: Perform a normalization operation on each fused initial attention feature to obtain an intermediate attention feature corresponding to each speech feature, and determine the speech recognition result corresponding to the speech sequence based on each intermediate attention feature.
[0256] In specific implementation, each fused initial attention feature can be input into the normalization layer (LayerNorm) in the speech recognition neural network, and LayerNorm is used to perform normalization operations on each fused initial attention feature to obtain the intermediate attention features corresponding to each fused initial attention feature. Since each fused initial attention feature corresponds one-to-one to the speech feature in the speech sequence to be recognized, the intermediate attention features corresponding to each speech feature in the speech sequence to be recognized are obtained.
[0257] Furthermore, the speech recognition neural network can directly analyze the intermediate attention features to determine the speech recognition results corresponding to the speech sequence.
[0258] Among them, the first feedforward network layer module, CBSA module, convolution module, second feedforward network layer module and normalization layer are all modules of the encoder in the speech recognition neural network. That is, after obtaining the speech sequence to be recognized, the speech sequence to be recognized can be input into the encoder, and each module in the encoder can output the speech recognition result corresponding to the speech sequence to be recognized based on the speech sequence to be recognized.
[0259] Alternatively, in another embodiment, after obtaining each intermediate attention feature, the sequence composed of each intermediate attention feature can be used as a new speech sequence to be recognized, and each intermediate attention feature can be used as an individual speech feature in the new speech sequence to be recognized.
[0260] Afterwards, return to the step of performing a spatial mapping operation on the speech sequence to obtain a mapped speech sequence, until the number of loops reaches a preset number, and each target attention feature corresponding to the speech sequence to be recognized is obtained.
[0261] Here, the preset number of times is determined according to the number of encoders included in the speech recognition neural network. The number of encoders can be set according to development requirements and is not limited here.
[0262] Exemplarily, the speech recognition neural network may include 12 encoders. The structure of each encoder is consistent, including the first feedforward network layer module, CBSA module, convolution module, second feedforward network layer module and normalization layer. For each encoder, the corresponding convolution kernel is 31, the model size is 256, and the two feedforward network layer modules have 2048 forward layers. The dropout rate corresponding to each layer can be set to 0.1.
[0263] After using the first encoder to output each intermediate attention feature, the output of the first encoder can be used as the input of the second encoder, and the second encoder is used to process the input to obtain each intermediate attention feature output by the second encoder, and then each intermediate attention feature output by the second encoder is used as the input of the third encoder, and so on, each intermediate attention feature output by the twelfth encoder can be used as each target attention feature corresponding to the speech sequence to be recognized. Among them, one target attention feature corresponds to one speech feature in the speech sequence to be recognized.
[0264] Finally, the speech recognition result can be determined based on each target attention feature output.
[0265] For example, a speech recognition neural network can directly parse each target attention feature of the output and determine the speech recognition result based on the parsing result.
[0266] In this way, by using multiple decoders to perform multiple decoding operations, the information represented by each speech feature can be fully extracted, thereby obtaining a target attention feature containing rich information. Using each target attention feature for speech recognition can improve the accuracy of the determined speech recognition result.
[0267] Alternatively, after obtaining each target attention feature, at least one preset decoding module can be used to perform feature decoding on each target attention feature to obtain a speech recognition result; wherein, the input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the last decoding module in the decoding order is the speech recognition result.
[0268] Here, the decoding module may specifically be a transformer decoder. The number of decoding modules may be set according to actual speech recognition needs and is not limited here.
[0269] Exemplarily, the speech recognition neural network can be deployed with 6 decoding modules, and each decoding module corresponds to a different decoding order. The input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the last decoding module in the decoding order is the speech recognition result.
[0270] For example, after the twelfth Encoder outputs each target attention feature, each target attention feature can be input into the first decoding module with a decoding order of 1, and the first decoding module can be used to perform feature decoding on each target attention feature respectively to obtain and output the decoding feature corresponding to each target attention feature. Then, the output of the first decoding module can be used as the input to the second decoding module with a decoding order of 2, and the second decoding module can be used to further decode each decoding feature to obtain the output of the second decoding module. The output of the second module can then be used as the input to the third decoding module with a decoding order of 3, and so on. The output of the sixth decoding module with a decoding order of 6 is used as the final speech recognition result.
[0271] In this way, using multiple decoding modules for decoding can fully decode the information represented by each target attention feature, thereby obtaining accurate speech recognition results.
[0272] like Figure 2 As shown, it is a schematic diagram of the structure of a speech recognition neural network provided by an embodiment of the present disclosure, wherein N represents the number of encoders in the speech recognition neural network, and M represents the number of transformer decoders in the speech recognition neural network. The specific structure of the encoder can be shown in the dotted box.
[0273] When the speech recognition neural network includes an Encoder and a Transformer Decoder, after the speech sequence to be recognized is input into the speech recognition neural network, the Encoder and Transformer Decoder in the speech recognition neural network can be used to process the speech sequence to be recognized, and finally the Transformer Decoder outputs the speech recognition result.
[0274] Alternatively, when only the encoder is included in the speech recognition neural network, the speech recognition result can be output directly based on the target attention features after the last encoder outputs the target attention features corresponding to the speech sequence to be recognized. Whether the speech recognition neural network needs to include a transformer decoder can be determined according to the actual speech recognition needs, and the embodiments of the present disclosure do not limit this.
[0275] In one embodiment, since the speech recognition method provided by the embodiment of the present disclosure can be performed using a trained speech recognition neural network, the embodiment of the present disclosure also provides a method for training a speech recognition neural network, such as Figure 3 As shown, it is a flowchart of a method for training a speech recognition neural network to be trained provided by an embodiment of the present disclosure, which may include the following steps:
[0276] S301: Obtain a sample speech sequence to be recognized.
[0277] Here, the sample speech sequence to be recognized may include multiple sample speech features.
[0278] S302: Inputting the sample speech sequence into the speech recognition neural network to be trained, and using the speech recognition neural network to be trained to perform recognition processing on the sample speech sequence to determine each target prediction attention feature corresponding to the sample speech sequence.
[0279] Here, one target prediction attention feature corresponds to one sample speech feature, the number of target attention features is consistent with the number of sample speech features, and the target prediction attention feature is a prediction feature corresponding to the sample speech feature output after the speech recognition neural network to be trained recognizes and processes the sample speech feature.
[0280] Specifically, each target prediction attention feature may be the output of the last Encoder in the speech recognition neural network to be trained.
[0281] S303: Determine the predicted speech result corresponding to the sample speech sequence based on each target predicted attention feature.
[0282] Here, the predicted speech result is the predicted text result output after recognizing the sample speech sequence.
[0283] In specific implementation, feature analysis can be performed on each target predicted attention feature respectively, and the predicted speech result corresponding to the sample speech sequence can be determined based on the analysis result.
[0284] S304: Based on the predicted speech result and the standard speech result corresponding to the sample speech sequence, determine the prediction loss corresponding to the speech recognition neural network to be trained, and use the prediction loss to iteratively train the speech recognition neural network to be trained until the training cutoff condition is met to obtain a trained speech recognition neural network.
[0285] Here, the standard speech result is the real label corresponding to the sample speech sequence. The training cutoff condition may be that the number of iterative training rounds reaches a preset number of rounds and / or the preset accuracy of the trained speech recognition neural network reaches a preset accuracy.
[0286] In specific implementation, the prediction loss of the speech recognition neural network to be trained during speech recognition can be determined based on the predicted speech results and the standard speech results, and then the prediction loss can be used to iteratively train the speech recognition neural network to be trained. When the training cutoff condition is met, the trained speech recognition neural network is used as the final trained speech recognition neural network.
[0287] In one embodiment, the predicted speech result may include a first predicted speech result, and the prediction loss may include a temporal classification loss.
[0288] Here, the first predicted speech result may be a predicted speech result obtained by directly processing the target predicted attention feature by the speech recognition neural network to be trained.
[0289] In specific implementation, when the target neural network to be trained does not include a Transformer Decoder, after the last Encoder in the speech recognition neural network to be trained outputs each target predicted attention feature corresponding to the sample speech sequence, the speech recognition neural network to be trained can directly parse and process each target predicted attention feature and output the first predicted speech result corresponding to the sample speech sequence.
[0290] Furthermore, the temporal classification loss may be a prediction loss calculated without including a decoding module (specifically, TransformerDecoder). The temporal classification loss may also be referred to as a CTC loss. Specifically, a neural network may be used to connect a temporal classification CTC algorithm, and the temporal classification loss may be determined based on the first predicted speech result and the standard speech result.
[0291] CTC: Connectionist temporal classification, neural network connection temporal classification, is an algorithm commonly used in speech recognition, text recognition and other fields. It is used to solve the problem that the sequence corresponding to the first predicted speech result and the sequence corresponding to the standard speech result are of different lengths and cannot be aligned. It can actually be used as the prediction loss corresponding to the speech recognition neural network to be trained.
[0292] In specific implementation, the CTC algorithm can be used to process the first predicted speech result and the standard speech result to obtain the time series classification loss, and the CTC criterion can be used to optimize the time series classification loss to obtain the optimized time series classification loss.
[0293] Afterwards, the optimized temporal classification loss can be used to iteratively train the speech recognition neural network to be trained until the training cutoff condition is met to obtain a trained speech recognition neural network.
[0294] In another embodiment, the predicted speech result may further include a second predicted speech result, and the prediction loss may further include a cross entropy loss. The cross entropy loss may be a prediction loss calculated when a decoding module (specifically, a TransformerDecoder) is included. The cross entropy loss may also be referred to as a CE loss, where CE: CrossEntropy.
[0295] Here, when the target neural network to be trained includes at least one decoding module (specifically, a Transformer Decoder), at least one decoding module preset in the speech recognition neural network to be trained can be used to perform feature decoding on each target predicted attention feature to obtain a second predicted speech result.
[0296] Exemplarily, after the last Encoder in the speech recognition neural network to be trained outputs each target prediction attention feature corresponding to the sample speech sequence, each target prediction attention feature can be input into the first Transformer Decoder, processed by the first Transformer Decoder to obtain the output of the first Transformer Decoder, and then the output of the first Transformer Decoder is used as the input of the second Transformer Decoder, and so on, and the output of the last Transformer Decoder is used as the second predicted speech result.
[0297] Then, the cross entropy loss corresponding to the speech recognition neural network to be trained can be determined based on the second predicted speech result and the standard speech result.
[0298] Finally, the speech recognition neural network to be trained can be iteratively trained using the cross entropy loss until the training cutoff condition is met to obtain a trained speech recognition neural network. Alternatively, the speech recognition neural network to be trained can be iteratively trained using the cross entropy loss and the temporal classification loss together to obtain a trained speech recognition neural network when the training cutoff condition is met.
[0299] Here, if the cross entropy loss and the temporal classification loss are used to iteratively train the speech recognition neural network to be trained, when the trained speech recognition neural network is used in a specific application, after the last Encoder in the speech recognition neural network outputs the predicted target attention feature, the target attention feature can be directly used to determine the speech recognition result; or the target attention feature can be feature decoded by the Transformer Decoder to determine the speech recognition result, which is not specifically limited here.
[0300] like Figure 4 As shown, it is a schematic diagram of determining the prediction loss corresponding to the speech recognition neural network to be trained provided by an embodiment of the present disclosure, wherein N represents the number of encoders in the speech recognition neural network to be trained, and M represents the number of transformer decoders in the speech recognition neural network to be trained.
[0301] In the case where the speech recognition neural network to be trained includes an encoder, after the last encoder outputs each target predicted attention feature corresponding to the sample speech sequence, the first predicted speech result corresponding to the sample speech sequence can be determined directly based on each target predicted attention feature. Afterwards, the temporal classification loss (CTC loss) corresponding to the speech recognition neural network to be trained can be determined based on the first predicted speech result and the standard speech result corresponding to the sample speech sequence.
[0302] In the case where the speech recognition neural network to be trained includes an Encoder and a Transformer Decoder, after the sample speech sequence is input into the speech recognition neural network to be trained, the Encoder and the Transformer Decoder in the speech recognition neural network can be used to process the sample speech sequence, and finally the Transformer Decoder outputs the second predicted speech result corresponding to the sample speech sequence. Furthermore, the cross entropy loss (CE loss) corresponding to the speech recognition neural network to be trained can be determined based on the second predicted speech result and the standard speech result corresponding to the sample speech sequence.
[0303] Afterwards, at least one of the CE loss and the CTC loss can be used to iteratively train the speech recognition neural network to be trained until a training cutoff condition is met, thereby obtaining a trained speech recognition neural network.
[0304] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0305] Based on the same inventive concept, a speech recognition device corresponding to the speech recognition method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned speech recognition method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0306] like Figure 5 FIG. 1 is a schematic diagram of a speech recognition device provided by an embodiment of the present disclosure, comprising:
[0307] A first determination module 501 is used to determine, based on the number of speech features in the speech sequence to be recognized, a first cosine weight of each initial query feature in the query matrix corresponding to the speech sequence, and a second cosine weight of each initial key feature in the key matrix corresponding to the speech sequence;
[0308] A second determination module 502, configured to determine the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight;
[0309] A third determination module 503 is used to determine, for each speech feature in the speech sequence, an attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence;
[0310] The fourth determination module 504 is used to determine the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to the various speech features in the speech sequence.
[0311] In a possible implementation manner, the second determination module 502, when determining the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight, is used to convert each of the initial query features into a non-negative target query feature and convert each of the initial key features into a non-negative target key feature using any one of a plurality of preset kernel functions;
[0312] Determine a first weighted result corresponding to each of the initial key features based on a second cosine weight corresponding to each of the initial key features and a target key feature corresponding to the initial key feature;
[0313] For each of the initial query features, based on the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature, determine the second weighted result corresponding to the initial query feature; and based on the second weighted result and the first weighted result corresponding to each of the initial key features, determine the similarity between the initial query feature and each of the initial key features.
[0314] In a possible implementation manner, the second determination module 502, when determining the similarity between the initial query feature and each of the initial key features respectively based on the second weighted result and the first weighted result corresponding to each of the initial key features, is used to determine the first sinusoidal weight corresponding to the initial query feature based on the first ranking value of the initial query feature in the query matrix and the number of the speech features, and to determine the second sinusoidal weight corresponding to each of the initial key features based on the second ranking value of each of the initial key features in the key matrix;
[0315] Determining a third weighted result corresponding to the initial query feature based on the first sinusoidal weight and a target query feature corresponding to the initial query feature;
[0316] For each of the initial key features, based on the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature, determine a fourth weighted result corresponding to the initial key feature;
[0317] Based on the second weighted result, the third weighted result, the first weighted result corresponding to each of the initial key features, and the fourth weighted result, the similarity between the initial query feature and each of the initial key features is determined.
[0318] In a possible implementation, the third determination module 503, when determining the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, is used to determine, for each of the initial key features, the first weighted result corresponding to the initial key feature, and the target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature, to determine the first intermediate result corresponding to the initial key feature;
[0319] Determine a second intermediate result corresponding to the initial key feature based on a fourth weighted result corresponding to the initial key feature and a target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature;
[0320] Multiplying the second weighted result corresponding to the initial query feature and the first intermediate result corresponding to each of the initial key features to obtain a fifth weighted result;
[0321] Multiplying the third weighted result corresponding to the initial query feature and the second intermediate result corresponding to each of the initial key features to obtain a sixth weighted result;
[0322] Based on the sum of the similarities between the initial query feature corresponding to the voice feature and each of the initial key features, the sum of the fifth weighted results, and the sum of the sixth weighted results, the attention feature corresponding to the voice feature is determined.
[0323] In a possible implementation, the device further includes a mapping module 505, which is used to obtain the speech sequence to be recognized, and perform a spatial mapping operation on the speech sequence to obtain the mapped speech sequence before determining the first cosine weight of each of the initial query features in the query matrix corresponding to the speech sequence based on the number of speech features in the speech sequence to be recognized;
[0324] Performing sequence fusion on the speech sequence and the mapped speech sequence to obtain a fused speech sequence;
[0325] The fused speech sequence is subjected to feature mapping processing using the target feature matrix to obtain a query matrix, a key matrix and a value matrix corresponding to the speech sequence; wherein the query matrix, the key matrix and the value matrix correspond to different target feature matrices respectively.
[0326] In a possible implementation, the fourth determination module 504, when determining the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to the respective speech features in the speech sequence, is used to fuse each speech feature in the fused speech sequence with the attention feature corresponding to the speech feature to obtain each fused attention feature;
[0327] Perform convolution operation on each fused attention feature to obtain each convolved attention feature, and perform feature fusion on each convolved attention feature and the fused attention feature corresponding to the attention feature to obtain the initial attention feature corresponding to each convolved attention feature;
[0328] Performing a spatial mapping operation on each of the initial attention features to obtain each mapped initial attention feature, and performing feature fusion on each of the initial attention features and the mapped initial attention feature corresponding to the initial attention feature to obtain each fused initial attention feature;
[0329] A normalization operation is performed on each fused initial attention feature to obtain an intermediate attention feature corresponding to each speech feature, and based on each intermediate attention feature, a speech recognition result corresponding to the speech sequence is determined.
[0330] In a possible implementation, the fourth determination module 504, when determining the speech recognition result corresponding to the speech sequence based on each intermediate attention feature, is used to use the sequence composed of each intermediate attention feature as a new speech sequence to be recognized, and use each intermediate attention feature as each speech feature in the new speech sequence to be recognized;
[0331] Returning to the step of performing a spatial mapping operation on the speech sequence to obtain the mapped speech sequence, until the number of loops reaches a preset number, and obtaining each target attention feature corresponding to the speech sequence to be recognized;
[0332] Based on each of the target attention features, the speech recognition result is determined.
[0333] In one possible implementation, the fourth determination module 504, when determining the speech recognition result based on each of the target attention features, is used to use at least one preset decoding module to perform feature decoding on each of the target attention features to obtain the speech recognition result; wherein the input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the decoding module located last in the decoding order is the speech recognition result.
[0334] In a possible implementation, the speech recognition method is performed using a pre-trained speech recognition neural network;
[0335] The apparatus further comprises: a training module 506, configured to train the speech recognition neural network according to the following steps:
[0336] Obtaining a sample speech sequence to be recognized;
[0337] Inputting the sample speech sequence into a speech recognition neural network to be trained, and using the speech recognition neural network to be trained to perform recognition processing on the sample speech sequence, and determining each of the target prediction attention features corresponding to the sample speech sequence;
[0338] Determining a predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0339] Based on the predicted speech result and the standard speech result corresponding to the sample speech sequence, the prediction loss corresponding to the speech recognition neural network to be trained is determined, and the speech recognition neural network to be trained is iteratively trained using the prediction loss until a training cutoff condition is met, thereby obtaining a trained speech recognition neural network.
[0340] In a possible implementation, the predicted speech result includes a first predicted speech result, and the prediction loss includes a temporal classification loss;
[0341] The training module 506 is used to determine a first predicted speech result corresponding to the sample speech sequence by using each of the target predicted attention features when determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0342] And when determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result, it is used to use the neural network connection temporal classification CTC algorithm to determine the temporal classification loss based on the first predicted speech result and the standard speech result.
[0343] In a possible implementation, the predicted speech result includes a second predicted speech result, and the prediction loss includes a cross entropy loss;
[0344] The training module 506 is used to perform feature decoding on each of the target predicted attention features to obtain the second predicted speech result by using at least one decoding module preset in the speech recognition neural network to be trained when determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features;
[0345] And when determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result, it is used to determine the cross entropy loss based on the second predicted speech result and the standard speech result.
[0346] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0347] Based on the same technical concept, the embodiment of the present application also provides a computer device. Figure 6 FIG. 1 is a schematic diagram of a computer device provided in an embodiment of the present application, including:
[0348] Processor 61, memory 62 and bus 63. The memory 62 stores machine-readable instructions executable by the processor 61, and the processor 61 is used to execute the machine-readable instructions stored in the memory 62. When the machine-readable instructions are executed by the processor 61, the processor 61 performs the following steps: S101: based on the number of speech features in the speech sequence to be recognized, determine the first cosine weight of each initial query feature in the query matrix corresponding to the speech sequence, and the second cosine weight of each initial key feature in the key matrix corresponding to the speech sequence; S102: based on the first cosine weight and the second cosine weight, determine the similarity between each initial query feature and each initial key feature; S103: for each speech feature in the speech sequence, determine the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each initial key feature, and each target value feature in the value matrix corresponding to the speech sequence; and S104: based on the attention features corresponding to each speech feature in the speech sequence, determine the speech recognition result corresponding to the speech sequence.
[0349] The above-mentioned memory 62 includes a memory 621 and an external memory 622; the memory 621 here is also called an internal memory, which is used to temporarily store the calculation data in the processor 61, as well as the data exchanged with the external memory 622 such as a hard disk. The processor 61 exchanges data with the external memory 622 through the memory 621. When the computer device is running, the processor 61 and the memory 62 communicate through the bus 63, so that the processor 61 executes the execution instructions mentioned in the above method embodiment.
[0350] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the speech recognition method described in the above method embodiment are executed. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0351] The computer program product of the speech recognition method provided in the embodiments of the present disclosure includes a computer-readable storage medium storing program code, and the instructions included in the program code can be used to execute the steps of the speech recognition method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0352] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.
[0353] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0354] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0355] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0356] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0357] If the technical solution of this application involves personal information, the product using the technical solution of this application has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using the technical solution of this application has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, the personal information processing rules are notified by obvious signs / information, and the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
[0358] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A speech recognition method, characterized in that: include: Determine a first cosine weight corresponding to each initial query feature according to the number of speech features in the speech sequence to be recognized and a first ranking value of each initial query feature in the query matrix corresponding to the speech sequence, and determine a second cosine weight corresponding to each initial key feature according to the number of speech features and a second ranking value of each initial key feature in the key matrix corresponding to the speech sequence; Based on the first cosine weight and the second cosine weight, determining the similarity between each of the initial query features and each of the initial key features; For each speech feature in the speech sequence, based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, determine the attention feature corresponding to the speech feature; Based on the attention features respectively corresponding to the various speech features in the speech sequence, a speech recognition result corresponding to the speech sequence is determined.
2. The method according to claim 1, characterized in that: The determining, based on the first cosine weight and the second cosine weight, the similarity between each of the initial query features and each of the initial key features, comprises: Using any one of the preset multiple kernel functions as the target kernel function, each of the initial query features is converted into a non-negative target query feature, and each of the initial key features is converted into a non-negative target key feature; Determine a first weighted result corresponding to each of the initial key features based on a second cosine weight corresponding to each of the initial key features and a target key feature corresponding to the initial key feature; For each of the initial query features, based on the target query feature corresponding to the initial query feature and the first cosine weight corresponding to the initial query feature, determine the second weighted result corresponding to the initial query feature; and based on the second weighted result and the first weighted result corresponding to each of the initial key features, determine the similarity between the initial query feature and each of the initial key features.
3. The method according to claim 2, characterized in that The determining, based on the second weighted result and the first weighted result corresponding to each of the initial key features, the similarity between the initial query feature and each of the initial key features, comprises: Determine a first sinusoidal weight corresponding to the initial query feature based on a first ranking value of the initial query feature in the query matrix and the number of the speech features, and determine a second sinusoidal weight corresponding to each initial key feature based on a second ranking value of each initial key feature in the key matrix; Determining a third weighted result corresponding to the initial query feature based on the first sinusoidal weight and a target query feature corresponding to the initial query feature; For each of the initial key features, based on the second sinusoidal weight corresponding to the initial key feature and the target key feature corresponding to the initial key feature, determine a fourth weighted result corresponding to the initial key feature; Based on the second weighted result, the third weighted result, the first weighted result corresponding to each of the initial key features, and the fourth weighted result, the similarity between the initial query feature and each of the initial key features is determined.
4. The method according to claim 3, characterized in that The determining of the attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence, comprises: For each of the initial key features, based on the first weighted result corresponding to the initial key feature and the target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature, determine the first intermediate result corresponding to the initial key feature; Determine a second intermediate result corresponding to the initial key feature based on a fourth weighted result corresponding to the initial key feature and a target value feature whose corresponding third ranking value in the value matrix is the same as the second ranking value corresponding to the initial key feature; Multiplying the second weighted result corresponding to the initial query feature and the first intermediate result corresponding to each of the initial key features to obtain a fifth weighted result; Multiplying the third weighted result corresponding to the initial query feature and the second intermediate result corresponding to each of the initial key features to obtain a sixth weighted result; Based on the sum of the similarities between the initial query feature corresponding to the voice feature and each of the initial key features, the sum of the fifth weighted results, and the sum of the sixth weighted results, the attention feature corresponding to the voice feature is determined.
5. The method according to any one of claims 1 to 4, characterized in that: Before determining the first cosine weight, the method further includes: Acquire the speech sequence to be recognized, and perform a spatial mapping operation on the speech sequence to obtain the mapped speech sequence; Performing sequence fusion on the speech sequence and the mapped speech sequence to obtain a fused speech sequence; The fused speech sequence is subjected to feature mapping processing using the target feature matrix to obtain a query matrix, a key matrix and a value matrix corresponding to the speech sequence; wherein the query matrix, the key matrix and the value matrix correspond to different target feature matrices respectively.
6. The method according to claim 5, characterized in that The determining, based on the attention features respectively corresponding to the speech features in the speech sequence, a speech recognition result corresponding to the speech sequence comprises: Fusing each speech feature in the fused speech sequence with the attention feature corresponding to the speech feature to obtain each fused attention feature; Perform convolution operation on each fused attention feature to obtain each convolved attention feature, and perform feature fusion on each convolved attention feature and the fused attention feature corresponding to the attention feature to obtain the initial attention feature corresponding to each convolved attention feature; Performing a spatial mapping operation on each of the initial attention features to obtain each mapped initial attention feature, and performing feature fusion on each of the initial attention features and the mapped initial attention feature corresponding to the initial attention feature to obtain each fused initial attention feature; A normalization operation is performed on each fused initial attention feature to obtain an intermediate attention feature corresponding to each speech feature, and based on each intermediate attention feature, a speech recognition result corresponding to the speech sequence is determined.
7. The method according to claim 6, characterized in that The step of determining the speech recognition result corresponding to the speech sequence based on each intermediate attention feature includes: Using a sequence composed of each intermediate attention feature as a new speech sequence to be recognized, and using each intermediate attention feature as each speech feature in the new speech sequence to be recognized; Returning to the step of performing a spatial mapping operation on the speech sequence to obtain the mapped speech sequence, until the number of loops reaches a preset number, and obtaining each target attention feature corresponding to the speech sequence to be recognized; Based on each of the target attention features, the speech recognition result is determined.
8. The method according to claim 7, characterized in that The step of determining the speech recognition result based on each of the target attention features comprises: Using at least one preset decoding module, feature decoding is performed on each of the target attention features to obtain the speech recognition result; wherein, the input of the latter decoding module of the two adjacent decoding modules in the decoding order is the output of the previous decoding module, and the output of the last decoding module in the decoding order is the speech recognition result.
9. The method according to claim 1, characterized in that: The speech recognition method is performed using a pre-trained speech recognition neural network; the speech recognition neural network is trained according to the following steps: Obtaining a sample speech sequence to be recognized; Inputting the sample speech sequence into a speech recognition neural network to be trained, and using the speech recognition neural network to be trained to perform recognition processing on the sample speech sequence to determine each target prediction attention feature corresponding to the sample speech sequence; Determining a predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features; Based on the predicted speech result and the standard speech result corresponding to the sample speech sequence, the prediction loss corresponding to the speech recognition neural network to be trained is determined, and the speech recognition neural network to be trained is iteratively trained using the prediction loss until a training cutoff condition is met, thereby obtaining a trained speech recognition neural network.
10. The method according to claim 9, characterized in that The predicted speech result includes a first predicted speech result, and the prediction loss includes a temporal classification loss; The step of determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features includes: Determine a first predicted speech result corresponding to the sample speech sequence by using each of the target predicted attention features; The step of determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result includes: The neural network connection temporal classification CTC algorithm is used to determine the temporal classification loss based on the first predicted speech result and the standard speech result.
11. The method according to claim 9 or 10, characterized in that: The predicted speech result includes a second predicted speech result, and the prediction loss includes a cross entropy loss; The step of determining the predicted speech result corresponding to the sample speech sequence based on each of the target predicted attention features includes: Using at least one decoding module preset in the speech recognition neural network to be trained, feature decoding is performed on each of the target predicted attention features to obtain the second predicted speech result; The step of determining the prediction loss corresponding to the speech recognition neural network to be trained based on the predicted speech result includes: The cross entropy loss is determined based on the second predicted speech result and the standard speech result.
12. A speech recognition device, characterized in that: include: A first determination module is used to determine a first cosine weight corresponding to each initial query feature according to the number of speech features in the speech sequence to be recognized and a first ranking value of each initial query feature in the query matrix corresponding to the speech sequence, and to determine a second cosine weight corresponding to each initial key feature according to the number of speech features and a second ranking value of each initial key feature in the key matrix corresponding to the speech sequence; A second determination module, configured to determine the similarity between each of the initial query features and each of the initial key features based on the first cosine weight and the second cosine weight; A third determination module is used to determine, for each speech feature in the speech sequence, an attention feature corresponding to the speech feature based on the similarity between the initial query feature corresponding to the speech feature and each of the initial key features, and each target value feature in the value matrix corresponding to the speech sequence; The fourth determination module is used to determine the speech recognition result corresponding to the speech sequence based on the attention features respectively corresponding to each of the speech features in the speech sequence.
13. A computer device, characterized in that: include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the processor is used to execute the machine-readable instructions stored in the memory. When the machine-readable instructions are executed by the processor, the processor executes the steps of the speech recognition method as described in any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program. When the computer program is executed by a computer device, the computer device executes the steps of the speech recognition method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Attention feature acquisition method and device for neural network, and storage medium
CN109635926A
Voice recognition method and device, equipment and storage medium
CN111933115A
Lightweight end-to-end speech recognition method based on convolutional self-attention transformation network
CN113140220A
Transform model-based data prediction method and device, server and storage medium
CN113282707A
Unsupervised pre-trained speech recognition model with enhanced local dependency relationship, and training method thereof
CN113380237A
