Language model training method and device, reply information generating method and device and medium
By using negative reply text to train language models, the problem of difficulty in ensuring the security of model-generated content in natural language processing is solved, reducing model training costs and improving safe answering capabilities.
Patent Information
- Application Number
- CN202410830671.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-12-22
- Filing Date
- 2024-06-25
- Publication Date
- 2024-09-17
AI Technical Summary
Existing technologies In natural language processing, it is difficult to solve the security problem of content generated by language models, especially due to the high cost of supervised fine-tuning of positive samples and the insufficient generalization ability of the model, which may cause the model to produce harmful answers.
By using negative reply text as training data, the language model is trained so that the generated content avoids negative reply text and improves the security of the output content. The specific method is to obtain training sample data, which contains the first training sample data (including question text and negative reply text) and the second training sample data (including question text and positive reply text), train the language model based on these data, and use the loss The function reduces the similarity between negative reply text and positive reply text, thereby improving the security of the model output.
It effectively reduces the cost of model training and manual annotation, improves the model's ability to safely answer sensitive words, and significantly reduces the probability of risky answers.
Smart Images

Figure CN118656645A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, in particular to the field of natural language processing and intelligent dialogue technology, and in particular to a language model training method, a method and device for generating reply information based on a language model, an electronic device and a storage medium. Background Art
[0002] Artificial intelligence technology is a branch of computer science. It is a technology that achieves intelligence through computers and algorithms. Through continuous learning and evolution, it makes computers more and more "intelligent" and able to perform complex operations such as dialogue, reasoning, and learning. Research in the field of artificial intelligence includes robots, language recognition, image recognition, natural language processing, and expert systems.
[0003] With the rapid development of generative pre-trained model technology in the field of natural language processing, how to ensure the security of model-generated language has gradually become an important issue. Existing algorithms use two methods to deal with the security of model output: 1) supervised fine-tuning using positive samples to guide and correct the model's answers; 2) using positive and negative sample pairs of a question to train a reward model, score the model's output, select safer answers (with higher reward scores) as positive samples, and perform supervised fine-tuning on the model.
[0004] However, there are several problems with directly using positive samples for supervised fine-tuning. 1) The labor cost is high, and a large number of people are required to annotate the instructions with positive answers, wasting a large number of negative samples in the existing corpus; 2) A small number of supervised positive samples cannot generalize the model to instructions with the same semantics but different expressions, and the model is easily induced to produce harmful answers. In order to deal with the generalization problem of the model to harmful instructions, it is proposed to use a positive and negative sample pair of a question to train a reward model, and then use the reward model to score the safety of the model's answer. The score is used to perform rejection sampling (Rejectionsampling) or human preference alignment (Human Perference Alignment) on the model, so that the model tends to generate safe answers that are biased towards human preferences. This alignment method is called reinforcement learning for human feedback (RLHF). However, the cost of training the reward model and the evaluation model in RLHF technology is high, and reinforcement learning has problems such as complex training process, high cost, and difficulty in model training. Summary of the invention
[0005] To this end, the present invention provides a language model training method, device, electronic device and storage medium, in an effort to solve or at least alleviate at least one of the above problems.
[0006] According to one aspect of the present invention, a method for training a language model is provided, comprising: acquiring training sample data and a first language model; wherein the training sample data comprises first training sample data and second training sample data, the first training sample data comprises a first question text and a negative answer text, and the second training sample data comprises the first question text and a positive answer text; and training the first language model based on the training sample data to obtain a second language model.
[0007] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the first training sample data to obtain the trained first language model; and training the trained first language model based on the second training sample data to obtain the second language model.
[0008] Optionally, the step of training the first language model based on the first training sample data to obtain a trained first language model includes: inputting the first training sample data into the first language model, the first language model processing the first training sample data and outputting a predicted probability of a first reply text, the predicted probability of the first reply text including the probability of a group of optional words corresponding to each word in the first reply text; training the first language model based on a first loss to reduce the similarity between the first reply text and the negative reply text.
[0009] Optionally, the first loss is:
[0010]
[0011] Wherein, is the word element vector generated by the first language model, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0012] Optionally, the step of training the trained first language model based on the second training sample data to obtain the second language model includes: inputting the second training sample data into the trained first language model, the trained first language model processing the second training sample data and outputting a predicted probability of a second reply text, the predicted probability of the second reply text including the probability of a group of optional words corresponding to each word in the second reply text; training the trained first language model based on the second loss to reduce the deviation between the second reply text and the positive reply text.
[0013] Optionally, the second loss is a cross entropy loss.
[0014] Optionally, the first language model is a pre-trained language model.
[0015] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the second training sample data to obtain the trained first language model; and training the trained first language model based on the first training sample data to obtain the second language model.
[0016] Optionally, the step of training the trained first language model based on the first training sample data to obtain the second language model includes: inputting the first training sample data into the trained first language model, the trained first language model processing the first training sample data and outputting a predicted probability of a third reply text, the predicted probability of the third reply text including the probability of a group of optional words corresponding to each word in the third reply text; training the trained first language model based on a third loss to reduce the similarity between the third reply text and the negative reply text.
[0017] Optionally, the third loss is:
[0018]
[0019] Wherein, is the word element vector generated by the first language model after training, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0020] According to another aspect of the present invention, a method for generating reply information based on a language model is provided, comprising: obtaining a question text; inputting the question text into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to the above-mentioned training method.
[0021] According to another aspect of the present invention, a language model training device is provided, comprising: an acquisition module, used to acquire training sample data and a first language model, wherein the training sample data includes first training sample data and second training sample data, the first training sample data includes a first question text and a negative answer text, and the second training sample data includes the first question text and a positive answer text; and a training module, used to train the first language model based on the training sample data to obtain a second language model.
[0022] According to another aspect of the present invention, a language model-based reply information generating device is provided, comprising: a question acquisition module for acquiring a question text; a text output module for inputting the question text into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to the above-mentioned training method.
[0023] According to another aspect of the present invention, there is provided an electronic device, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be suitable for execution by the at least one processor, and the program instructions include instructions for executing the above-mentioned training method.
[0024] According to another aspect of the present invention, a readable storage medium storing program instructions is provided. When the program instructions are read and executed by a computing device, the computing device executes the above-mentioned training method.
[0025] The language model training method provided in the present application trains the language model by using negative response text as negative sample training data, so that the content output by the trained language model avoids the negative response text, thereby improving the security of the content output by the language model. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings. The drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the drawings, the same reference numerals generally represent the same components or steps.
[0027] Figure 1 is a schematic block diagram of an electronic device according to an embodiment of the present invention;
[0028] Figure 2 is a schematic flow chart of a method for training a language model according to an embodiment of the present invention;
[0029] Figure 3 is a schematic diagram of a method for processing input and output of a language model during training according to an embodiment of the present invention;
[0030] Figure 4 is a schematic flow chart of step S220 in the training method according to an embodiment of the present invention;
[0031] Figure 5 is another schematic flow chart of step S220 in the training method according to an embodiment of the present invention;
[0032] Figure 6 is a schematic flow chart of a method for generating reply information based on a language model according to an embodiment of the present invention;
[0033] Figure 7 is a schematic diagram of a language model training device according to an embodiment of the present invention;
[0034] Figure 8 It is a schematic diagram and block diagram of a device for generating reply information based on a language model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0036] The embodiment of the present application provides a language model training method, device, electronic device and storage medium, which can be applied to the field of text generation. The training method includes obtaining first training sample data and a first language model, wherein the first training sample data includes a first question text and a negative answer text; and training the first language model based on the first training sample data to obtain a second language model. The training method solves the problem of complex training process and high cost in the prior art.
[0037] The training method provided in the embodiments of the present application can be applied to electronic devices with computing and processing capabilities, which may be mobile phones, tablet computers, desktop computers, laptop computers, servers, vehicle-mounted devices, netbooks, as well as augmented reality (AR) devices, virtual reality (VR) devices, smart speakers, artificial intelligence robots, etc. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device.
[0038] Figure 1 FIG. 1 is a schematic diagram showing the structure of an electronic device 100 according to an embodiment of the present invention. The electronic device can be used to implement the methods of various embodiments of the present invention. Figure 1 As shown, in a basic configuration 102, the electronic device 100 typically includes a memory 106 and one or more processors 104. A memory bus 108 may be used for communication between the processor 104 and the memory 106.
[0039] Depending on the desired configuration, the processor 104 may be any type of processor, including but not limited to: a microprocessor, a microcontroller, a digital signal processor (DSP), or any combination thereof. The processor 104 may include one or more levels of cache, such as a primary cache 110 and a secondary cache 112, a processor core 114, and registers 116. An example processor core 114 may include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core, or any combination thereof. In some implementations, the memory controller 118 may be a separate component used with the processor 104; in some other implementations, the memory controller 118 may be an internal component of the processor 104.
[0040] Depending on the desired configuration, the memory 106 can be any type of memory, including but not limited to: volatile memory (such as RAM, etc.), non-volatile memory (such as ROM, flash memory, etc.) or any combination thereof. The physical memory in the electronic device generally refers to the volatile memory RAM, and the data in the disk needs to be loaded into the physical memory before it can be read by the processor 104. The memory 106 can store an operating system 120 and one or more applications 122. In some embodiments, the application 122 can be arranged to execute instructions on the operating system by one or more processors 104. The operating system 120 can be, for example, Linux, Windows, Android, Hongmeng, Apple iOS, etc., which includes program instructions for processing basic system services and performing hardware-dependent tasks. The application 122 includes program instructions for implementing various user-desired functions. The application 122 can be, for example, a browser, game software, business software, office software, instant messaging software, software development tools (such as integrated development environment IDE, compiler, etc.), etc., but is not limited thereto. When the application 122 is installed in the electronic device 100, a driver module can be added to the operating system 120 if necessary.
[0041] When the electronic device 100 starts running, the processor 104 reads and executes the program instructions of the operating system 120 from the memory 106. The application 122 runs on the operating system 120 and uses the interface provided by the operating system 120 and the underlying hardware to implement various functions desired by the user. When the user starts the application 122, the processor 104 reads and executes the program instructions of the application 122 from the memory 106.
[0042] The electronic device 100 may also include an interface bus 140 that facilitates communication from various interface devices (e.g., output devices 142, peripheral interfaces 144, and communication devices 146) to the basic configuration 102 via the bus / interface controller 130. Example output devices 142 include a graphics processing unit 148 and an audio processing unit 150. They can be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 152. Example peripheral interfaces 144 may include a serial interface controller 154 and a parallel interface controller 156, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboards, mice, voice input devices, touch input devices, handwriting input devices, etc.) or other peripherals (e.g., printers, scanners, etc.) via one or more I / O ports 158. Example communication devices 146 may include a network controller 160, which may be configured to facilitate communication with one or more other electronic devices via a network communication link via one or more communication ports 164.
[0043] A network communication link can be an example of a communication medium. Communication media can generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. As a non-limiting example, communication media can include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable medium used herein can include both storage media and communication media.
[0044] In the electronic device 100 according to the present invention, the application 122 includes instructions for executing the language model training method of the present invention, and the instructions can instruct the processor 104 to execute the language model training method of the present invention.
[0045] It is to be understood that the structure shown in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include: Figure 1 More or fewer components are shown, or some components are combined, or some components are separated, or there are different component arrangements. The components shown can be implemented in hardware, software, firmware, or any combination of the three.
[0046] For ease of understanding, the relevant terms involved in this application are first explained.
[0047] 1. Pre-training and fine-tuning
[0048] Pre-training refers to the process of training a model on large-scale unlabeled data. In Natural Language Processing (NLP), pre-training is the initial stage of language model learning. During pre-training, the model is exposed to a large amount of unlabeled text data, such as books, articles, and websites. Train a language model on a large amount of unlabeled text data. For example, a language model like GPT-3 is pre-trained on a dataset containing millions of books, articles, and websites. The goal of pre-training is to capture the underlying patterns, structures, and semantic knowledge present in the text corpus.
[0049] Fine-tuning refers to the supervised training of a model using a small amount of labeled data based on a pre-trained model. Through fine-tuning, the pre-trained model can adapt to the data and objectives of a specific task, improving the performance of the model on that task. In natural language processing, fine-tuning is the process of further training a large language model (LLM) on a specific task or domain. Specifically, fine-tuning can be seen as using a pre-trained LLM as the initial model and then training it on a labeled dataset for a specific task or domain. Fine-tuning can improve the performance of the LLM on a specific task or domain by adjusting the weights of the model to better fit the data.
[0050] Pre-training and fine-tuning techniques are widely used in the field of NLP, covering tasks such as text classification, named entity recognition, sentiment analysis, and machine translation. Through pre-training and fine-tuning, the model can learn general semantic representations from large-scale unlabeled data, allowing the model to better understand and process natural language.
[0051] Taking text classification as an example, pre-trained models such as BERT can learn rich semantic representations by pre-training on large-scale unlabeled data. Then, by fine-tuning on labeled text classification data, the model can adapt to the data and objectives of a specific classification task and improve the accuracy of classification.
[0052] Pre-training focuses on unsupervised learning from large-scale unlabeled data to acquire general language understanding. Fine-tuning builds on pre-training and uses task-specific labeled data to adapt the model to a specific task, thereby achieving specialized performance.
[0053] 2. Pre-trained language model
[0054] A pre-trained language model is a language model obtained through pre-training. The pre-trained language model adopts a two-stage learning method. First, the model is trained on a large corpus to enable the model to learn universal language representation, and then the pre-trained model is fine-tuned according to different downstream tasks.
[0055] 3. Reward Model
[0056] The reward model is derived from the reward function in reinforcement learning. It can describe the current state with a score to show how much value this state generates. The reward model in the fine-tuning of the large language model calculates a score for the input question and answer. The higher the match between the input answer and the question, the higher the score output by the reward model.
[0057] 4. Autoregressive Language Model
[0058] The autoregressive language model generates text by predicting the next token in a text sequence. During the training process, the model processes the input sequence token by token and predicts the probability distribution of the next token. During the generation process, the model gradually generates new tokens based on the context and the generated tokens until the entire text sequence is completed.
[0059] 5. Token
[0060] In natural language processing, a token refers to a basic unit in a text, which can usually be a word, a phrase, a punctuation mark, a character, etc., depending on the needs and methods of text processing.
[0061] 6. Large Model
[0062] In the field of artificial intelligence technology, a large model usually refers to a deep neural network model with a large number of parameters (for example, hundreds of millions of scale). Among them, a large language model (LLM) is a deep learning model that is trained with a large amount of text data and can process natural language (for example, generate natural language text or understand the meaning of language text, etc.). The large language model can process not only text, but also images and sounds. The training text data used in the training of the large language model usually corresponds to at least one natural language task. Therefore, the large language model obtained by training has good natural language processing capabilities and can realize the generation of natural language text or the understanding of language text. The large language model has a wide range of application scenarios, including but not limited to chatbots, language translation, content creation, etc. This application does not impose any restrictions on the specific network structure of the large language model used.
[0063] Below, based on the above-mentioned hardware involved in the embodiments of the present application, other embodiments of the present application will be described in detail in conjunction with the accompanying drawings.
[0064] like Figure 2 As shown, an embodiment of the present invention provides a method for training a language model. For example, the method can be Figure 1 Specifically, the method may include:
[0065] Step S210: Acquire training sample data and a first language model; wherein the training sample data includes first training sample data and second training sample data, the first training sample data includes a first question text and a negative answer text, and the second training sample data includes the first question text and a positive answer text;
[0066] Among them, the first training sample data and the second training sample data can both adopt some existing data or data that is easier to obtain, such as sample data in the existing corpus and sample data used in training the reward model; this can save time for manual data labeling and improve the efficiency of obtaining training data.
[0067] Negative reply text is the reply text that the language model is expected to avoid outputting as much as possible. Specifically, the negative reply text can be the answer to the first question text that the language model is not expected to output, which may be some sensitive replies, unsafe replies or negative replies. For example, assuming that the sensitive reply is a reply containing "first" or "most", and the first question text is "Which restaurant nearby has better food?", the negative reply text may be "Restaurant A tastes the best." Positive reply text is the reply text that the language model is expected to output, which is opposite to the negative reply text. Specifically, the positive reply text may be a positive text, a non-sensitive text, or a relatively safe text. For example, the first question text is "Which restaurant nearby has better food?", and the positive reply text may be "Everyone's evaluation of the taste of the food in Restaurant A is better." The training of the language model with negative reply text mainly makes the trained model try not to output text that is not expected to be output, but the specific text output by the model may be random; in order to make the text output by the trained language model more targeted, the positive reply text is trained, so that the language model can output the corresponding text according to the training requirements.
[0068] Step S220: training the first language model based on the training sample data to obtain a second language model.
[0069] In the embodiment of the present application, the first language model may be a pre-trained language model. The first language model and the second language model may be autoregressive language models, such as chatgpt, Wenxinyiyan, llama, CHATGML, etc. Specifically, the first language model and the second language model in the embodiment of the present invention may be large language models. When the first language model is a pre-trained language model, step S220 may be a fine-tuning operation on the first language model.
[0070] The training sample data contains negative response texts, so that the content output by the trained second language model can avoid negative response texts when it is actually used, thereby improving the security of the model output content. Through the training method of the embodiment of the present application, the language model obtained after training "hates" certain instructions and their responses, thereby spontaneously generating safe answers, effectively reducing the labor and training costs of increasing the security of the model.
[0071] The training method in the embodiment of the present application can greatly reduce the labor cost and model training cost of increasing the security of the model. Experiments show that using negative samples (i.e., training samples containing negative reply texts) to train the model can effectively generate safe answers to sensitive words in the instructions while maintaining the original effectiveness of the model. For example, it can produce a rejection result for harmful instructions that have no positive samples (i.e., training samples containing positive reply texts), while increasing the probability of safe answers. Experiments show that the solution of the embodiment of the present invention can reduce risky answers from 30% to 6% on a self-built security data set.
[0072] In the embodiments of the present application, Figure 4 As shown, step S220 specifically includes:
[0073] S2201: Training the first language model based on first training sample data to obtain a trained first language model;
[0074] S2203: Training the trained first language model based on second training sample data to obtain a second language model.
[0075] Specifically, S2201 includes:
[0076] S22011: inputting the first training sample data into the first language model, the first language model processes the first training sample data and outputs a predicted probability of the first reply text, the predicted probability of the first reply text including the probability of a group of optional words corresponding to each word in the first reply text;
[0077] S22013: Training a first language model based on a first loss to reduce the similarity between the first reply text and the negative reply text.
[0078] In step S22011, the first reply text contains at least one word. Each word of the first reply text is selected from a group of optional words corresponding to each word. There are as many groups of optional words as there are words in the first reply text. The number of words contained in each group of optional words is the same, and the specific words are also the same. Only the probabilities are different. The sum of the probabilities of all optional words contained in each group of optional words is 1. The probability of an optional word represents the probability of being the target word in the output answer. Ultimately, the word with the highest probability in each group of words will be selected as the word of the first reply text. In 22013, the similarity between the first reply text and the negative reply text can specifically be the probability of the same words in the two texts.
[0079] Specific as Figure 3 As shown in , S represents the first training sample data input to the language model, where the white box represents the first question text, the gray box represents the negative answer text, and the number of boxes represents the number of words. Figure 3In , the first question text is 2 words and the negative answer text is 3 words. The language model outputs the word meta-vector y^, where y^ represents the output word meta-vector of each token. Figure 3 The first reply text in y^ contains 3 words, so the output contains 3 word element vectors, each word element vector contains N probability values, each probability value corresponds to a word (i.e., a selectable word), the black indices in y^ are the indices selected by the current word element, and the white indices are the indices that are not selected; in the vector on the right, the black indices that the current token needs to be encouraged to approach 1 / (N-1), and the white indices that are set to zero. In other words, through the training of the language model, the output word element vector should gradually approach the right from the left.
[0080] For example, the input of the language model is "Which restaurant nearby has better food? The best restaurant is Restaurant A". A set of optional words and indexes are shown in Table 1, which contains 10 optional words. The word with the highest probability is "most". The final training goal is to make the index corresponding to "most" close to 0, and the index of other optional words close to 1 / N-1, where N is 10, which is close to 1 / 9.
[0081] Table 1
[0082] Optional words index I 0.001 of 0.02 like 0.008 most 0.5 people 0.003 since 0.05 No 0.09 have 0.1 sky 0.13 earth 0.098
[0083] In step S2203, reducing the similarity between the first reply text and the negative reply text means increasing the difference between the first reply text and the negative reply text, making the words in the first reply text as different as possible from the words in the negative reply text, and avoiding the first language model from outputting the negative reply text in the end. The first loss reflects the similarity between the first reply text and the negative reply text, so to achieve the purpose of training the model, it is necessary to minimize the first loss. Specifically, the first loss is
[0084]
[0085] in, is the word element vector generated by the first language model during training, N is the vocabulary size, y={y0,y1,...,y N}, if j is the index of a negative sample word (i.e., a word in the negative reply text) in the vocabulary, then y j =1,y k =0(k≠j).
[0086] By training the language model through the first loss, the output of the language model can be encouraged to be close to other word-grams except the harmful sample word-grams, so as to forget the attention between the harmful answer and the keywords in the answer.
[0087] The training method provided in the embodiment of the present application utilizes harmful corpus (negative samples) and cooperates with the first loss to encourage the language model to generate responses other than negative samples to harmful sensitive words in the instructions, thereby increasing the probability of harmless responses (such as refusing to answer).
[0088] When the first language model is a pre-trained language model, this training method can effectively help the pre-trained language model forget the incorrect knowledge and effectively refuse to answer sensitive questions in the pre-training data.
[0089] In the embodiment of the present application, step S2203 includes:
[0090] S22031: inputting the second training sample data into the trained first language model, the trained first language model processes the second training sample data and outputs a predicted probability of the second reply text, the predicted probability of the second reply text including a probability of a group of optional words corresponding to each word in the second reply text;
[0091] S22033 trains the trained first language model based on the second loss to reduce the deviation between the second reply text and the positive reply text.
[0092] Reducing the deviation between the second reply text and the positive reply text means reducing the difference between the first reply text and the positive reply text, making the words in the second reply text as similar as possible to the words in the negative reply text, and encouraging the first language model to finally output the positive reply text. The second loss reflects the deviation between the second reply text and the positive reply text, so the purpose of training the model is to minimize the second loss. Specifically, the second loss can be a cross entropy loss.
[0093] In the embodiment of the present invention, Figure 5 As shown, there is another solution for step S220, which specifically includes:
[0094] S22010: Training the first language model based on the second training sample data to obtain a trained first language model;
[0095] S22030: Train the trained first language model based on the first training sample data to obtain the second language model.
[0096] The solution here is different from the previous solution in that the first language model is first trained with the positive response text, and then the trained first language model is trained with the negative response text.
[0097] Specifically, S22030 includes:
[0098] S220301: inputting the first training sample data into the trained first language model, the trained first language model processes the first training sample data and outputs a predicted probability of the third reply text, the predicted probability of the third reply text including the probability of a group of optional words corresponding to each word in the third reply text;
[0099] S220303: Training the trained first language model based on the third loss to reduce the similarity between the third reply text and the negative reply text.
[0100] Specifically, the third loss is:
[0101]
[0102] in, is the word element vector generated by the first language model after training, N is the vocabulary size, y={y0,y1,…,y N}, if j is the index of each word in the negative answer text in the vocabulary, then y j =1,y k =0(k≠j).
[0103] In the embodiment of the present invention, S22010 specifically includes:
[0104] S220101: input the second training sample data into the first language model, and the first language model processes the second training sample data and outputs a predicted probability of the fourth reply text, where the predicted probability of the fourth reply text includes a probability of a group of optional words corresponding to each word in the fourth reply text;
[0105] S220103: Training the first language model based on the fourth loss to reduce the deviation between the fourth reply text and the positive reply text.
[0106] Specifically, the fourth loss is a cross entropy loss. The first language model is a pre-trained language model.
[0107] Figure 6 A method for generating reply information based on a language model according to an embodiment of the present invention is shown, the method comprising:
[0108] S310: Obtain question text;
[0109] S320: Input the question text into the above-mentioned language model to obtain a reply text generated by the language model, wherein the above-mentioned language model is trained by the above-mentioned training method.
[0110] If the language model outputs a word meta-vector (that is, the output contains the probability value of the optional words), it is necessary to use the argmax function to select the word corresponding to the maximum probability value in each word meta-vector as the output.
[0111] For example, the question text may be "What's the weather like today?", and the response text output by the language model may be "Sunny".
[0112] The above method (including the training method and / or the reply information generating method) in the embodiment of the present application can be executed by a data processing device, and can also be executed by a chip in the data processing device.
[0113] Figure 7 A schematic block diagram of a language model training device 200 provided in an embodiment of the present invention is shown.
[0114] like Figure 7 As shown, the training device 200 according to an embodiment of the present invention includes an acquisition module 210 and a training module 220 .
[0115] Among them, the acquisition module 210 is used to obtain training sample data and a first language model, wherein the training sample data includes first training sample data and second training sample data, the first training sample data includes a first question text and a negative answer text, and the second training sample data includes a first question text and a positive answer text; the training module 220 is used to train the first language model based on the training sample data to obtain a second language model.
[0116] Specifically, the training module 220 specifically includes two cases. In the first case, the training module 220 includes a first training module 221 and a second training module 222. The first training module 221 is used to train the first language model based on the first training sample data to obtain the trained first language model; the second training module 222 is used to train the trained first language model based on the second training sample data to obtain the second language model.
[0117] Specifically, the first training module 221 includes a first processing module 2211 and a first adjustment module 2212 .
[0118] Among them, the first processing module 2201 is used to input the first training sample data into the first language model, and the pre-training model outputs the predicted probability of the first reply text after processing the first training sample data. The predicted probability of the first reply text includes the probability of a group of optional words corresponding to each word in the first reply text; the first adjustment module 2202 is used to train the first language model based on the first loss to reduce the similarity between the first reply text and the negative reply text. Specifically, the first loss is
[0119]
[0120] in, is the word element vector generated by the first language model during training, N is the vocabulary size, y={y0,y1,...,y N}, if j is the index of a negative sample word (i.e., a word in the negative reply text) in the vocabulary, then y j =1,y k =0(k≠j).
[0121] In the embodiment of the present application, the second training module 222 includes a second processing module 2221 and a second adjustment module 2222 .
[0122] Among them, the second processing module 2221 is used to input the second training sample data into the trained first language model, and the trained first language model processes the second training sample data and outputs the predicted probability of the second reply text, and the predicted probability of the second reply text includes the probability of a group of optional words corresponding to each word in the second reply text; the second adjustment module 2222 is used to train the trained first language model based on the second loss to reduce the deviation between the second reply text and the positive reply text. Specifically, the second loss is a cross entropy loss.
[0123] In the second case, the training module 220 includes a third training module 223 and a fourth training module 224. The third training module 223 is used to train the first language model based on the second training sample data to obtain the trained first language model; the fourth training module 224 is used to train the trained first language model based on the first training sample data to obtain the second language model.
[0124] The fourth training module 224 specifically includes a third processing module 2241 and a third adjustment module 2242, wherein the third processing module 2241 is used to input the first training sample data into the trained first language model, and the trained first language model processes the first training sample data and outputs the predicted probability of the third reply text, and the predicted probability of the third reply text includes the probability of a group of optional words corresponding to each word in the third reply text; the third adjustment module 2242 is used to train the trained first language model based on the third loss, so as to reduce the similarity between the third reply text and the negative reply text.
[0125] Specifically, the third loss is:
[0126]
[0127] in, is the word element vector generated by the first language model after training, N is the vocabulary size, y={y0,y1,...,y N}, if j is the index of each word in the negative answer text in the vocabulary, then y j =1,y k =0(k≠j).
[0128] like Figure 8 As shown, the embodiment of the present application provides a language model-based reply information generating device 300 , which includes a question acquisition module 310 and a text output module 320 .
[0129] Among them, the question acquisition module 310 is used to obtain the question text; the text output module 320 is used to input the question text into the language model to obtain the reply text generated by the language model, wherein the language model is trained by the training method in the embodiment of the present application.
[0130] It should be noted that the modules mentioned in the embodiments of the present application are all logical modules. Physically, a logical unit can be a physical module, or a part of a physical module, or can be implemented as a combination of multiple physical modules. The physical implementation of these logical modules themselves is not the most important. The combination of functions implemented by these logical modules is the key to solving the technical problems proposed by this application. Specifically, the modules in the embodiments of the present application may refer to application specific integrated circuits (ASICs), electronic circuits, processors (such as shared processors, proprietary processors or group processors, etc.) and memories for executing one or more software or firmware programs, merged logic circuits and / or other suitable components that support the described functions.
[0131] The training device 200 and / or the reply information generating device 300 have the function of implementing the corresponding steps executed by the data processing device in the above method; the above functions can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. For example, the first acquisition module 210 and the question acquisition module 310 can both be communication interfaces, such as transceiver interfaces.
[0132] The training device 200 and / or the reply information generating device 300 of the embodiment of the present invention may be composed of Figure 1 The electronic device 100 shown runs program instructions to implement and execute various steps in the training method and / or reply information generating method according to the embodiments of the present invention.
[0133] According to an exemplary embodiment of the present invention, an electronic device is provided. The electronic device may include at least one processor and at least one memory. The memory stores program codes for implementing the corresponding steps in the training method and / or the reply information generating method according to the embodiment of the present invention. The processor is used to run the program codes stored in the memory to execute the corresponding steps in the training method and / or the reply information generating method according to the embodiment of the present invention, and to implement the various modules in the training device and / or the reply information generating device according to the embodiment of the present invention. The electronic device may adopt the aforementioned Figure 1 The electronic devices in the illustrated embodiments and any other suitable electronic devices.
[0134] In one embodiment, when the program code is executed by a processor, the following steps are performed:
[0135] A method for training a language model comprises: obtaining training sample data and a first language model; wherein the training sample data comprises first training sample data and second training sample data, the first training sample data comprises a first question text and a negative answer text, and the second training sample data comprises the first question text and a positive answer text; and training the first language model based on the training sample data to obtain a second language model.
[0136] In addition, when the program code is executed by the processor, the following steps are also performed:
[0137] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the first training sample data to obtain the trained first language model; and training the trained first language model based on the second training sample data to obtain the second language model.
[0138] Optionally, the step of training the first language model based on the first training sample data to obtain a trained first language model includes: inputting the first training sample data into the first language model, the first language model processing the first training sample data and outputting a predicted probability of a first reply text, the predicted probability of the first reply text including the probability of a group of optional words corresponding to each word in the first reply text; training the first language model based on a first loss to reduce the similarity between the first reply text and the negative reply text.
[0139] Optionally, the first loss is:
[0140]
[0141] Wherein, is the word element vector generated by the first language model, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0142] Optionally, the step of training the trained first language model based on the second training sample data to obtain the second language model includes: inputting the second training sample data into the trained first language model, the trained first language model processing the second training sample data and outputting a predicted probability of a second reply text, the predicted probability of the second reply text including the probability of a group of optional words corresponding to each word in the second reply text; training the trained first language model based on the second loss to reduce the deviation between the second reply text and the positive reply text.
[0143] Optionally, the second loss is a cross entropy loss.
[0144] Optionally, the first language model is a pre-trained language model.
[0145] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the second training sample data to obtain the trained first language model; and training the trained first language model based on the first training sample data to obtain the second language model.
[0146] Optionally, the step of training the trained first language model based on the first training sample data to obtain the second language model includes: inputting the first training sample data into the trained first language model, the trained first language model processing the first training sample data and outputting a predicted probability of a third reply text, the predicted probability of the third reply text including the probability of a group of optional words corresponding to each word in the third reply text; training the trained first language model based on a third loss to reduce the similarity between the third reply text and the negative reply text.
[0147] Optionally, the third loss is:
[0148]
[0149] Wherein, is the word element vector generated by the first language model after training, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0150] In another embodiment, when the program code is executed by a processor, the following steps are performed:
[0151] A method for generating reply information based on a language model comprises: obtaining a question text; inputting the question text into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to the training method of an embodiment of the present invention.
[0152] In addition, according to another embodiment of the present invention, a computer-readable storage medium is provided, on which program instructions are stored, and when the program instructions are executed by a computer or a processor, they are used to execute the corresponding steps of the training method and / or the reply information generation method of the embodiment of the present invention, and are used to implement the corresponding modules in the training device and / or the reply information generation device according to the embodiment of the present invention. The storage medium may include, for example, a memory card of a smart phone, a storage component of a tablet computer, a hard disk of a personal computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer-readable storage medium may be any combination of one or more computer-readable storage media.
[0153] In one embodiment, when the computer program instructions are executed by a computer, they can implement the various functional modules of the training device and / or the reply information generating device according to the embodiments of the present invention, and / or can execute the training method and / or the reply information generating method according to the embodiments of the present invention.
[0154] In one embodiment, the computer program instructions, when executed by a computer, perform the following steps:
[0155] A method for training a language model comprises: obtaining training sample data and a first language model; wherein the training sample data comprises first training sample data and second training sample data, the first training sample data comprises a first question text and a negative answer text, and the second training sample data comprises the first question text and a positive answer text; and training the first language model based on the training sample data to obtain a second language model.
[0156] In addition, the computer program instructions, when executed by a computer, further perform the following steps:
[0157] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the first training sample data to obtain the trained first language model; and training the trained first language model based on the second training sample data to obtain the second language model.
[0158] Optionally, the step of training the first language model based on the first training sample data to obtain a trained first language model includes: inputting the first training sample data into the first language model, the first language model processing the first training sample data and outputting a predicted probability of a first reply text, the predicted probability of the first reply text including the probability of a group of optional words corresponding to each word in the first reply text; training the first language model based on a first loss to reduce the similarity between the first reply text and the negative reply text.
[0159] Optionally, the first loss is:
[0160]
[0161] Wherein, is the word element vector generated by the first language model, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0162] Optionally, the step of training the trained first language model based on the second training sample data to obtain the second language model includes: inputting the second training sample data into the trained first language model, the trained first language model processing the second training sample data and outputting a predicted probability of a second reply text, the predicted probability of the second reply text including the probability of a group of optional words corresponding to each word in the second reply text; training the trained first language model based on the second loss to reduce the deviation between the second reply text and the positive reply text.
[0163] Optionally, the second loss is a cross entropy loss.
[0164] Optionally, the first language model is a pre-trained language model.
[0165] Optionally, the training the first language model based on the training sample data to obtain the second language model includes: training the first language model based on the second training sample data to obtain the trained first language model; and training the trained first language model based on the first training sample data to obtain the second language model.
[0166] Optionally, the step of training the trained first language model based on the first training sample data to obtain the second language model includes: inputting the first training sample data into the trained first language model, the trained first language model processing the first training sample data and outputting a predicted probability of a third reply text, the predicted probability of the third reply text including the probability of a group of optional words corresponding to each word in the third reply text; training the trained first language model based on a third loss to reduce the similarity between the third reply text and the negative reply text.
[0167] Optionally, the third loss is:
[0168]
[0169] Wherein, is the word element vector generated by the first language model after training, N is the vocabulary size, and if j is the index of each word in the negative reply text in the vocabulary, then y j =1,y k =0(k≠j).
[0170] In another embodiment, the computer program instructions, when executed by a computer, perform the following steps:
[0171] A method for generating reply information based on a language model comprises: obtaining a question text; inputting the question text into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to the above-mentioned training method.
[0172] Each module of the training device and / or the reply information generating device according to an embodiment of the present invention can be implemented by executing computer program instructions stored in a memory by a processor of an electronic device according to an embodiment of the present invention, or can be implemented when computer instructions stored in a computer-readable storage medium according to an embodiment of the present invention are executed by a computer.
[0173] According to the training method and / or reply information generating method and device, electronic device and storage medium of the embodiments of the present invention, by using training sample data containing negative reply text to train the language model, the language model can avoid the appearance of unsafe words or sensitive words in the output text, thereby improving the security of the output content of the language model.
[0174] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely exemplary and are not intended to limit the scope of the present invention thereto. Various changes and modifications may be made therein by one of ordinary skill in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as required by the appended claims.
[0175] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0176] The various techniques described herein may be implemented in combination with hardware or software, or a combination thereof. Thus, the method, apparatus, and device of the present invention, or some aspects or portions of the method, apparatus, and device of the present invention may be in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, a USB flash drive, a floppy disk, a CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes a device for practicing the present invention.
[0177] In the case where the program code is executed on a programmable computer, the electronic device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code; the processor is configured to execute the remote assistance method of the present invention according to the instructions in the program code stored in the memory.
[0178] By way of example and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer-readable instructions, data structures, program modules or other data. Communication media generally embody computer-readable instructions, data structures, program modules or other data in modulated data signals such as carrier waves or other transmission mechanisms, and include any information transmission medium. Any combination of the above is also included in the scope of readable media. In the specification of the present application, algorithms and displays are not inherently related to any specific computer, virtual system or other device. Various general systems can also be used with the examples of the present invention. According to the above description, it is obvious to construct the structure required for such systems. In addition, the present invention is not directed to any specific programming language. It should be understood that various programming languages can be used to implement the software and algorithm-related content of the present invention described herein, and the description of the specific language above is only to disclose some specific embodiments of the present invention, but not to limit the use of the specific language.
[0179] In the specification of the application, a lot of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this specification.
[0180] In the several embodiments provided in this application, it should be understood that the disclosed devices, equipment and methods can be implemented in other ways. For example, the above-described device and equipment embodiments are only illustrative, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
[0181] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0182] Similarly, it should be understood that in order to streamline the present invention and help understand one or more of the various inventive aspects, in the description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, the method of the present invention should not be interpreted as reflecting the following intention: the claimed invention requires more features than the features explicitly stated in each claim. More specifically, as reflected in the corresponding claims, the inventive point is that the corresponding technical problem can be solved with less than all the features of a single disclosed embodiment. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present invention.
[0183] It will be understood by those skilled in the art that, except for mutually exclusive features, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this specification may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature that provides the same, equivalent or similar purpose.
[0184] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.
[0185] The components in the various embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that computers, servers, microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some modules in the equipment and devices according to embodiments of the present invention. The present invention can also be implemented as a device program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0186] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. Nouns such as "comprise", "include", "have" do not exclude the presence of elements or steps not listed in the claims. The quantifier "one" or "a" preceding an element does not exclude the presence of multiple such elements. The present invention can be implemented by means of hardware including several different elements and by means of appropriately programmed computers. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order, and these words may be interpreted as names.
[0187] In addition, in the embodiments of the present application, the expression "and / or" includes any and all combinations of the associated listed words. For example, the expression "A and / or B" may include A, may include B, or may include both A and B. Words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way. In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more.
[0188] In the description of the embodiments of the present application, when a component is referred to as being "connected" or "accessed" to other components, it should be understood that: the component is not only directly connected to or accessed to other components, but also another component may exist between the component and the other components. On the other hand, when a component is referred to as being "directly connected" or "directly accessed" to other components, it should be understood that there is no component between them. When a component is referred to as being "movably connected" to other components, it means that the positional relationship between the component and the other components is changeable, such as the relationship between a slide rail and a slider, the slider can slide on the slide rail, and the slide rail and the track are movably connected. When a component is referred to as being "fixedly connected" to other components, it means that the positional relationship between the component and the other components after being assembled together is relatively fixed.
[0189] The above is only a specific embodiment of the present invention or an explanation of a specific embodiment. The protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Although the present application is described according to a limited number of embodiments, it is understood by the technicians in the technical field that other embodiments can be envisioned within the scope of the present application described thereby, thanks to the above description. In addition, it should be noted that the language used in this specification is mainly selected for the purpose of readability and teaching, rather than for explaining or limiting the subject matter of the present application. Therefore, without departing from the scope and spirit of the attached claims, many modifications and changes are obvious to ordinary technicians in the technical field. For the scope of the present application, the disclosure made in the present application is illustrative, not restrictive, and the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method for training a language model, characterized in that: include: Acquire training sample data and a first language model; wherein the training sample data includes first training sample data and second training sample data, the first training sample data includes a first question text and a negative answer text, and the second training sample data includes the first question text and a positive answer text; The first language model is trained based on the training sample data to obtain a second language model.
2. The training method according to claim 1, characterized in that: The step of training the first language model based on the training sample data to obtain a second language model includes: Training the first language model based on the first training sample data to obtain a trained first language model; The trained first language model is trained based on the second training sample data to obtain the second language model.
3. The training method according to claim 2, characterized in that: The step of training the first language model based on the first training sample data to obtain a trained first language model comprises: Inputting the first training sample data into the first language model, the first language model processes the first training sample data and outputs a predicted probability of a first reply text, wherein the predicted probability of the first reply text includes a probability of a group of optional words corresponding to each word in the first reply text; The first language model is trained based on the first loss to reduce the similarity between the first reply text and the negative reply text.
4. The training method according to claim 2, characterized in that: The first loss is: in, is the word element vector generated by the first language model, N is the vocabulary size, y={y0,y1,…,y N }, if j is the index of each word in the negative answer text in the vocabulary, then y j =1,y k =0 (k≠j).
5. The training method according to claim 2, characterized in that: The step of training the trained first language model based on the second training sample data to obtain the second language model comprises: Inputting the second training sample data into the trained first language model, the trained first language model processes the second training sample data and outputs a predicted probability of a second reply text, wherein the predicted probability of the second reply text includes a probability of a group of optional words corresponding to each word in the second reply text; The trained first language model is trained based on the second loss to reduce the deviation between the second reply text and the positive reply text.
6. The training method according to claim 5, characterized in that: The second loss is the cross entropy loss.
7. The training method according to claim 1, characterized in that: The first language model is a pre-trained language model.
8. The training method according to claim 1, characterized in that: The step of training the first language model based on the training sample data to obtain a second language model includes: Training the first language model based on second training sample data to obtain a trained first language model; The trained first language model is trained based on the first training sample data to obtain the second language model.
9. The training method according to claim 8, characterized in that: The step of training the trained first language model based on the first training sample data to obtain the second language model comprises: Inputting the first training sample data into the trained first language model, the trained first language model processes the first training sample data and outputs a predicted probability of a third reply text, wherein the predicted probability of the third reply text includes a probability of a group of optional words corresponding to each word in the third reply text; The trained first language model is trained based on the third loss to reduce the similarity between the third reply text and the negative reply text.
10. The training method according to claim 9, characterized in that: The third loss is: in, is the word element vector generated by the first language model after training, N is the vocabulary size, y={y0,y1,...,y N }, if j is the index of each word in the negative answer text in the vocabulary, then y j =1,y k =0 (k≠j).
11. A method for generating reply information based on a language model, characterized in that: The method comprises: Get the question text; The question text is input into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to any one of the training methods according to claims 1-10.
12. A language model training device, characterized in that: include: An acquisition module, configured to acquire training sample data and a first language model, wherein the training sample data comprises first training sample data and second training sample data, the first training sample data comprises a first question text and a negative answer text, and the second training sample data comprises the first question text and a positive answer text; A training module is used to train the first language model based on the training sample data to obtain a second language model.
13. A reply information generating device based on a language model, characterized in that: Include: Question acquisition module, used to obtain question text; A text output module is used to input the question text into the language model to obtain a reply text generated by the language model, wherein the language model is trained according to the training method described in any one of claims 1-10.
14. An electronic device, characterized in that: include: at least one processor; as well as A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, and the program instructions include instructions for executing the training method according to any one of claims 1-10.
15. A readable storage medium storing program instructions, characterized in that: When the program instructions are read and executed by a computing device, the computing device is caused to execute the training method according to any one of claims 1 to 10.
Citation Information
Cited By
Method and equipment for optimizing instruction following capability of large language model and medium
CN119129754A
Question and answer model training method and device, computer equipment and storage medium
CN119513253A
