Speech recognition model training method, speech recognition method and related device

By performing word segmentation processing on the speech recognition model and randomly selecting attention windows, the problem of high complexity of the attention mechanism in processing long sequence speech data is solved, and the efficiency and adaptability of the model are improved.

CN118762689AActive Publication Date: 2024-10-11PING AN TECH (SHENZHEN) CO LTD

Patent Information

Application Number
CN202411016780.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-10-11
Estimated Expiration
2044-07-26

AI Technical Summary

Technical Problem

When a speech recognition model based on the attention mechanism processes long sequence speech data, the space complexity and time complexity increase quadratically, resulting in high memory requirements and computational overhead, which reduces the scalability and computational efficiency of the model.

Method used

By performing word segmentation processing on the training speech data, selecting the target position and size of the window, randomly selecting target word elements from the word elements, and generating the keys and values ​​of the attention mechanism, reducing computational complexity and storage consumption, and increasing the nonlinear capability of the model and robustness.

Benefits of technology

It effectively reduces computing overhead and storage consumption, improves the model's processing capabilities and adaptability to long sequence inputs, and enhances the model's generalization ability on different data sets and tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118762689A_ABST
    Figure CN118762689A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a training method of a speech recognition model, a speech recognition method and a related device, and belongs to the technical field of artificial intelligence. The method comprises the following steps: selecting a target lexical element from lexical elements of training voice data according to a target position and a target size of a window, and obtaining a key according to the target lexical element; obtaining attention features according to the query, the keys and the values; performing classification according to the attention features to obtain prediction text data; adjusting the position range and the size range of the window according to the predicted text data to obtain a trained speech recognition model; the target position of the window is randomly selected from the position range of the window, and the target size of the window is randomly selected from the size range of the window, so that the nonlinear capability of the model is improved, the calculation overhead and the storage consumption are reduced, and the model can process long sequence input; the size and interaction mode of the window can be adjusted according to data characteristics and task requirements, and the adaptability and generalization ability of the model on different data sets and tasks are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a training method for a speech recognition model, a speech recognition method and related devices. Background Art

[0002] In the speech recognition task, the speech recognition model uses the attention mechanism to focus on the key features of the input speech data to improve the efficiency and accuracy of the speech recognition model. In the attention mechanism, the input feature sequence needs to be weighted and summarized to calculate the correlation score between each pair of word units at different positions. For example, for an input speech sequence of length n, the space complexity and time complexity of the attention mechanism are both O(n^2), because it is necessary to store the matrix of correlation scores between all positions and calculate the correlation between all positions. For example, for an input sequence of length 100, it is necessary to store a 100×100 correlation score matrix with a total of 10,000 elements; and 10,000 correlation score calculations are required. For longer input sequences, this space complexity and time complexity will grow quadratically, increasing memory consumption and reducing computational efficiency. The increase in space complexity and time complexity limits the ability of speech recognition models based on the attention mechanism to process long-sequence speech data. When long-sequence speech data needs to be processed, the memory requirements and computational overhead become very high, thereby reducing the scalability and computational efficiency of the speech recognition model. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose a training method for a speech recognition model, a speech recognition method and related devices, which reduce computing overhead and storage consumption and are conducive to the model processing long sequence inputs.

[0004] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a method for training a speech recognition model, and the method for training a speech recognition model includes:

[0005] Acquiring training speech data, and inputting the training speech data into an initial speech recognition model;

[0006] Performing word segmentation processing on the training speech data to obtain a plurality of word units;

[0007] Obtaining a query and a value of an attention mechanism according to the word-unit;

[0008] A target word-membrane is selected from the word-membrane according to a target position and a target size of the window, and a key of an attention mechanism is obtained according to the target word-membrane, wherein the number of the target word-membrane is less than the number of the word-membrane, the target position of the window is randomly selected from a position range of the window, and the target size of the window is randomly selected from a size range of the window;

[0009] obtain an attention feature based on the query, the key, and the value;

[0010] Classify according to the attention features to obtain predicted text data;

[0011] The position range and size range of the window are adjusted according to the predicted text data to obtain a trained speech recognition model.

[0012] In some embodiments, obtaining a query and a value of an attention mechanism according to the word-element includes:

[0013] Obtaining a query of the attention mechanism according to the product of the word-unit and the first weight parameter corresponding to the query;

[0014] The value of the attention mechanism is obtained according to the product of the word element and the second weight parameter corresponding to the value.

[0015] In some embodiments, obtaining a key of an attention mechanism according to the target word-element includes:

[0016] The key of the attention mechanism is obtained according to the product of the target word and the third weight parameter corresponding to the key.

[0017] In some embodiments, obtaining an attention feature according to the query, the key, and the value includes:

[0018] Add the positional encoding to the product of the query and the key to obtain an attention score;

[0019] The attention feature is obtained according to the product of the attention score and the value.

[0020] In some embodiments, the position encoding corresponding to the i-th attention score is expressed as: in, PE i is the position code corresponding to the i-th attention score, k is a positive integer greater than or equal to 1, and d is the dimension of the training speech data.

[0021] In some embodiments, the classifying according to the attention feature to obtain predicted text data includes:

[0022] Classify according to the attention feature to obtain the probability value of each word in the vocabulary corresponding to the attention feature;

[0023] Determine a target word from the words in the vocabulary according to the probability value;

[0024] The target words form predicted text data.

[0025] To achieve the above object, a second aspect of an embodiment of the present application proposes a speech recognition method, the speech recognition method comprising:

[0026] Acquire voice data to be recognized;

[0027] Inputting the speech data to be recognized into a trained speech recognition model for speech recognition to obtain a speech recognition result;

[0028] Among them, the trained speech recognition model is trained according to the speech recognition model training method as described in the first aspect of the embodiment of the present application.

[0029] To achieve the above-mentioned purpose, a third aspect of an embodiment of the present application provides a training device for a speech recognition model, and the training device for a speech recognition model includes:

[0030] An input module, used to obtain training speech data and input the training speech data into an initial speech recognition model;

[0031] A word segmentation module, used for performing word segmentation processing on the training speech data to obtain multiple word units;

[0032] an attention module, configured to obtain a query and a value of an attention mechanism according to the word-grams, select a target word-gram from the word-grams through a window, obtain a key of the attention mechanism according to the target word-grams, and obtain an attention feature according to the query, the key and the value, wherein the number of the target word-grams is less than the number of the word-grams;

[0033] A classification module, used for classifying according to the attention features to obtain predicted text data;

[0034] A parameter adjustment module is used to adjust the position and size of the window according to the predicted text data to obtain a trained speech recognition model.

[0035] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements the training method of the speech recognition model as described in the first aspect of the embodiment of the present application and the speech recognition method as described in the second aspect of the embodiment of the present application.

[0036] To achieve the above-mentioned purpose, the fifth aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the training method of the speech recognition model as described in the first aspect of the embodiment of the present application and the speech recognition method as described in the second aspect of the embodiment of the present application.

[0037] The training method, speech recognition method and related device of the speech recognition model proposed in the present application obtain multiple word units by performing word segmentation processing on the training speech data; obtain the query and value of the attention mechanism according to the word unit; randomly select the target position of the window from the position range of the window, randomly select the target size of the window from the size range of the window, select the target word unit from the word units of the training speech data according to the target position and target size of the window, and obtain the key according to the target word unit; obtain the attention feature according to the query, key and value; classify according to the attention feature to obtain the predicted text data; adjust the position range and size range of the window according to the predicted text data to obtain the trained speech recognition model. By randomly generating the attention window range and random interaction, the nonlinear ability of the model is increased, so that the model can better represent complex input correlations; reduce the computational overhead and storage consumption, which is conducive to the model processing long sequence inputs; the randomization of the attention mechanism can increase the robustness of the model to uncertainty and noise; can flexibly adjust the size and interaction mode of the window in different scenarios according to the data characteristics and task requirements, and improve the adaptability and generalization ability of the model on different data sets and tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a step diagram of a method for training a speech recognition model provided in an embodiment of the present application;

[0039] Figure 2 It is a sub-step diagram of step S300 provided in an embodiment of the present application;

[0040] Figure 3 It is a sub-step diagram of obtaining a key of an attention mechanism according to a target word provided by an embodiment of the present application;

[0041] Figure 4 It is a sub-step diagram of step S500 provided in an embodiment of the present application;

[0042] Figure 5 is a step diagram of a speech recognition method provided by an embodiment of the present application;

[0043] Figure 6 is a schematic diagram of the attention mechanism provided by an embodiment of the present application;

[0044] Figure 7 is a structural diagram of a training device for a speech recognition model provided in an embodiment of the present application;

[0045] Figure 8 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0047] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0049] In the speech recognition task, the speech recognition model uses the attention mechanism to focus on the key features of the input speech data to improve the efficiency and accuracy of the speech recognition model. In the attention mechanism, the input feature sequence needs to be weighted and summarized to calculate the correlation score between each pair of word units at different positions. For example, for an input speech sequence of length n, the space complexity and time complexity of the attention mechanism are both O(n^2), because it is necessary to store the matrix of correlation scores between all positions and calculate the correlation between all positions. For example, for an input sequence of length 100, it is necessary to store a 100×100 correlation score matrix with a total of 10,000 elements; and 10,000 correlation score calculations are required. For longer input sequences, this space complexity and time complexity will grow quadratically, increasing memory consumption and reducing computational efficiency. The increase in space complexity and time complexity limits the ability of speech recognition models based on the attention mechanism to process long-sequence speech data. When long-sequence speech data needs to be processed, the memory requirements and computational overhead become very high, thereby reducing the scalability and computational efficiency of the speech recognition model.

[0050] For input speech features T is the length of the speech feature, D is the embedding dimension of the word unit, and the query and key are obtained according to the input speech feature. According to formula A i =q i ×K T +positional_encoding gets the i-th row element of the attention score matrix from the query and key, and the matrix of attention scores is composed of multiple rows of elements Each row in the attention score matrix consists of each query vector and key matrix The multiplication operation is performed to obtain the relationship between the query vector and the word units at different positions. Each q vector is multiplied by the K matrix, which requires T×2D floating point calculations. There are T q vectors in the calculation process of the attention matrix A, and the size of K is Therefore, the time replication and computational complexity are both O(T 2 ).

[0051] In order to solve the above problems, the embodiments of the present application provide a training method for a speech recognition model, a speech recognition method and related devices to improve the adaptability and generalization ability of the model on different data sets and tasks.

[0052] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0053] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0054] The training method of the speech recognition model, the speech recognition method and related devices provided in the embodiments of the present application relate to the field of artificial intelligence technology. The training method of the speech recognition model and the speech recognition method provided in the embodiments of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application of the training method of the speech recognition model and the speech recognition method, etc., but is not limited to the above forms.

[0055] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0056] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant regulations. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or jump to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.

[0057] The training method of the speech recognition model, the speech recognition method and the related device provided in the embodiments of the present application are specifically described through the following embodiments. First, the training method of the speech recognition model in the embodiments of the present application is described.

[0058] The present application embodiment provides a method for training a speech recognition model. Figure 1 , the training method of the speech recognition model includes the following steps:

[0059] Step S100, obtaining training speech data, and inputting the training speech data into an initial speech recognition model;

[0060] Step S200, performing word segmentation processing on the training speech data to obtain a plurality of word units;

[0061] Step S300, obtaining a query and value of the attention mechanism according to the word element;

[0062] Step S400, selecting a target word from the word-units according to the target position and target size of the window, and obtaining a key of the attention mechanism according to the target word-unit;

[0063] Step S500, obtaining attention features according to the query, key and value;

[0064] Step S600, classifying according to the attention features to obtain predicted text data;

[0065] Step S700, adjusting the position range and size range of the window according to the predicted text data to obtain a trained speech recognition model.

[0066] In this embodiment, all word units obtained by word segmentation of training speech data are no longer used as keys to calculate attention features with queries through learnable windows. Instead, some word units are selected as keys to calculate attention features with queries, thereby increasing the nonlinear ability of the speech recognition model, increasing the robustness of the model to uncertainty and noise, and enabling the model to better represent complex input correlations; the position and size of the window are flexibly adjusted according to different scenarios, so that the model can adapt according to the requirements of specific tasks and the characteristics of the data set, so that the model has different focus and emphasis for different inputs, thereby improving the adaptability and generalization ability of the model on different data sets and tasks, and further improving the flexibility of the model.

[0067] The following is a detailed description of steps S100 to S700 in the method for training the speech recognition model.

[0068] In step S100 of some embodiments, training speech data is obtained and input into an initial speech recognition model. The training speech data may come from a large speech database or from speech data collected by matching downstream tasks. By training the speech recognition model with a large amount of speech data from a large speech database, the speech recognition model can have better speech recognition capabilities. By training the speech recognition model with speech data collected by matching downstream tasks, the speech recognition model can have better speech recognition capabilities for downstream tasks.

[0069] The training speech data is annotated with labels of real values. For example, if the speech information of the training speech data is "You are so beautiful", the training speech data is annotated with labels of the text information "You are so beautiful".

[0070] In step S200 of some embodiments, the training speech data is tokenized to obtain a plurality of tokens. Tokenization is to convert the data to be processed into a numerical form that can be understood by a computer. The process of tokenization is to decompose the data to be processed into smaller units, which are usually called tokens.

[0071] First, the training speech data is preprocessed, for example, the noise in the training speech data is removed by denoising; the sampling rate conversion is used to ensure that different training speech data have a uniform sampling rate; the high-frequency part of the speech is improved by pre-emphasis and the signal is flatter; the training speech data is divided into small frames by windowing, for example, a Hamming window can be used, and each frame is usually 20-40 milliseconds. Feature extraction is performed on each frame, for example, Mel-Frequency Cepstral Coefficients (MFCC), Perceptual Linear Prediction (PLP) and other feature extraction methods are used. Voice Activity Detection (VAD) is used to detect the start and end points of the detected speech, and the speech segment and the silent segment are detected to exclude the silent and non-speech parts. The word unit boundary is detected by the word unit boundary detection method, and multiple word units are obtained by word unit boundary segmentation; for example, an energy-based method is used to detect the sudden change of speech energy to locate the word unit boundary, or a phoneme-based method is used to use a phoneme model to predict the word unit boundary.

[0072] In some embodiments, an energy-based method is used to detect the sudden change of speech energy to locate word unit boundaries, and word segmentation is performed according to word unit boundaries to obtain multiple word units. For each frame of speech signal, its energy is calculated. The energy can be calculated by the following formula: Where E[n] represents the energy of the nth frame speech signal, x[i,n] represents the ith sample of the nth frame speech signal, and N represents the size of the frame. In order to reduce the impact of different speakers, environments, and devices, the energy is normalized. An energy threshold is determined based on experience or through experiments to determine the sudden change of energy. The energy mutation point is detected by comparing the energy difference between consecutive frames. If the energy difference between two consecutive frames exceeds the preset threshold, it is considered that there may be a word unit boundary. In order to reduce the impact of noise and short-term fluctuations, the detected boundary can be smoothed; for example, a median filter or a dynamic programming algorithm can be used to optimize the boundary position. After determining the word unit boundary, multiple word units are obtained by segmentation based on the word unit boundary.

[0073] In some embodiments, using a phoneme-based method to predict word boundaries generally involves using a phoneme model to identify specific phoneme transition points in a speech signal, which generally correspond to word boundaries. The main steps of using a phoneme-based method to predict word boundaries include: phoneme model training, speech signal preprocessing, phoneme recognition, word boundary detection, and boundary optimization. In the step of phoneme model training, a large amount of annotated speech data is collected, including phoneme-level annotations; features such as Mel-frequency cepstral coefficients, perceptual linear prediction, etc. are extracted from the speech signal. The phoneme model is trained using the extracted features and annotated data, and the phoneme model is generally based on a hidden Markov model or a deep learning model (such as a recurrent neural network, a long short-term memory network). In the step of speech signal preprocessing, the sampling rate of the speech signal is ensured to be consistent by sampling rate conversion; the high-frequency part of the speech signal is strengthened by pre-emphasis; the speech signal is divided into a series of short-time frames by framing; and acoustic features are extracted for each frame by feature extraction. In the step of phoneme recognition, phoneme transition points are detected in the phoneme sequence, which may be the locations of word-unit boundaries. First, an empty list is set to store the detected word-unit boundaries, and then the phoneme sequence is traversed to check whether the continuous phonemes have changed. When a phoneme change is detected, the position of the current frame is recorded as a potential word-unit boundary. In the step of boundary optimization, smoothing techniques are used to reduce false detections to smooth boundaries, such as through dynamic programming or Gaussian smoothing; contextual information is considered to confirm boundaries, such as using language models to evaluate the rationality of boundaries, and further accurately determine boundaries. After determining the word-unit boundaries, word segmentation is performed according to the word-unit boundaries to obtain multiple word units.

[0074] Reference Figure 6 Attention Mechanism is a technology used in neural networks to enhance the model's ability to pay attention to important information. Its core idea is to enable the model to dynamically select and focus on different parts of the input data according to the needs of the current task when processing input data. The attention mechanism simulates the process of human visual attention mechanism, which can focus on the key parts and ignore the unimportant parts when processing information; that is, different levels of attention are assigned to different parts of the input information. The attention mechanism calculates the importance weight (attentionweight) of each element in the input sequence, and then weighted sums the input sequence according to these weights to obtain a new representation. This method allows the model to more flexibly select and focus on important information when processing long sequence data.

[0075] In step S300 of some embodiments, the query and value of the attention mechanism are obtained according to the word unit. The word unit can be represented as: T is the length of the acoustic feature, and D is the embedding dimension of each word.

[0076] Reference Figure 2 , get the query and value of the attention mechanism according to the word unit, including the following steps:

[0077] Step S310, obtaining a query of the attention mechanism according to the product of the word unit and the first weight parameter corresponding to the query;

[0078] Step S320, obtaining the value of the attention mechanism according to the product of the word and the second weight parameter corresponding to the value.

[0079] The query of the attention mechanism is usually a variable or a set of variables that represents the query issued by the data point currently being processed. For example, when processing a speech signal, the query is the word unit of the speech signal that needs to be paid attention to or processed. The purpose of this query is to find the most relevant part from other data points. The query is used to calculate the similarity or correlation with other keys. These similarity scores determine how much weight should be given to each value when synthesizing the final output representation of the attention mechanism.

[0080] The query of the attention mechanism can be expressed as follows: q = x n *w q . Where q represents the query of the attention mechanism; x n represents the nth sample in the word, w q Indicates the first weight parameter corresponding to the query.

[0081] have

[0082] The value of the attention mechanism is the data point associated with the key. In the attention mechanism, the value is usually a feature vector extracted from the original input data, which represents different aspects or attributes of the input data. The role of the value in the attention mechanism is to provide detailed information related to the key, which is used to generate the final output representation of the attention mechanism. During the calculation of the attention mechanism, the value is obtained by weighted summing with the attention score calculated by the query and the key. This weighted value is the output of the attention mechanism, which contains the most relevant parts of the original input data.

[0083] The value of the attention mechanism can be expressed as follows: v = x n *w v . Where v represents the value of the attention mechanism; x n represents the nth sample in the word, w v Represents the second weight parameter corresponding to the value. The value of the attention mechanism is in matrix form, expressed as

[0084] In step S400 of some embodiments, target tokens are selected from the tokens based on the target position and target size of the window, and keys for the attention mechanism are obtained based on the target tokens.

[0085] The keys of the attention mechanism are data points used for comparison with queries. In the attention mechanism, keys are usually feature vectors extracted from the original input data, and these feature vectors represent different aspects or attributes of the input data. The role of the keys of the attention mechanism in the attention mechanism is to help determine the values most relevant to the query. By comparing the similarity or match degree between the query and each key, attention scores can be calculated. These attention scores determine the weights that should be assigned to each value when synthesizing the final output representation of the attention mechanism.

[0086] The target position of the window is randomly selected from within the position range of the window, and the target size of the window is randomly selected from within the size range of the window. For example, the position range of the window is to start selecting from the 2nd sample of the tokens to starting from the 5th sample of the tokens, and the size range of the window is to select 3 samples to selecting 6 samples. A random number 3 is generated by the random number generator, and the target position of the window is to start selecting from the 3rd sample of the tokens; a random number 4 is generated by the random number generator, and the target size of the window is to select 4 samples. By using the random number generator to generate the position and size of each window, it is ensured that the position and size of each window are within the predefined window position range and size range.

[0087] Target tokens are selected from the tokens x = (x1, …, x T ) through the window. The size of the window is less than T to ensure that the number of target tokens is less than the number of tokens. The size of the window is win, where 0 < win < T, and win target tokens are selected from the tokens. win is a learnable parameter, and as the network continuously learns, it will find appropriate window values for different tasks or datasets. Furthermore, the matrix composed of the keys of the attention mechanism is represented as Specifically, when the size of the window is 3 and the position of the window is to start sampling from the second sample, the target tokens selected from the tokens through this window are x2, x3, and x4. In particular, for any row vector in the K matrix, it is any token randomly sampled from the input features.

[0088] Referring to Figure 3 , specifically, obtaining the keys of the attention mechanism based on the target tokens includes:

[0089] Step S410, obtaining the keys of the attention mechanism based on the product of the target tokens and the third weight parameter corresponding to the keys.

[0090] The keys of the attention mechanism can be represented by the following formula: k = x n * wk . Where k represents the key of the attention mechanism; x n represents the nth sample in the word, w v Represents the third weight parameter corresponding to the key. Compared with the traditional method of calculating the key based on all samples in the word, the method of selecting the target word from the word through the window and obtaining the key of the attention mechanism based on the target word can improve efficiency and reduce time complexity and computational complexity.

[0091] Reference Figure 4 In step S500 of some embodiments, obtaining attention features according to the query, key and value includes the following steps:

[0092] Step S510, adding the position code to the product of the query and the key to obtain an attention score;

[0093] Step S520, obtaining the attention feature according to the product of the attention score and the value.

[0094] The attention score can be expressed as: A i =q i ×K T + positional_encoding; where q represents the i-th attention score, i represents the i-th query vector of the attention mechanism, K represents the matrix composed of the keys of the attention mechanism, and positional_encoding represents the position encoding.

[0095] For each vector, there is no need to interact with the entire context, only with the target key. Specifically, for the input feature Arbitrary query vector Extracted through the window (where x′1,…,x′ win ∈x) matrix dot product operation, and win values ​​are obtained. The row value of each win value is i, and the column value is the label of each vector in each K matrix; the value other than the label is 0 by default. Compared with the traditional Matrix multiplication, each query vector and Matrix multiplication can improve efficiency and reduce time complexity and computational complexity.

[0096] To prevent position shift, a position code is added to each element (the product of the query and the key). The position code corresponding to the i-th attention score is expressed as: in, PE i is the position code corresponding to the i-th attention score, k is a positive integer greater than or equal to 1, and d is the dimension of the training speech data.

[0097] The matrix of attention scores is sparse.

[0098] Perform a dot product operation on the attention score and the value. According to the product of the attention score and the value, the attention feature is obtained. Then the attention feature Y can be expressed by the following formula: Y = A*V.

[0099] In step S600 of some embodiments, classification is performed according to the attention features to obtain predicted text data.

[0100] Specifically, the attention features are passed through the activation layer, pooling layer, fully connected layer and softmax layer.

[0101] By performing nonlinear transformations on the attention features through activation layers, the network can better learn and process complex data and improve the expressiveness of the model. Nonlinear activation functions enable the network to combine and transform features at multiple levels to capture complex structures and patterns in the input data. Nonlinear activation functions help the network to better propagate gradients during training, which is the key to learning through the back-propagation algorithm. For example, the activation layer can use Sigmoid function, Tanh function, ReLU function, etc.

[0102] The attention features are downsampled through the pooling layer to reduce the dimension and computation of the data while retaining important feature information. The pooling layer reduces the dimension of the data by reducing the width and height of the attention features. This helps to reduce the number of parameters of subsequent layers, reduce computational complexity, and prevent overfitting. The pooling operation can increase the tolerance of features to small changes, so that the network has a certain invariance to small translations, rotations, or deformations of the input image. Commonly used pooling functions include maximum pooling and average pooling. The maximum pooling operation is to take the maximum value of every several pixels in the output of the convolutional layer as the output of the pooling layer. Average pooling is to take the average value of every several pixels in the output of the convolutional layer as the output of the pooling layer. This downsampling operation of the pooling layer can reduce the dimension and computation of the data while retaining important features and improving the generalization ability of the network.

[0103] The fully connected layer integrates the features extracted by the previous layers and maps them to the classification results. The calculation process of the fully connected layer is to multiply the output of the previous layers by the weights of the fully connected layer element by element and add the bias term. Through its internal weights and biases, the fully connected layer can learn the complex nonlinear relationship between the input features. For example, the fully connected layer maps the features to the classification results of "you" text, "you" text, and "we" text.

[0104] The score of each category in the fully connected layer is converted into a probability distribution through the softmax layer. The probability of the i-th category is expressed as: Among them, zi represents the score of the fully connected layer for the i-th category, zj represents the score of the fully connected layer for the j-th category, and e zi is the exponent of zi, e zj is the exponential of zj, y i Represents the probability of the i-th category. For example, through the softmax layer, the probability corresponding to the text "you" is 0.5, the probability corresponding to the text "you" is 0.4, and the probability corresponding to the text "we" is 0.1.

[0105] Sort the probabilities of each category output by the softmax layer and select the category with the highest probability as the predicted text data. For example, the probability corresponding to the "you" text is 0.5, the probability corresponding to the "you" text is 0.4, and the probability corresponding to the "we" text is 0.1. The category with the highest probability is the "you" text, and the "you" text is selected as the predicted text data.

[0106] In step S700 of some embodiments, the position range and size range of the window are adjusted according to the predicted text data to obtain a trained speech recognition model.

[0107] Specifically, the loss function is calculated based on the true value corresponding to the predicted text data and the training speech data, and the parameters of the speech recognition model are adjusted by reverse calculation based on the loss function. The parameters of the speech recognition model include the position range and size range of the window, so as to obtain a trained speech recognition model.

[0108] For example, the loss function may adopt one or more of a classification cross entropy function, an attention loss function, and a mean square error function.

[0109] Traditional attention mechanisms usually use fixed window ranges and interaction methods, which limits the expressive power of the model. The method of randomly generating attention window ranges and sizes to achieve random interactions can introduce more nonlinear capabilities, enabling the model to better represent complex input correlations. By randomly generating attention window ranges and random interactions, the model can flexibly adjust the window size and interaction method in different scenarios. This flexibility enables the model to adapt according to the requirements of specific tasks and the characteristics of the data set, improving the sensitivity and performance of the model.

[0110] The interaction between each token and other tokens is represented by the generated attention score matrix, where each row has only win non-zero attention scores, the scores of other positions are zero, and the positions of non-zero scores in each row are randomly selected. This method of randomly generating the range and position of the attention window can increase the nonlinear ability of the model. By introducing the randomness of attention, the correlation between the input speech data can be better captured to improve the performance of the model. The randomization of the attention mechanism can increase the robustness of the model to uncertainty and noise. Randomly generating the attention window range and random interactions enables the model to have different focus and emphasis for different inputs, thereby improving the adaptability and generalization ability of the model on different data sets and tasks. For each token in the window, tokens in other windows or in the global scope can be randomly selected for interaction. This can be achieved by randomly selecting the index of the token and setting a non-zero value at the corresponding position in the attention score matrix.

[0111] The present application embodiment provides a speech recognition method. Figure 5 , a speech recognition method, comprising the following steps:

[0112] Step S800: Acquire voice data to be recognized.

[0113] Step S900: input the speech data to be recognized into the trained speech recognition model for speech recognition to obtain a speech recognition result.

[0114] The trained speech recognition model is obtained by training according to the above speech recognition model training method.

[0115] In step S800 of some embodiments, voice data to be recognized is collected by a recording device, and the voice data is not labeled.

[0116] In step S900 of some embodiments, the speech data to be recognized is input into a trained speech recognition model for speech recognition.

[0117] In the speech recognition model, the speech data to be recognized is preprocessed, for example, the noise in the speech data to be recognized is removed by denoising; the sampling rate conversion is used to ensure that different speech data to be recognized have a uniform sampling rate; the high-frequency part of the speech is improved by pre-emphasis and the signal is flatter; the speech data to be recognized is divided into small frames by windowing, for example, a Hamming window can be used, and each frame is usually 20-40 milliseconds. Feature extraction is performed on each frame, for example, using feature extraction methods such as Mel frequency cepstral coefficients and perceptual linear prediction. Voice activity detection is used to detect the start and end points of the speech, and speech segments and silent segments are detected to exclude silent and non-speech parts. The word unit boundary is detected by the word unit boundary detection method, and multiple word units are obtained by word unit segmentation according to the word unit boundary; for example, an energy-based method is used to detect the sudden change of speech energy to locate the word unit boundary, or a phoneme-based method is used to predict the word unit boundary using a phoneme model.

[0118] Reference Figure 6 , according to the product of the word unit and the first weight parameter corresponding to the query, the query of the attention mechanism is obtained. The query of the attention mechanism can be expressed by the following formula: q = x n *w q . Where q represents the query of the attention mechanism; x n represents the nth sample in the word, w q Indicates the first weight parameter corresponding to the query.

[0119] have

[0120] The value of the attention mechanism is obtained by multiplying the word unit and the second weight parameter corresponding to the value. The value of the attention mechanism can be expressed by the following formula: v = x n *w v . Where v represents the value of the attention mechanism; x n represents the nth sample in the word, w v Represents the second weight parameter corresponding to the value. The value of the attention mechanism is in matrix form, expressed as

[0121] Randomly select the target position of the window within the position range of the window, and randomly select the target size of the window within the size range of the window. The position range of the window and the size range of the window are obtained during the training process of the speech recognition model. For example, the position range of the window is selected starting from the 2nd sample of the token to starting from the 5th sample of the token, and the size range of the window is selecting 3 samples to selecting 6 samples. Generate a random number 3 through the random number generator, and the target position of the window is selected starting from the 3rd sample of the token; generate a random number 4 through the random number generator, and the target size of the window is selecting 4 samples. By using the random number generator to generate the position and size of each window, ensure that the position and size of each window are within the predefined window position range and size range.

[0122] Select the target tokens from the tokens x=(x1,…,x T ) through the window. The size of the window is less than T to ensure that the number of target tokens is less than the number of tokens. The size of the window is win, where 0 < win < T, and win target tokens are selected from the tokens.

[0123] The key of the attention mechanism can be expressed by the following formula: k = x n *w k . Where k represents the key of the attention mechanism; x n represents the nth sample in the tokens, and w v represents the third weight parameter corresponding to the key. The matrix composed of the keys of the attention mechanism is expressed as Specifically, the size of the window is 3, and the position of the window is sampled starting from the second sample. Then the target tokens selected from the tokens through this window are x2, x3, and x4.

[0124] Add the product of the query and the key to the positional encoding to obtain the attention score; the attention score can be expressed as: A i =q i ×K T +positional_encoding; where represents the ith attention score, q i represents the ith query vector of the attention mechanism, K represents the matrix composed of the keys of the attention mechanism, and positional_encoding represents the positional encoding. The positional encoding corresponding to the ith attention score is expressed as: Where, PE i is the positional encoding corresponding to the ith attention score, k is a positive integer greater than or equal to 1, and d is the dimension of the training speech data. For each vector, there is no need to interact with the entire context, just interact with the target key. Specifically, for the input feature Arbitrary query vector Extracted through the window (where x′1,…,x′ win ∈x) matrix dot product operation, and win values ​​are obtained. The row value of each win value is i, and the column value is the label of each vector in each K matrix; for values ​​other than the label, the default is 0.

[0125] According to the product of the attention score and the value, the attention feature is obtained. The attention score and the value are dot-producted. According to the product of the attention score and the value, the attention feature is obtained. Then the attention feature Y can be expressed by the following formula: Y = A*V.

[0126] The attention features are classified through the activation layer, pooling layer, fully connected layer and softmax layer to convert the speech sequence into a text sequence. The attention features are nonlinearly transformed through the activation layer, downsampled through the pooling layer, integrated through the fully connected layer, and mapped to the classification results. The scores of each category in the fully connected layer are converted into probability distributions through the softmax layer, and the probabilities of each category output by the softmax layer are sorted, and the category with the highest probability is selected as the speech recognition result.

[0127] For example, the word "thank you" contained in the speech data to be recognized is mapped to the classification results of "Xie Xie", "Xie Xie" and "Duo Xie" text through the fully connected layer; the probability corresponding to the "Xie Xie" text is 0.1, the probability corresponding to the "Xie Xie" text is 0.6, and the probability corresponding to the "Duo Xie" text is 0.3 through the softmax layer; the category with the largest probability is the "Xie Xie" text, and the "Xie Xie" text is selected as the speech recognition result.

[0128] In this embodiment, by randomly generating attention window ranges and random interactions, the nonlinear ability of the model is increased, enabling the model to better represent complex input correlations; reducing computational overhead and storage consumption, which is beneficial for the model to process long sequence inputs; the randomization of the attention mechanism can increase the robustness of the model to uncertainty and noise; and the window size and interaction mode can be flexibly adjusted in different scenarios according to data characteristics and task requirements, thereby improving the adaptability and generalization ability of the model on different data sets and tasks.

[0129] The embodiment of the present application proposes a training device for a speech recognition model. Figure 7 The training device of the speech recognition model includes: an input module 801, a word segmentation module 802, an attention module 803, a classification module 804 and a parameter adjustment module 805.

[0130] The input module 801 is used to obtain training speech data and input the training speech data into the initial speech recognition model; the word segmentation module 802 is used to perform word segmentation on the training speech data to obtain multiple word units; the attention module 803 is used to obtain the query and value of the attention mechanism based on the word unit, select the target word unit from the word unit through the window, obtain the key of the attention mechanism based on the target word unit, and obtain the attention feature based on the query, key and value. The number of target word units is less than the number of word units; the classification module 804 is used to classify according to the attention feature to obtain predicted text data; the parameter adjustment module 805 is used to adjust the position and size of the window according to the predicted text data to obtain a trained speech recognition model.

[0131] It is understandable that the training device of the speech recognition model of the embodiment of the present application applies the training method of the speech recognition model as described above. The modules of the training device of the speech recognition model of the embodiment of the present application correspond to the steps of the training method of the speech recognition model. The training device of the speech recognition model and the training method of the speech recognition model adopt the same technical means, solve the same technical problems, and bring the same technical effects, which will not be repeated here.

[0132] The present application also provides an electronic device. Figure 8 The electronic device includes a memory 902 and a processor 901. The memory 902 stores a computer program. When the processor 901 executes the computer program, the training method and the speech recognition method of the speech recognition model are implemented. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0133] The processor 901 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application; the memory 902 can be implemented in the form of a read-only memory (Read Only Memory, ROM), a static storage device, a dynamic storage device, or a random access memory (Random Access Memory, RAM). The memory 902 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 902, and the processor 901 is used to call and execute the training method and speech recognition method of the speech recognition model of the embodiments of the present application.

[0134] The input / output interface 903 is used to realize information input and output; the communication interface 904 is used to realize communication interaction between this device and other devices, and communication can be realized through wired methods (such as USB, network cable, etc.) or wireless methods (such as mobile network, WIFI, Bluetooth, etc.); the bus 905 transmits information between the various components of the device (such as the processor 901, the memory 902, the input / output interface 903 and the communication interface 904); wherein the processor 901, the memory 902, the input / output interface 903 and the communication interface 904 realize communication connection with each other within the device through the bus 905.

[0135] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the training method and speech recognition method of the above-mentioned speech recognition model.

[0136] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0137] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0138] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0139] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0141] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0142] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0143] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, 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 interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0144] The units described above 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.

[0145] In addition, each functional unit in each embodiment of the present application 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0146] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0147] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for training a speech recognition model, It is characterized in that include: Acquiring training speech data, and inputting the training speech data into an initial speech recognition model; Performing word segmentation processing on the training speech data to obtain a plurality of word units; Obtaining a query and a value of an attention mechanism according to the word-unit; A target word-membrane is selected from the word-membrane according to a target position and a target size of the window, and a key of an attention mechanism is obtained according to the target word-membrane, wherein the number of the target word-membrane is less than the number of the word-membrane, the target position of the window is randomly selected from a position range of the window, and the target size of the window is randomly selected from a size range of the window; obtain an attention feature based on the query, the key, and the value; Classify according to the attention features to obtain predicted text data; The position range and size range of the window are adjusted according to the predicted text data to obtain a trained speech recognition model.

2. The method for training a speech recognition model according to claim 1, It is characterized in that The step of obtaining a query and a value of an attention mechanism according to the word element includes: Obtaining a query of the attention mechanism according to the product of the word-unit and the first weight parameter corresponding to the query; The value of the attention mechanism is obtained according to the product of the word element and the second weight parameter corresponding to the value.

3. The method for training a speech recognition model according to claim 1, It is characterized in that The key of the attention mechanism is obtained according to the target word, including: The key of the attention mechanism is obtained according to the product of the target word and the third weight parameter corresponding to the key.

4. The method for training a speech recognition model according to claim 1, It is characterized in that The obtaining of the attention feature according to the query, the key and the value comprises: Add the positional encoding to the product of the query and the key to obtain an attention score; The attention feature is obtained according to the product of the attention score and the value.

5. The method for training a speech recognition model according to claim 4, It is characterized in that The position encoding corresponding to the i-th attention score is expressed as: in, PE i is the position code corresponding to the i-th attention score, k is a positive integer greater than or equal to 1, and d is the dimension of the training speech data.

6. The method for training a speech recognition model according to claim 1, It is characterized in that The classifying according to the attention feature to obtain predicted text data includes: Classify according to the attention feature to obtain the probability value of each word in the vocabulary corresponding to the attention feature; Determine a target word from the words in the vocabulary according to the probability value; The target words form predicted text data.

7. A speech recognition method, It is characterized in that include: Acquire voice data to be recognized; Inputting the speech data to be recognized into a trained speech recognition model for speech recognition to obtain a speech recognition result; Wherein, the trained speech recognition model is obtained by training according to the speech recognition model training method according to any one of claims 1 to 6.

8. A training device for a speech recognition model, It is characterized in that include: An input module, used to obtain training speech data and input the training speech data into an initial speech recognition model; A word segmentation module, used for performing word segmentation processing on the training speech data to obtain multiple word units; an attention module, configured to obtain a query and a value of an attention mechanism according to the word-grams, select a target word-gram from the word-grams through a window, obtain a key of the attention mechanism according to the target word-grams, and obtain an attention feature according to the query, the key and the value, wherein the number of the target word-grams is less than the number of the word-grams; A classification module, used for classifying according to the attention features to obtain predicted text data; A parameter adjustment module is used to adjust the position and size of the window according to the predicted text data to obtain a trained speech recognition model.

9. An electronic device, It is characterized in that The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the training method of the speech recognition model described in any one of claims 1 to 6 and the speech recognition method described in claim 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the training method of the speech recognition model described in any one of claims 1 to 6 and the speech recognition method described in claim 7 are implemented.

Citation Information

Patent Citations

  • Speech recognizing method and apparatus

    CN108269569A

  • Speech emotion classification method and device, equipment and storage medium

    CN116312644A

  • Multi-modal text error detection method and device, equipment and medium

    CN116629256A

  • Speech recognition method and device, electronic equipment and computer readable storage medium

    CN117789699A

  • Aircraft air conflict detection method based on control voice semantic analysis

    CN118072563A

Cited By

  • Voice activity signal detection method and voice activity signal detection system

    CN120452428A