A language model training method for native speech modality
By constructing training data sets and speech semantic codecs, fine-tuning large language models to have speech understanding and emotion perception capabilities solves the problem of traditional speech models being unable to obtain intonation and emotional information, and achieves efficient and real-time speech interaction capabilities.
Patent Information
- Application Number
- CN202410911342.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-07-09
AI Technical Summary
Traditional large-scale speech models cannot directly obtain the intonation, pauses and emotional information in the user's speech, resulting in limited humanization of replies. The complex system structure leads to increased processing delays, making it difficult to meet the needs of real-time interaction.
Using the language model training method of the native speech mode, we achieve end-to-end speech understanding and generation by building a training data set, building a speech semantic codec, fine-tuning the large language model to have speech understanding and emotion perception capabilities, and conducting quantitative deployment. .
It improves the naturalness, efficiency and real-time nature of interaction, enables large language models to directly process speech output without relying on multiple separation stages, and enhances the model's real-time interaction capabilities.
Smart Images

Figure CN118471202B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of language model training, and in particular to a language model training method of a native speech modality. Background Art
[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) have made remarkable achievements in the field of text processing and are widely used in many fields such as natural language understanding, machine translation, and question-answering systems. However, text interaction has limitations in some scenarios, especially when a more natural and intuitive way of communication is needed. As a modality that is closer to the natural way of human communication, voice has the following unique advantages:
[0003] 1. Voice is one of the most natural ways of communication for people. Using voice mode can provide a more natural and intuitive interactive experience.
[0004] 2. When both hands are busy or vision is limited, voice input provides a hands-free way of interaction, improving convenience.
[0005] 3. Voice can convey emotion and intonation, making communication richer and more humane.
[0006] Despite this, traditional large-scale voice models usually adopt a multi-stage processing flow: first, the voice is converted into text through automatic speech recognition (ARS) technology, then the text is input into a large language model to generate a text response, and finally the text is converted into speech output using text-to-speech (TTS) technology. This process has the following shortcomings:
[0007] 1. Large language models cannot directly obtain the intonation, pauses, and emotional information in the user's voice, which limits the humanization of the response.
[0008] 2. The complex system structure leads to increased processing delays, making it difficult to meet the needs of real-time interaction.
[0009] In order to overcome these limitations, the present invention proposes a language model training method of native speech modality. Summary of the invention
[0010] The present invention provides a language model training method of native speech modality, comprising:
[0011] Step 1: Use the traditional speech model to build a training data set;
[0012] Step 2: Construct a speech semantic codec based on the speech-text pairs in the training dataset;
[0013] Step 3: Use the speech semantic codec to fine-tune the large language model for the first time to enable it to have speech understanding capabilities;
[0014] Step 4: Fine-tune the large language model a second time based on human preferences to enable it to perceive speech intonation and human emotions;
[0015] Step 5: Quantize and stream-deploy the fine-tuned large language model.
[0016] A language model training method for a native speech modality as described above, wherein a training data set is constructed using a traditional speech model, specifically comprises the following sub-steps:
[0017] Use large language models to generate daily conversation text data;
[0018] Generate text data into speech data using a traditional speech model and create speech-text pairs;
[0019] Combine speech-text pairs with real voice conversation data to create a training dataset.
[0020] A language model training method for a native speech modality as described above, wherein a speech semantic codec is constructed based on speech-text pairs in a training data set, specifically comprising the following sub-steps:
[0021] Using speech-text pair data, train a speech semantic encoder-decoder based on self-attention mechanism;
[0022] During the training process of the encoder-decoder, the latent variables of the encoder-decoder are aligned with the text features.
[0023] A language model training method for a native speech modality as described above, wherein the speech semantic codec adopts an encoder-decoder architecture, the encoder is used to convert the original speech input into a series of feature vectors, and the decoder is used as the inverse process of the encoder to convert the feature vectors back into speech signals.
[0024] A language model training method for a native speech mode as described above, wherein two special signals are introduced when fine-tuning a large language model: <audio> ”、"< / audio> " is used to process voice and text multimodal input.
[0025] A language model training method for a native speech modality as described above, wherein a second fine-tuning of the large language model is performed based on human preferences, specifically comprising the following sub-steps:
[0026] Extract real voice conversation data from the training dataset;
[0027] Combine the real speech conversation data with the large language model after the first fine-tuning to construct positive and negative sample pairs;
[0028] The large language model is fine-tuned a second time based on positive and negative sample pairs, introducing human preferences.
[0029] The present invention also provides a language model training system for native voice modality, including: a training data set construction module, a voice semantic encoding and decoding module, a voice multimodal large model acquisition module, and a voice real-time dialogue module;
[0030] A training data set construction module, used to construct a training data set using a traditional speech model;
[0031] A speech semantic codec building module is used to build a speech semantic codec using speech-text pairs in the training dataset;
[0032] A large language model fine-tuning module is used to fine-tune the original large language model to adapt it to the input and output of the native speech modality;
[0033] The speech multimodal large model deployment module is used to quantize and stream deploy the fine-tuned large language model.
[0034] A language model training system for a native voice modality as described above, wherein the training data set construction module includes a text data generation submodule, a voice data generation submodule, and a training data set creation submodule;
[0035] The text data generation submodule is used to generate daily conversation text data using a large language model;
[0036] A speech data generation submodule, for generating speech data from text data using a traditional speech model and creating speech-text pairs;
[0037] The training dataset creation submodule is used to create a training dataset by combining speech-text pairs with real speech conversation data.
[0038] A language model training system for a native speech modality as described above, wherein the speech semantic codec adopts an encoder-decoder architecture, the encoder is used to convert the original speech input into a feature vector, and the decoder is the inverse process of the encoder, and is used to convert the feature vector back into a speech signal.
[0039] The beneficial effects achieved by the present invention are as follows: With relatively low training cost, the present invention converts a large text language model into a large multimodal model with end-to-end speech understanding and generation, which can directly process speech output without relying on multiple separate stages, thereby improving the naturalness, efficiency and real-time nature of the interaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0041] Figure 1 This is a flow chart of a language model training method for a native speech modality provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0042] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention. Embodiment 1
[0043] like Figure 1 As shown, the first embodiment of the present invention provides a language model training method of a native voice mode, including:
[0044] Step S10: constructing a training data set using a traditional speech model;
[0045] Before model training, two types of data resources need to be prepared as training data, namely, synthesized speech-text pairs and real speech dialogue data. In order to effectively control the cost, the present invention adopts a strategy of mainly using synthetic data and supplemented by real data to construct a training data set, which specifically includes the following sub-steps:
[0046] Step S11: Generate daily conversation text data using a large language model;
[0047] First, a large language model is used to generate a large amount of daily conversation text data. This text data is presented in the synthesis markup language SSML format. Synthesis markup language is a language designed specifically for speech synthesis that can contain rich speech expression information such as tone and pauses.
[0048] Step S12: using a traditional speech model to generate text data into speech data and create a speech-text pair;
[0049] The text data in SSML format is input into the text-to-speech (TTS) model to generate the corresponding voice data. Since SSML can guide the TTS model to simulate various characteristics of natural speech, including intonation, rhythm, and emotion, the generated voice data is more realistic, natural, and expressive. The generated voice data and text data are organized into voice-text pairs, represented as ,in Different voice data, are text feature vectors converted from different text data, and m is the number of speech-text pairs. The text feature vector is generated by the text encoder in CLIP.
[0050] Step S13: Creating a training data set by combining the speech-text pairs with the real speech conversation data;
[0051] Although synthetic data dominates the training data set, the present invention also combines a certain proportion (1%) of real voice conversation data. This combined method can ensure that the model can obtain more comprehensive and accurate training signals when learning to simulate real voice scenarios. It is also in this way that efficient model training can be achieved at a lower cost, while ensuring that the model can generate high-quality and natural voice output.
[0052] Step S20: constructing a speech semantic codec based on the speech-text pairs in the training data set;
[0053] The speech semantic codec is used to realize the conversion between feature vectors and speech. Its construction method includes the following sub-steps:
[0054] Step S21: using speech-text pair data, training a speech semantic codec based on a self-attention mechanism;
[0055] The speech semantic codec adopts an encoder-decoder architecture, in which the encoder is used to convert the original speech input into a series of feature vectors that capture the physical characteristics of speech; the decoder is the inverse process of the encoder and is used to convert the feature vectors back into speech signals.
[0056] Step S22: during the training process of the codec, aligning the latent variables of the codec with the text features;
[0057] In order to enhance the semantics of speech features, contrastive learning is introduced in the process of codec training to achieve contrastive learning of speech and text features, so that the speech feature space is close to the text feature space, so that the latent variables obtained by the encoder are aligned with the text features. The loss function of the codec is: ,in represents the feature vector obtained by the encoder of the i-th speech, Representation and The matched text feature vector, i ranges from 1 to N, N is the number of samples in the current training batch, sim is the similarity function between the speech and text features (the dot product similarity function is used in this embodiment), Represents the text feature vector of the jth speech, where j ranges from 1 to N. is the temperature parameter, which is used to control the smoothness of the softmax distribution. Stop training when you stop falling.
[0058] The loss function based on the encoder-decoder is used to amplify the similarity between i and j=i and reduce the similarity between i and j!=i.
[0059] Step S30: Use the speech semantic codec to perform a first fine-tuning on the large language model to enable it to have speech understanding capabilities;
[0060] The original large language model is a text model that can only process text information. Even if the aligned speech features are input into the text model, no effective output can be obtained. This is because the text model has never seen similar data. By using the speech-text pairs encoded by the speech semantic codec and the low-rank adaptation (LoRA) fine-tuning technology, any large language model can be equipped with speech understanding capabilities. This embodiment uses Qwen7B as the base model for the final deployment.
[0061] In order to improve the accuracy and stability of the model, this invention introduces two special tokens: <audio> ”、"< / audio> ", the speech-text multimodal input is processed as follows:
[0062] User: What is the name of the following song? <audio> < / audio> Please help me cover this song using Zhang San's voice.
[0063] AI Assistant: This song is "Any Song" by Li Si, and this is the result of singing it with Zhang San's voice: <audio> < / audio> .
[0064] in is the feature vector sequence obtained by the speech semantic codec of the input speech, is the output feature vector sequence, <audio> ”、"< / audio> " is separated from the preceding and following text features to reduce the difficulty of model training and improve model accuracy and stability.
[0065] Step S40: performing a second fine-tuning on the large language model based on human preferences so that it has the perception of speech intonation and human emotions, which specifically includes the following sub-steps:
[0066] Step S41: extracting real voice conversation data from the training data set;
[0067] Real voice conversation data reflects human pronunciation preferences. Using this data to perform secondary fine-tuning on the large language model can make the voice generated by the model more realistic and vivid.
[0068] Step S42: constructing positive and negative sample pairs by combining the real voice conversation data with the large language model after the first fine-tuning;
[0069] The feature vector output by the speech semantic codec of real speech conversation data is used as a positive sample, and a similar feature vector is generated by a large language model as a negative sample. For example, for the text "Hello", the feature vector encoded into real human speech is a positive sample, and the feature vector of the model-generated speech is a negative sample.
[0070] Step S43: fine-tune the large language model for the second time by introducing human preferences based on positive and negative sample pairs;
[0071] The positive sample in the positive and negative sample pair is generated by real speech data, which is more in line with human preferences. Therefore, it is necessary to train the output of the large language model to be more biased towards positive samples. A loss function based on human preferences is designed for the large language model. The language model is optimized based on the loss function to complete the second fine-tuning of the large language model. The loss function based on human preferences is expressed as:
[0072] in, is a positive sample preferred by humans, For human preference negative samples, It means that when given an input x, Output is better than The probability p of D is a dataset containing input and positive and negative sample pairs. Represents a positive sample given an input x .
[0073] Fine-tune the large language model based on the loss function calculation result L of human preference for N rounds (optionally 3 rounds of human preference fine-tuning) of training data, and ensure that the calculation result of L is as small as possible during fine-tuning.
[0074] Compared with the original large language model, the large language model after two fine-tunings has the ability to understand and generate voice data, and can also understand and perceive voice intonation and emotional rhythm.
[0075] Step S50: quantizing and streaming the fine-tuned large language model;
[0076] In order to support real-time voice conversations, the model needs to be quantized and deployed in a streaming manner. Through AQW quantization technology, the model can be compressed 8 times with almost no impact on performance. The streaming reasoning of the model is then implemented based on the DeepStream architecture, ultimately achieving real-time voice conversations between users and models. Embodiment 2
[0077] Embodiment 2 of the present invention provides a language model training system of native voice modality, including: a training data set construction module, a voice semantic encoding and decoding module, a voice multimodal large model acquisition module, and a voice real-time dialogue module;
[0078] (1) A training data set construction module, which is used to construct a training data set using a traditional speech model, including a text data generation submodule, a speech data generation submodule, and a training data set creation submodule;
[0079] 1. Text data generation submodule, used to generate daily conversation text data using a large language model;
[0080] First, a large language model is used to generate a large amount of daily conversation text data. This text data is presented in the synthesis markup language SSML format. Synthesis markup language is a language designed specifically for speech synthesis that can contain rich speech expression information such as tone and pauses.
[0081] 2. A speech data generation submodule, which is used to generate text data into speech data using a traditional speech model and create speech-text pairs;
[0082] The text data in SSML format is input into the text-to-speech (TTS) model to generate the corresponding voice data. Since SSML can guide the TTS model to simulate various characteristics of natural speech, including intonation, rhythm, and emotion, the generated voice data is more realistic, natural, and expressive.
[0083] The generated voice data and text data are organized into voice-text pairs, represented as ,in Different voice data, are text feature vectors converted from different text data, and m is the number of speech-text pairs. The text feature vector is generated by the text encoder in CLIP.
[0084] 3. A training data set creation submodule, which is used to create a training data set by combining speech-text pairs with real speech conversation data;
[0085] Although synthetic data dominates the training data set, the present invention also combines a certain proportion (1%) of real voice conversation data. This combined method can ensure that the model can obtain more comprehensive and accurate training signals when learning to simulate real voice scenarios. It is also in this way that efficient model training can be achieved at a lower cost, while ensuring that the model can generate high-quality and natural voice output.
[0086] (2) A speech semantic codec construction module, which is used to construct a speech semantic codec using speech-text pairs in the training dataset;
[0087] The speech semantic codec consists of two parts: encoder and decoder:
[0088] 1. The encoder is used to convert the raw speech input into a series of feature vectors that capture the physical characteristics of the speech.
[0089] 2. The decoder is used to convert the feature vector back into a speech signal, which is the inverse process of the encoder.
[0090] The construction process of the speech semantic codec is:
[0091] I. Using speech-text pair data, train a speech-semantic encoder-decoder based on self-attention mechanism;
[0092] II. During the training process of the encoder-decoder, align the latent variables of the encoder-decoder with the text features;
[0093] In order to enhance the semantics of speech features, contrastive learning is introduced in the process of codec training to achieve contrastive learning of speech and text features, so that the speech feature space is close to the text feature space, so that the latent variables obtained by the encoder are aligned with the text features. The loss function of the codec is: ,in represents the feature vector obtained by the encoder of the i-th speech, Representation and The matched text feature vector, i ranges from 1 to N, N is the number of samples in the current training batch, sim is the similarity function between the speech and text features (the dot product similarity function is used in this embodiment), Represents the text feature vector of the jth speech, where j ranges from 1 to N. is the temperature parameter, which is used to control the smoothness of the softmax distribution. Don't stop training on a descent.
[0094] The loss function based on the encoder-decoder is used to amplify the similarity between i and j=i and reduce the similarity between i and j!=i.
[0095] (3) A large language model fine-tuning module, which is used to fine-tune the original large language model to adapt it to the input and output of the native speech modality. Specifically, it includes:
[0096] I. Fine-tune the large language model for the first time based on the speech semantic codec to enable it to have speech understanding capabilities;
[0097] The original large language model is a text model that can only process text information. Even if the aligned speech features are input into the text model, no effective output can be obtained. This is because the text model has never seen similar data. By using the speech-text pairs encoded by the speech semantic codec and the low-rank adaptation (LoRA) fine-tuning technology, any large language model can be equipped with speech understanding capabilities. This embodiment uses Qwen7B as the base model for the final deployment.
[0098] In order to improve the accuracy and stability of the model, this invention introduces two special tokens: <audio> ”、"< / audio> ", the speech-text multimodal input is processed as follows:
[0099] User: What is the name of the following song? <audio> < / audio> Please help me cover this song using Zhang San's voice.
[0100] AI Assistant: This song is "Any Song" by Li Si, and this is the result of singing it with Zhang San's voice: <audio> < / audio> .
[0101] in is the feature vector sequence obtained by the speech semantic codec of the input speech, is the output feature vector sequence, <audio> ”、"< / audio> " is separated from the preceding and following text features to reduce the difficulty of model training and improve model accuracy and stability.
[0102] II. Extracting real speech dialogue data from the training dataset;
[0103] Real voice conversation data reflects human pronunciation preferences. Using this data to perform secondary fine-tuning on the large language model can make the voice generated by the model more realistic and vivid.
[0104] III. Combine the real speech conversation data with the model after the first fine-tuning to construct positive and negative sample pairs;
[0105] The feature vector output by the speech semantic codec of real speech conversation data is used as a positive sample, and a similar feature vector is generated by a large language model as a negative sample. For example, for the text "Hello", the feature vector encoded into real human speech is a positive sample, and the feature vector of the model-generated speech is a negative sample.
[0106] IV. Fine-tune the large language model a second time based on positive and negative sample pairs and introducing human preferences;
[0107] The positive sample in the positive and negative sample pair is generated by real speech data, which is more in line with human preferences. Therefore, it is necessary to train the output of the large language model to be more biased towards positive samples. A loss function based on human preferences is designed for the large language model. The language model is optimized based on the loss function to complete the second fine-tuning of the large language model. The loss function based on human preferences is expressed as:
[0108] in It means that when given an input x, Output is better than The probability p of D is a dataset containing input and positive and negative sample pairs. is a positive sample, is a negative sample, Represents a positive sample given an input x .
[0109] The large language model is fine-tuned for three rounds of training data based on the loss function calculation result L based on human preference, and the calculation result of L is kept as small as possible during fine-tuning.
[0110] Compared with the original large language model, the large language model after two fine-tunings has the ability to understand and generate voice data, and can also understand and perceive voice intonation and emotional rhythm.
[0111] (4) Speech multimodal large model deployment module, used to quantize and stream deploy the fine-tuned large language model;
[0112] In order to support real-time voice conversations, the model needs to be quantized and deployed in a streaming manner. Through AQW quantization technology, the model can be compressed 8 times with almost no impact on performance. The streaming reasoning of the model is then implemented based on the DeepStream architecture, ultimately achieving real-time voice conversations between users and models.
[0113] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A language model training method for native speech modality, characterized in that: The method comprises: Step 1: Use the traditional speech model to build a training data set; Step 2: Construct a speech semantic codec based on the speech-text pairs in the training dataset; Step 3: Use the speech semantic codec to fine-tune the large language model for the first time to enable it to have speech understanding capabilities; Step 4: Fine-tune the large language model a second time based on human preferences to enable it to perceive speech intonation and human emotions; Step 5: Quantize and stream-deploy the fine-tuned large language model; The second fine-tuning of the large language model based on human preferences includes the following sub-steps: Extract real voice conversation data from the training dataset; Combine the real speech conversation data with the large language model after the first fine-tuning to construct positive and negative sample pairs; Fine-tune the large language model a second time based on positive and negative sample pairs to introduce human preferences; Design a loss function based on human preference for the large language model, optimize the language model based on the loss function, and complete the second fine-tuning of the large language model. The loss function based on human preference is expressed as: in, is a positive sample preferred by humans, For human preference negative samples, It means that when given an input x, Output is better than The probability p of D is a dataset containing input and positive and negative sample pairs. Represents a positive sample given an input x .
2. The language model training method of the native speech modality according to claim 1, characterized in that: Using the traditional speech model to build a training data set includes the following sub-steps: Use large language models to generate daily conversation text data; Generate text data into speech data using a traditional speech model and create speech-text pairs; Combine speech-text pairs with real voice conversation data to create a training dataset.
3. The language model training method of the native speech modality according to claim 2, characterized in that: Constructing a speech semantic codec based on the speech-text pairs in the training dataset includes the following sub-steps: Using speech-text pair data, train a speech semantic encoder-decoder based on self-attention mechanism; During the training process of the encoder-decoder, the latent variables of the encoder-decoder are aligned with the text features.
4. The method for training a language model of a native speech modality according to claim 1, characterized in that: The speech semantic codec adopts an encoder-decoder architecture. The encoder is used to convert the original speech input into a feature vector, and the decoder is the inverse process of the encoder, which is used to convert the feature vector back into a speech signal.
5. A language model training system for native speech modality, characterized in that: The system includes: a training data set construction module, a speech semantic encoding and decoding module, a speech multimodal large model acquisition module, and a speech real-time dialogue module; A training data set construction module, used to construct a training data set using a traditional speech model; A speech semantic codec building module is used to build a speech semantic codec using speech-text pairs in the training dataset; A large language model fine-tuning module is used to fine-tune the original large language model to adapt it to the input and output of the native speech modality; The speech multimodal large model deployment module is used to quantize and stream-deploy the fine-tuned large language model; The large language model fine-tuning module specifically includes: using the speech semantic codec to perform the first fine-tuning on the large language model so that it has speech understanding capabilities; performing the second fine-tuning on the large language model based on human preferences so that it has the perception of speech intonation and human emotions; The second fine-tuning of the large language model based on human preferences includes the following sub-steps: Extract real voice conversation data from the training dataset; Combine the real speech conversation data with the large language model after the first fine-tuning to construct positive and negative sample pairs; Fine-tune the large language model a second time based on positive and negative sample pairs to introduce human preferences; Design a loss function based on human preference for the large language model, optimize the language model based on the loss function, and complete the second fine-tuning of the large language model. The loss function based on human preference is expressed as: in, is a positive sample preferred by humans, For human preference negative samples, It means that when given an input x, Output is better than The probability p of D is a dataset containing input and positive and negative sample pairs. Represents a positive sample given an input x .
6. The language model training system of the native speech modality according to claim 5, characterized in that: The training data set construction module includes a text data generation submodule, a speech data generation submodule and a training data set creation submodule; The text data generation submodule is used to generate daily conversation text data using a large language model; A speech data generation submodule, for generating speech data from text data using a traditional speech model and creating speech-text pairs; The training dataset creation submodule is used to create a training dataset by combining speech-text pairs with real speech conversation data.
7. The language model training system of the native speech modality according to claim 5, characterized in that: The speech semantic codec adopts an encoder-decoder architecture. The encoder is used to convert the original speech input into a feature vector, and the decoder is the inverse process of the encoder, which is used to convert the feature vector back into a speech signal.
Citation Information
Patent Citations
Emotion recognition method based on multiple modes and related equipment
CN115775565A
Multi-modal sentiment analysis method, system and equipment based on multivariate loss function and medium
CN116701996A
Audio understanding and generating method based on large-scale audio representation language model
CN116741153A
Emotion recognition method and system based on voice text cross-modal fusion
CN117765981A
Using Aligned Text and Speech Representations to Train Automatic Speech Recognition Models without Transcribed Speech Data
US20240029715A1
