A method and apparatus for generating an answer, an electronic device, and a storage medium
Patent Information
- Application Number
- CN202510198728.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2026-08-21
AI Technical Summary
[0003]然而,由于计算资源的限制,大语言模型支持输入的信息的长度也是有限制的,拼接结果的长度可能会超过大语言模型支持输入的信息的长度,导致无法利用大语言模型给出回答
[0092]基于本申请实施例提供的回答生成方法,在获取需要生成回答的第一提示词后,可以从备选信息中确定与第一提示词相关的关联备选信息。进而,可以基于预先建立的模型参数与备选信息之间的对应关系,从关联备选信息对应的模型参数中确定出目标模型参数。可以理解的是,由于一个备选信息对应的模型参数为:利用该备选信息对初始参数的大语言模型进行训练得到的,因此,初始参数的大语言模型在结合一个备选信息对应的模型参数后,能够学习到该备选信息中的内容。即,由于初始参数的大语言模型结合目标模型参数后,能够学习到该目标模型参数对应的关联备选信息中的内容。因此,在利用初始参数的大语言模型结合目标模型参数生成回答时,生成的回答为:在大语言模型学习目标模型参数对应的备选信息的基础上推理得到的。如此,保证生成的回答的准确度。也就是说,初始参数的大语言模型结合目标模型参数后,能够学习到该目标模型参数对应的关联备选信息中的内容。因此,在生成第二提示词的过程中,可以仅将关联备选信息中除目标模型参数对应的备选信息以外其他的信息与第一提示词进行拼接,即,第二提示词中不包含该目标模型参数对应的备选信息,如此,能够在保证大语言模型生成的回答的准确度的基础上,缩短输入至大语言模型的信息的长度,在一定程度上避免出现无法利用大语言模型给出回答的情况,提高回答生成的稳定性。
Smart Images

Figure CN122616701A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus, electronic device, and storage medium for generating answers. Background Technology
[0002] In the field of artificial intelligence, large language models can perform tasks such as multi-turn dialogue, document retrieval, or modality transformation. Each time a large language model performs a question-and-answer session, to enhance the relevance between the output answer and related information, it concatenates the acquired user-input prompt with related information, and then inputs the concatenated result into the model for reasoning. The related information can include: historical dialogue information related to the prompt, and knowledge information related to the prompt from a pre-defined knowledge base.
[0003] However, due to limitations in computing resources, the length of input information that large language models can support is also limited. The length of the concatenated result may exceed the length of input information that the large language model can support, making it impossible to use the large language model to provide an answer. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for generating answers, thereby shortening the length of information input to a large language model, avoiding situations where the large language model cannot provide an answer, and improving the stability of answer generation. The specific technical solution is as follows:
[0005] A first aspect of this application provides a method for generating an answer, the method comprising:
[0006] Get the suggestion word entered by the user and use it as the first suggestion word;
[0007] Based on the similarity between the first prompt word and each alternative information, related alternative information related to the first prompt word is determined from the current alternative information; wherein, each current alternative information includes at least one of the following: historical dialogue information, and knowledge information in a preset knowledge base;
[0008] Based on the pre-established correspondence between model parameters and candidate information, target model parameters are determined from the model parameters corresponding to the associated candidate information; wherein, the model parameters corresponding to a candidate information are: model parameters of a specified network layer obtained by training a large language model with initial parameters based on the candidate information;
[0009] The information other than the candidate information corresponding to the target model parameters in the associated candidate information is concatenated with the first prompt word to obtain the second prompt word;
[0010] Using the large language model with the initial parameters and the target model parameters, the second prompt word is processed to generate an answer for the first prompt word.
[0011] In some embodiments, concatenating the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word includes:
[0012] The information other than the candidate information corresponding to the target model parameters in the associated candidate information is concatenated with the first prompt word;
[0013] Determine whether the obtained concatenation result meets the maximum input information length supported by the large language model;
[0014] If the conditions are met, the splicing result will be determined as the second prompt word;
[0015] If the conditions are not met, the splicing result is compressed to obtain the second prompt word.
[0016] In some embodiments, compressing the splicing result to obtain the second prompt word includes:
[0017] The concatenation result is encoded to obtain an encoded result whose length is no greater than the maximum input information length, which is used as the second prompt word;
[0018] or,
[0019] From the associated candidate information, the candidate information with the highest similarity to the first prompt word is selected; wherein, the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length; the selected candidate information is concatenated with the first prompt word to obtain the second prompt word.
[0020] In some embodiments, the correspondence is obtained based on the following steps:
[0021] According to the preset division dimensions, the current candidate information is divided into at least one set of candidate information;
[0022] For each set of alternative information, determine the corresponding sample prompts and sample responses;
[0023] By combining the large language model with the initial parameters and the current model parameters of the specified network layer, the sample prompt words are processed to obtain a predicted answer;
[0024] Based on the difference between the predicted answer and the sample answer, the current model parameters of the specified network layer are adjusted to obtain the model parameters corresponding to the set of candidate information.
[0025] In some embodiments, the model parameters of the specified network layer are low-rank adaptive LoRA parameters;
[0026] The process of using the large language model with the initial parameters and combining it with the current model parameters of the specified network layer to process the sample prompt words and obtain a predicted answer includes:
[0027] The model parameters of the large language model with the initial parameters are corrected using the current model parameters of the specified network layer.
[0028] The sample prompts are processed using the modified large language model to obtain the predicted answer;
[0029] The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes:
[0030] The target model parameters are used to correct the model parameters of the large language model with the initial parameters;
[0031] The modified large language model is used to process the second prompt word to obtain an answer for the first prompt word.
[0032] In some embodiments, the specified network layer is a network layer in the large language model with the initial parameters;
[0033] The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes:
[0034] Replace the model parameters of the specified network layer in the large language model with the target model parameters;
[0035] The second prompt word is processed using the replaced large language model to obtain an answer for the first prompt word.
[0036] In some embodiments,
[0037] The process of using the large language model with the initial parameters and combining it with the current model parameters of the specified network layer to process the sample prompt words and obtain a predicted answer includes:
[0038] Add the specified network layer of the current model parameters at the specified position in the large language model with the initial parameters;
[0039] The sample prompts are processed using the added large language model to obtain the predicted answer;
[0040] The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes:
[0041] Add a specified network layer with the target model parameters at a specified position in the large language model with the initial parameters;
[0042] The second prompt word is processed using the added large language model to obtain an answer for the first prompt word.
[0043] In some embodiments, determining associated candidate information related to the first prompt word from the current candidate information based on the similarity between the first prompt word and each candidate information includes:
[0044] Calculate the similarity between the feature vector of the first prompt word and the feature vector of each alternative information;
[0045] Candidate information with a similarity greater than a preset similarity threshold is identified as associated candidate information related to the first prompt word.
[0046] In some embodiments, determining the target model parameters from the model parameters corresponding to the associated candidate information based on the pre-established correspondence between model parameters and candidate information includes:
[0047] The candidate information with the highest similarity to the first prompt word is determined from the associated candidate information and used as the target information;
[0048] The model parameters corresponding to the target information are determined from the pre-established correspondence between model parameters and candidate information, and are used as the target model parameters.
[0049] A second aspect of this application provides a response generation apparatus, the apparatus comprising:
[0050] The prompt word acquisition module is used to acquire the prompt word input by the user and use it as the first prompt word;
[0051] The associated alternative information determination module is used to determine associated alternative information related to the first prompt word from the current alternative information based on the similarity between the first prompt word and each alternative information; wherein, each current alternative information includes at least one of the following: historical dialogue information and knowledge information in a preset knowledge base;
[0052] The model parameter determination module is used to determine the target model parameters from the model parameters corresponding to the associated candidate information based on the pre-established correspondence between model parameters and candidate information; wherein, the model parameters corresponding to a candidate information are: the model parameters of a specified network layer obtained by training a large language model with initial parameters based on the candidate information;
[0053] The splicing module is used to splice the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word;
[0054] The answer generation module is used to process the second prompt word by combining the large language model with the initial parameters and the target model parameters, and generate an answer for the first prompt word.
[0055] In some embodiments, the splicing module includes:
[0056] The concatenation submodule is used to concatenate the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word; the judgment submodule is used to determine whether the obtained concatenation result meets the maximum input information length supported by the large language model; if it meets the requirement, the first unit is triggered; the first unit is used to determine the concatenation result as the second prompt word; if it does not meet the requirement, the second unit is triggered; the second unit is used to compress the concatenation result to obtain the second prompt word.
[0057] In some embodiments, the second unit is specifically used for: encoding the concatenation result to obtain an encoded result with a length not greater than the maximum input information length, as a second prompt word; or, filtering out the candidate information with the highest similarity to the first prompt word from the associated candidate information; wherein the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length; and concatenating the selected candidate information with the first prompt word to obtain the second prompt word.
[0058] In some embodiments, the apparatus further includes: a correspondence establishment module, comprising:
[0059] The segmentation submodule is used to segment the current candidate information according to preset segmentation dimensions to obtain at least one set of candidate information;
[0060] The sample data acquisition submodule is used to determine the sample prompts and sample answers corresponding to each set of candidate information.
[0061] The prediction submodule is used to process the sample prompt words by combining the large language model with the initial parameters and the current model parameters of the specified network layer to obtain the predicted answer;
[0062] The adjustment submodule is used to adjust the current model parameters of the specified network layer based on the difference between the predicted answer and the sample answer, so as to obtain the model parameters corresponding to the set of candidate information.
[0063] In some embodiments, the model parameters of the specified network layer are low-rank adaptive LoRA parameters;
[0064] The prediction submodule is specifically used for:
[0065] The model parameters of the large language model with the initial parameters are corrected using the current model parameters of the specified network layer.
[0066] The sample prompts are processed using the modified large language model to obtain the predicted answer;
[0067] The answer generation module is specifically used for:
[0068] The target model parameters are used to correct the model parameters of the large language model with the initial parameters;
[0069] The modified large language model is used to process the second prompt word to obtain an answer for the first prompt word.
[0070] In some embodiments, the specified network layer is a network layer in the large language model with the initial parameters;
[0071] The answer generation module is specifically used for:
[0072] Replace the model parameters of the specified network layer in the large language model with the target model parameters;
[0073] The second prompt word is processed using the replaced large language model to obtain an answer for the first prompt word.
[0074] In some embodiments, the prediction submodule is specifically used for:
[0075] Add the specified network layer of the current model parameters at the specified position in the large language model with the initial parameters;
[0076] The sample prompts are processed using the added large language model to obtain the predicted answer;
[0077] The answer generation module is specifically used for:
[0078] Add a specified network layer with the target model parameters at a specified position in the large language model with the initial parameters;
[0079] The second prompt word is processed using the added large language model to obtain an answer for the first prompt word.
[0080] In some embodiments, the associated candidate information determination module includes:
[0081] Calculate the similarity between the feature vector of the first prompt word and the feature vector of each alternative information;
[0082] Candidate information with a similarity greater than a preset similarity threshold is identified as associated candidate information related to the first prompt word.
[0083] In some embodiments, the model parameter determination module includes:
[0084] The candidate information with the highest similarity to the first prompt word is determined from the associated candidate information and used as the target information;
[0085] The model parameters corresponding to the target information are determined from the pre-established correspondence between model parameters and candidate information, and are used as the target model parameters.
[0086] A third aspect of this application provides an electronic device, including:
[0087] Memory, used to store computer programs;
[0088] The processor, when executing a program stored in memory, implements any of the above-described answer generation methods.
[0089] In another aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements any of the above-described answer generation methods.
[0090] In another aspect of the embodiments of this application, a computer program product containing instructions is provided, which, when run on a computer, causes the computer to perform any of the above-described answer generation methods.
[0091] Beneficial effects of the embodiments in this application:
[0092] Based on the answer generation method provided in this application, after obtaining the first prompt word for which an answer needs to be generated, related alternative information can be determined from the alternative information. Furthermore, based on the pre-established correspondence between model parameters and alternative information, the target model parameters can be determined from the model parameters corresponding to the related alternative information. It is understood that since the model parameters corresponding to an alternative information are obtained by training the large language model of the initial parameters using that alternative information, the large language model of the initial parameters, after combining the model parameters corresponding to an alternative information, can learn the content of that alternative information. That is, since the large language model of the initial parameters, after combining the target model parameters, can learn the content of the related alternative information corresponding to the target model parameters, when generating an answer using the large language model of the initial parameters combined with the target model parameters, the generated answer is inferred based on the large language model learning the alternative information corresponding to the target model parameters. This ensures the accuracy of the generated answer. In other words, the large language model of the initial parameters, after combining the target model parameters, can learn the content of the related alternative information corresponding to the target model parameters. Therefore, in the process of generating the second prompt word, only the information other than the candidate information corresponding to the target model parameter in the associated candidate information can be concatenated with the first prompt word. That is, the second prompt word does not contain the candidate information corresponding to the target model parameter. In this way, while ensuring the accuracy of the answer generated by the large language model, the length of the information input to the large language model can be shortened, which can avoid the situation where the large language model cannot provide an answer to a certain extent and improve the stability of answer generation.
[0093] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0094] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0095] Figure 1 A first flowchart of the answer generation method provided in the embodiments of this application;
[0096] Figure 2 A second flowchart of the answer generation method provided in the embodiments of this application;
[0097] Figure 3 A first flowchart for establishing a correspondence provided in an embodiment of this application;
[0098] Figure 4 A third flowchart of the answer generation method provided in the embodiments of this application;
[0099] Figure 5 A flowchart illustrating the process of establishing a correspondence between model parameters and alternative information, provided for an embodiment of this application;
[0100] Figure 6 A schematic diagram of a process for generating an answer is provided in an embodiment of this application;
[0101] Figure 7 A structural diagram of an answer generation device provided in an embodiment of this application;
[0102] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0103] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0104] In the field of artificial intelligence, large language models can perform tasks such as multi-turn dialogue, document retrieval, or modality switching. Each time a large language model performs a question-and-answer session, to enhance the relevance between the output answer and related information, it concatenates the user-input prompts with related information and inputs the concatenated result into the model for reasoning. The related information can include: historical dialogue information related to the prompts, and knowledge information related to the prompts from a pre-defined knowledge base.
[0105] However, due to limitations in computing resources, the length of input information that large language models can support is also limited. The length of the concatenated result may exceed the length of input information that the large language model can support, making it impossible to use the large language model to provide an answer.
[0106] This application provides an answer generation method that can be applied to electronic devices with data processing capabilities, such as servers and computers. See also... Figure 1 , Figure 1 A first flowchart of an answer generation method provided in an embodiment of this application, the method comprising the following steps:
[0107] S101: Obtain the prompt word input by the user and use it as the first prompt word.
[0108] S102: Based on the similarity between the first prompt word and each alternative information, determine the associated alternative information related to the first prompt word from the current alternative information.
[0109] The current alternative information includes at least one of the following: historical dialogue information, and knowledge information from a preset knowledge base.
[0110] S103: Based on the pre-established correspondence between model parameters and candidate information, determine the target model parameters from the model parameters corresponding to the associated candidate information.
[0111] Among them, the model parameters corresponding to one of the alternative information are: the model parameters of the specified network layer obtained by training the large language model with initial parameters based on the alternative information.
[0112] S104: Concatenate the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word.
[0113] S105: Using the large language model with initial parameters combined with the target model parameters, process the second prompt word to generate an answer for the first prompt word.
[0114] Based on the above processing, after obtaining the first prompt word for which an answer needs to be generated, related alternative information can be determined from the candidate information. Furthermore, based on the pre-established correspondence between model parameters and candidate information, the target model parameters can be determined from the model parameters corresponding to the related alternative information. It can be understood that since the model parameters corresponding to a candidate piece of information are obtained by training the initial parameter large language model using that candidate information, the initial parameter large language model, after combining the model parameters corresponding to a candidate piece of information, can learn the content of that candidate information. That is, since the initial parameter large language model, after combining the target model parameters, can learn the content of the related alternative information corresponding to that target model parameter, when generating an answer using the initial parameter large language model combined with the target model parameters, the generated answer is inferred based on the large language model learning the alternative information corresponding to the target model parameters. This ensures the accuracy of the generated answer. In other words, the initial parameter large language model, after combining the target model parameters, can learn the content of the related alternative information corresponding to that target model parameter. Therefore, in the process of generating the second prompt word, only the information other than the candidate information corresponding to the target model parameter in the associated candidate information can be concatenated with the first prompt word. That is, the second prompt word does not contain the candidate information corresponding to the target model parameter. In this way, while ensuring the accuracy of the answer generated by the large language model, the length of the information input to the large language model can be shortened, which can avoid the situation where the large language model cannot provide an answer to a certain extent and improve the stability of answer generation.
[0115] In step S101, the electronic device can acquire the prompt word input by the user as the first prompt word. For ease of subsequent description, the user who inputs the first prompt word can be referred to as the first user.
[0116] For each user who needs to interact with the large language model, the user can input a prompt word that the large language model wants to respond to through their logged-in client. That is, the prompt word can be an instruction uploaded by the user to their logged-in client, in which they hope the large language model will generate a response. For example, the client can be a smart terminal such as a smartphone or computer. Correspondingly, the electronic device can communicate with the client, obtain the prompt word input by the user (i.e., the first prompt word), and after receiving a response to the first prompt word, send a response to the user for that first prompt word.
[0117] The prompt is an injected instruction used to input into the Large Language Model (LLM). The prompt is not limited to text; it can also be audio, video, etc.
[0118] The first prompt can be in text form; that is, the electronic device can acquire the text entered by the user through the client and use it as the first prompt. The statement to be processed can also be in audio form; that is, the electronic device can acquire the audio uploaded by the user through the client and use it as the first prompt. Furthermore, the electronic device can use an audio-to-text algorithm to convert it into text for subsequent processing.
[0119] Large language models can learn the grammatical and semantic rules of natural language, and can perform corresponding text generation functions based on input prompts. For example, large language models can be ChatGPT (Chat Generative Pre-trained Transformer) and QWEN (Generalized Meaning) models.
[0120] For step S102, the current alternative information includes at least one of the following: historical dialogue information and knowledge information in a preset knowledge base.
[0121] Historical dialogue information includes: prompts input by any user in the past, and responses generated by the large language model in response to those prompts in the past. In other words, for each prompt input by a user, the electronic device can store both the prompt and the response as a historical dialogue entry. It is understandable that as the number of dialogue rounds between the user and the large language model increases, the historical dialogue information stored in the electronic device also increases; that is, the historical dialogue information included in the alternative information is dynamically changing.
[0122] In one implementation, the current alternative information includes at least one of the following: the user's historical dialogue information, and knowledge information in a preset knowledge base.
[0123] In this embodiment, when recording historical dialogue information, the electronic device can also record the correspondence between the historical dialogue information and users. Furthermore, for each user, the electronic device determines the user's historical dialogue information based on the correspondence between the historical dialogue information and the user.
[0124] Accordingly, for the first user who inputs the first prompt word, the electronic device can use the first user's historical dialogue information and knowledge information in the preset knowledge base as the current alternative information.
[0125] It is understandable that, since the topics involved in multiple rounds of dialogue between the same user and the large language model are usually quite similar, in the process of generating an answer for the first prompt word input by the first user, prioritizing the retrieval of related alternative information in the user's historical dialogue information can improve retrieval efficiency and reduce the amount of computation required to determine related alternative information.
[0126] The preset knowledge base can be a public knowledge base, or it can be a private knowledge base pre-built by technical personnel. For example, the knowledge information in a public knowledge base can be publicly available information on the Internet (such as academic papers, news articles, etc.). Understandably, technical personnel can maintain and update the preset knowledge base according to actual needs; for example, they can maintain and update the preset knowledge base after reaching a fixed update cycle (such as daily, monthly, etc.). In other words, the knowledge information in the preset knowledge base included in the alternative information is also dynamically changing.
[0127] Since users' historical dialogue information may contain dialogue information with semantically similar meanings to the first prompt word, the historical dialogue information related to the first prompt word can be identified and used as reference content for the large language model. This can ensure the consistency of the dialogue and improve the quality of the responses generated by the large language model to the first prompt word.
[0128] Similarly, since the knowledge information in the preset knowledge base may contain knowledge information with similar semantics to the first prompt word, the quality of the large language model's generated answers to the first prompt word can be improved by identifying the knowledge information related to the first prompt word and using it as a reference for the large language model.
[0129] In other words, after receiving the first prompt word, the electronic device can determine the associated alternative information related to the first prompt word from the current alternative information based on the similarity between the first prompt word and each alternative information.
[0130] In some embodiments, see Figure 2 , Figure 2 This is a second flowchart of the answer generation method provided in the embodiments of this application.
[0131] exist Figure 1 Based on this, step S102 includes:
[0132] S1021: Calculate the similarity between the feature vector of the first prompt word and the feature vector of each alternative information.
[0133] S1022: Select candidate information with a similarity greater than a preset similarity threshold as related candidate information associated with the first prompt word.
[0134] In this embodiment, after receiving the first prompt word, the electronic device can acquire the feature vectors of each pre-recorded alternative information. That is, the electronic device can pre-encode each recorded alternative information to obtain its feature vector. For example, the electronic device can encode each new alternative information when recording it, obtaining and recording its feature vector.
[0135] For each candidate piece of information, the electronic device can use a pre-trained encoding model to encode the candidate information, obtaining the encoded result (i.e., feature vector). For example, the pre-trained encoding model can be BERT (Bidirectional Encoder Representations from Transformers).
[0136] Accordingly, after receiving the first prompt word, the electronic device can encode the first prompt word to obtain its feature vector.
[0137] Furthermore, based on a preset similarity algorithm, the similarity between the feature vector of the first prompt word and the feature vector of each candidate information can be calculated. For example, the preset similarity algorithm can be cosine similarity, Euclidean distance, etc.
[0138] If the similarity between the feature vector of the first prompt word and the feature vector of a candidate information is greater than a preset similarity threshold, it indicates that the semantics represented by the first prompt word are relatively close to the semantics represented by the candidate information. Accordingly, the candidate information is suitable for inputting together with the first prompt word into the large language model for subsequent reasoning; that is, the electronic device can determine the candidate information as related candidate information associated with the first prompt word.
[0139] Based on the above processing, the electronic device can quantify the correlation between the first prompt word and each piece of alternative information based on the similarity between the feature vector of the first prompt word and the feature vectors of the alternative information. This allows it to determine the associated alternative information related to the first prompt word from among the current alternative information. Subsequently, the large language model can perform inference based on the first prompt word and its associated alternative information, thereby improving the relevance of the generated answer to the first prompt word to the first prompt word itself.
[0140] Regarding step S103, the electronic device stores a pre-established correspondence between model parameters and candidate information. Accordingly, after determining the associated candidate information related to the first prompt word, the electronic device can determine the target model parameters from the model parameters corresponding to the associated candidate information based on this correspondence.
[0141] Among them, the model parameters corresponding to one of the alternative information are: the model parameters of the specified network layer obtained by training the large language model with initial parameters based on the alternative information.
[0142] In some embodiments, see Figure 3 , Figure 3 This is a first flowchart illustrating the establishment of a correspondence in an embodiment of this application. The correspondence is obtained based on the following steps:
[0143] S301: According to the preset division dimensions, divide the current candidate information into at least one set of candidate information.
[0144] S302: For each set of alternative information, determine the sample prompts and sample answers corresponding to that set of alternative information.
[0145] S303: Using a large language model with initial parameters combined with the current model parameters of a specified network layer, the sample prompt words are processed to obtain a predicted answer.
[0146] S304: Adjust the current model parameters of the specified network layer based on the difference between the predicted answer and the sample answer to obtain the model parameters corresponding to the set of alternative information.
[0147] In the embodiments of this application, the process of obtaining model parameters corresponding to a set of candidate information according to the above steps S301 to S304 can be called the training process.
[0148] For step S301, the preset division dimensions may include at least one of the following: division according to the time range to which the information belongs, or division according to the domain category to which the information belongs.
[0149] For example, in the process of dividing information according to the time range to which it belongs, electronic devices can use days (or weeks) as a cycle to determine the user's historical dialogue information belonging to a cycle as a set of candidate information.
[0150] For example, in the process of classifying information according to its domain category, the electronic device can determine the domain to which each piece of knowledge information in the preset knowledge base belongs. Furthermore, knowledge information belonging to the same domain category can be identified as a group of candidate information. For instance, the domains to which knowledge information belongs can be divided into: natural sciences, social sciences, and humanities and arts, etc. This application does not specifically limit the scope and number of domains to which knowledge information belongs; those skilled in the art can classify the domains to which each piece of knowledge information in the preset knowledge base belongs according to actual needs.
[0151] Accordingly, the electronic device can divide the current candidate information according to the above-mentioned division dimensions to obtain at least one set of candidate information.
[0152] In one implementation, the difference between the candidate information in a set of candidate information obtained by partitioning along a partitioning dimension is less than the difference threshold corresponding to that partitioning dimension.
[0153] For example, in a division dimension based on the time range to which the information belongs, the difference between the earliest and latest times of each candidate information in a set of candidate information is less than a preset time difference threshold.
[0154] For example, in a segmentation dimension based on the domain category to which the information belongs, the distance between any two feature vectors in a set of candidate information is less than a preset distance difference threshold. The fact that the distance between the feature vectors of two candidate information items is less than the preset distance difference threshold indicates that the semantics represented by the two candidate information items are relatively similar, and correspondingly, they can be considered to belong to the same domain category.
[0155] For step S302, for each set of candidate information, the electronic device can split each candidate information in the set of candidate information to determine at least one sample prompt word corresponding to the set of candidate information and the sample answer corresponding to each sample prompt word.
[0156] In one implementation, for each candidate information, when the candidate information is a historical dialogue information, the electronic device can use the prompt word in the historical dialogue information as a sample prompt word and the answer in the historical dialogue information as the sample answer corresponding to the sample prompt word.
[0157] In another implementation, for each candidate piece of information, when the candidate piece of information is a piece of knowledge information in a preset knowledge base, the electronic device can use a part of the knowledge information as a sample prompt word and another part of the knowledge information as the sample answer corresponding to the sample prompt word.
[0158] For example, an electronic device can divide a piece of knowledge information into a first half and a second half according to the number of words. Accordingly, the electronic device can use the first half of the knowledge information as a sample prompt word and the second half of the knowledge information as the sample answer corresponding to the sample prompt word.
[0159] In this application, there is no specific limitation on how a set of alternative information is split. Technical personnel can split each set of alternative information according to actual needs.
[0160] For steps S303 to S304, the electronic device can adjust the model parameters of a specified network layer based on the parameter-efficient fine-tuning (PEFT) method to obtain model parameters corresponding to a set of alternative information.
[0161] The process by which the electronic device can process sample prompts using a large language model with initial parameters combined with the current model parameters of a specified network layer to obtain a predicted answer will be described in subsequent embodiments.
[0162] After receiving the responses (i.e., predicted responses) to sample prompts for the set of candidate information, the electronic device can calculate a loss value based on the difference between the predicted response and the sample responses for the set of candidate information. Based on the calculated loss value, the current model parameters of the specified network layer are adjusted to obtain the model parameters corresponding to the set of candidate information.
[0163] For example, the electronic device can calculate the distance between the feature vector of the predicted answer and the feature vector of the sample answer, using it as the loss value. Then, based on the calculated loss value, the electronic device can perform gradient adjustments on the current model parameters of a specified network layer to obtain the model parameters corresponding to the set of candidate information.
[0164] Accordingly, the electronic device can obtain the model parameters corresponding to each set of candidate information based on the above training process. It can be understood that, for each piece of candidate information contained in a set, the electronic device can record the correspondence between that candidate information and the model parameters corresponding to that set of candidate information. In this way, the electronic device can establish a correspondence between model parameters and candidate information.
[0165] For example, the pre-established correspondence records: candidate information 1 corresponds to model parameter 1 and model parameter 2; candidate information 2 corresponds to model parameter 3; candidate information 3 corresponds to model parameter 1 and model parameter 3; candidate information 4 corresponds to model parameter 4; ...
[0166] Based on the above processing, the electronic device can group the candidate information, identifying multiple candidate information pieces with similar representations as a group. Then, for each group of candidate information, the current model parameters of a specified network layer are adjusted using a large language model with initial parameters to obtain the model parameters corresponding to that group of candidate information. Thus, the model parameters corresponding to that group of candidate information represent the content within that group. Subsequently, by combining the large language model with the model parameters corresponding to that group of candidate information, the large language model can learn the content of each candidate information piece within that group. When generating an answer using the large language model with initial parameters and the target model parameters, the generated answer is inferred based on the candidate information corresponding to the target model parameters learned by the large language model. This ensures the accuracy of the generated answer.
[0167] In one implementation, the electronic device can periodically trigger the above training process according to a preset update strategy to update the recorded correspondence.
[0168] In other words, electronic devices can periodically group candidate information according to a preset cycle (e.g., days) and obtain the model parameters corresponding to each group of candidate information.
[0169] Thus, with the alternative information dynamically updated, the electronic device can also dynamically update the correspondence between the recorded model parameters and the alternative information. Subsequently, when determining the target model parameters based on the recorded correspondence, the electronic device can determine the model parameters corresponding to the alternative information with the highest similarity to the first prompt word, ensuring the relevance between the determined target model parameters and the first prompt word.
[0170] It is understandable that there may be multiple alternative information related to the first prompt word, and there may also be multiple model parameters corresponding to these multiple alternative information in the pre-established correspondence.
[0171] Continuing with the previous example, if the related alternative information for the first prompt word includes: alternative information 1, alternative information 2, and alternative information 4, then according to the pre-established correspondence, the model parameters corresponding to these multiple related alternative information include: model parameter 1, model parameter 2, model parameter 3, and model parameter 4.
[0172] In one implementation, the electronic device can randomly select one of the multiple model parameters corresponding to the multiple associated alternative information as the target model parameter.
[0173] In some embodiments, see Figure 4 , Figure 4 This is a third flowchart of the answer generation method provided in the embodiments of this application.
[0174] exist Figure 1Based on this, step S103 includes:
[0175] S1031: Determine the candidate information with the highest similarity to the first prompt word from the associated candidate information, and use it as the target information.
[0176] S1032: Determine the model parameters corresponding to the target information from the pre-established correspondence between model parameters and candidate information, and use them as target model parameters.
[0177] In this embodiment, the electronic device can calculate the similarity between the first prompt word and each associated candidate information. The candidate information with the highest similarity to the first prompt word is selected as the target information. The specific process of calculating the similarity between the first prompt word and each associated candidate information can refer to the process described above for obtaining the similarity between the first prompt word and each candidate information, and will not be repeated here.
[0178] Furthermore, the electronic device can determine the model parameters corresponding to the target information from the pre-established correspondence between model parameters and candidate information, and use them as the target model parameters.
[0179] Continuing the example above, the related alternative information for the first prompt word includes: alternative information 1, alternative information 2, and alternative information 4. The model parameters corresponding to these multiple alternative information include: model parameter 1, model parameter 2, model parameter 3, and model parameter 4. If the first prompt word has the highest similarity to alternative information 2 among the alternative information, then the model parameter (i.e., model parameter 3) corresponding to alternative information 2 (i.e., the target information) can be used as the target model parameter.
[0180] Based on the above processing, when there are multiple related alternative information items and multiple model parameters corresponding to these alternative information items, the electronic device can determine the alternative information item with the highest similarity to a first prompt word as the target information. In other words, the target information is the information among the alternative information items whose semantics are closest to the first prompt word. Therefore, determining the model parameters corresponding to the target information as the target model parameters ensures that the content represented by the obtained target model parameters matches the first prompt word. Subsequently, after combining the model parameters corresponding to this set of alternative information items with the initial parameter large language model, the large language model can learn the content of each alternative information item in this set. When generating an answer using the initial parameter large language model combined with the target model parameters, the generated answer is inferred based on the alternative information corresponding to the target model parameters learned by the large language model. This ensures the accuracy of the generated answer.
[0181] For steps S104 to S105, after determining the target model parameters, the electronic device can concatenate the other information in the associated alternative information (excluding the alternative information corresponding to the target model parameters) with the first prompt word to obtain the second prompt word.
[0182] Continuing with the previous example, the associated alternative information for the first prompt word includes: alternative information 1, alternative information 2, and alternative information 4, and the target model parameter is the model parameter corresponding to alternative information 2 (i.e., model parameter 3). Therefore, the electronic device can concatenate alternative information 1 and alternative information 4 with the first prompt word to obtain the second prompt word.
[0183] Understandably, if the candidate information corresponding to the target model parameters corresponds one-to-one with the associated candidate information of the first prompt word—that is, if there is no other information in the associated candidate information besides the candidate information corresponding to the target model parameters—then the electronic device can directly determine the first prompt word as the second prompt word.
[0184] Correspondingly, electronic devices can use a large language model with initial parameters combined with target model parameters to process the second prompt word and generate an answer for the first prompt word.
[0185] In some embodiments, the model parameters of the network layer are specified as Low-Rank Adaptation (LoRA) parameters.
[0186] Step S105 includes:
[0187] Step S1051: Use the target model parameters to correct the model parameters of the large language model with initial parameters.
[0188] Step S1052: Process the second prompt word using the modified large language model to obtain the answer to the first prompt word.
[0189] Accordingly, step S303 above includes:
[0190] Step S3031: Use the current model parameters of the specified network layer to correct the model parameters of the large language model with initial parameters.
[0191] Step S3032: Process the sample prompts using the modified large language model to obtain the predicted answer.
[0192] In this embodiment, the low-rank adaptation (LoRA) parameter is the product of the first low-rank matrix and the second low-rank matrix.
[0193] The first low-rank matrix has the same number of rows as the parameter matrix corresponding to the large language model, and the same number of columns as the rank of the parameter matrix corresponding to the large language model. The second low-rank matrix has the same number of rows as the rank of the parameter matrix corresponding to the large language model, and the same number of columns as the parameter matrix corresponding to the large language model. The process of obtaining the first and second low-rank matrices will be explained in subsequent embodiments. The parameter matrix corresponding to the large language model represents the model parameters of the large language model with the initial parameters.
[0194] Correspondingly, electronic devices can use the target model parameters (i.e., the product of the first low-rank matrix and the second low-rank matrix) to correct the model parameters of the large language model with initial parameters.
[0195] For a large language model with initial parameters, the parameter matrix corresponding to the large language model can be represented as: W m×n This can be denoted as W. The first low-rank matrix in the target model parameters can be represented as: A m×r The first low-rank matrix can be denoted as A; the second low-rank matrix can be represented as B. r×n Let be denoted as B. Here, m represents the number of rows in the parameter matrix corresponding to the large language model, n represents the number of columns in the parameter matrix corresponding to the large language model, and r represents the rank of the parameter matrix corresponding to the large language model.
[0196] Correspondingly, the parameter matrix of the corrected large language model can be represented as: W ′ =W+AB. Furthermore, the electronic device can input the second prompt word into the modified large language model, which can then infer and generate an answer based on the first prompt word.
[0197] During the training process described above, the electronic device can obtain an initial first low-rank matrix based on a random initialization algorithm, and set the initialized second low-rank matrix to zero, so as to maintain the initial parameters of the large language model (i.e., the initial offset is 0) at the beginning of training. For example, the random initialization algorithm can be a Gaussian initialization algorithm or a uniform initialization algorithm. Accordingly, the initialized A×B is a zero matrix.
[0198] Correspondingly, the electronic device can use the current model parameters of a specified network layer to correct the model parameters of the large language model with initial parameters. Then, the electronic device can input sample prompts into the corrected large language model, which can then infer and generate an answer (i.e., a predicted answer) based on the sample prompts.
[0199] Understandably, regarding step S304 above, after obtaining the predicted answer, the electronic device can calculate the loss value based on the difference between the predicted answer and the sample answers of the set of candidate information. Then, based on the calculated loss value, it can perform gradient adjustments on the current model parameters (i.e., the current first low-rank matrix and second low-rank matrix) of the specified network layer.
[0200] Based on the above processing, compared to directly adjusting the model parameters of each network layer in the large language model, the answer generation method provided in this application can adjust the added LoRA parameters. Furthermore, since the number of LoRA parameters is much smaller than the number of parameters in the large language model, adjusting only the LoRA parameters while keeping the large language model's own model parameters unchanged allows the large language model (i.e., the modified large language model) to learn the candidate information corresponding to the LoRA parameters based on the initial parameters. Subsequently, in the process of generating answers using the large language model with the initial parameters combined with the target model parameters, it can be ensured that the generated answer is inferred based on the candidate information corresponding to the target model parameters learned by the large language model. This ensures the accuracy of the generated answer.
[0201] In some embodiments, the network layer is specified as the network layer in a large language model with initial parameters.
[0202] Step S105 includes:
[0203] Step S105a: Replace the model parameters of the specified network layer in the large language model of the initial parameters with the target model parameters.
[0204] Step S105b: Process the second prompt word using the replaced large language model to obtain the answer to the first prompt word.
[0205] In this embodiment, the target model parameters refer to the model parameters of a specified network layer in a large language model. That is, the network layer in a large language model with specified network layers as initial parameters.
[0206] For example, if the large language model is implemented based on the Transformer network architecture, then the specified network layer can be the network layer corresponding to the Head in the Transformer network architecture. The specific process for obtaining the target model parameters will be described in subsequent embodiments.
[0207] Accordingly, the electronic device can replace the model parameters of a specified network layer in the initial large language model with the target model parameters. That is, the model parameters of all network layers except the specified network layer remain unchanged in the replaced large language model. Then, the electronic device can input the second prompt word into the replaced large language model, which can then infer and generate an answer based on the first prompt word.
[0208] During the training process described above, while the electronic device adjusts the current model parameters of the specified network layer based on the difference between the predicted answer and the sample answer, the model parameters of other network layers in the large language model remain unchanged.
[0209] Correspondingly, electronic devices can input sample prompts into the current large language model, which can then infer and generate an answer (i.e., a predicted answer) based on the sample prompts.
[0210] Understandably, regarding step S304 above, after obtaining the predicted answer, the electronic device can calculate the loss value based on the difference between the predicted answer and the sample answers of the set of candidate information. Then, based on the calculated loss value, it can perform gradient adjustments on the current model parameters of the specified network layer in the large language model.
[0211] After training, the electronic device can determine the model parameters of a specified network layer in the large language model as the model parameters corresponding to the candidate information group.
[0212] Based on the above processing, compared to directly adjusting the model parameters of each network layer in a large language model, the answer generation method provided in this application can adjust the model parameters of a subset of network layers in the large language model. That is, the number of parameters that need to be adjusted is much smaller than the total number of parameters in the large language model. Therefore, the large language model (i.e., the replaced large language model) that combines the adjusted model parameters of a specified network layer with the initial parameters can learn the content of the alternative information corresponding to the model parameters of that specified network layer. Subsequently, in the process of generating an answer using the large language model with the initial parameters and the target model parameters, it can be ensured that the generated answer is inferred based on the alternative information corresponding to the target model parameters learned by the large language model. This ensures the accuracy of the generated answer.
[0213] In some embodiments, step S105 includes:
[0214] Step 1: Add a specified network layer with the target model parameters at a specified location in the large language model with initial parameters.
[0215] Step 2: Use the added large language model to process the second prompt word to obtain the answer to the first prompt word.
[0216] Accordingly, step S303 above includes:
[0217] Step 1: Add the specified network layer with the current model parameters at the specified position in the large language model with the initial parameters.
[0218] Step 2: Use the added large language model to process the sample prompts to obtain the predicted answer.
[0219] In this embodiment of the application, the target model parameter refers to the model parameter of the specified network layer that needs to be added at a specified position in the large language model.
[0220] The specific type of network layer is not limited here. For example, a network layer may contain: a downsampling layer, an activation function layer, and an upsampling layer.
[0221] The specified position within the large language model is not limited here. For example, if the large language model is implemented based on a Transformer network architecture, the specified position could be after the fully connected layer in the large language model. The specific process for obtaining the target model parameters will be described in subsequent embodiments.
[0222] Accordingly, the electronic device can add a specified network layer with the target model parameters at a specified location in the large language model with initial parameters. After the addition, the model parameters of all network layers in the large language model remain unchanged, except for the specified network layer.
[0223] Furthermore, the electronic device can input the second prompt word into the added large language model, which can then infer and generate an answer based on the first prompt word.
[0224] During the training process described above, the electronic device can set the initial model parameters of a specified network layer to zero, or determine the initial values of the model parameters of a specified network layer through random initialization.
[0225] Accordingly, the electronic device can use the initial values of the model parameters of a specified network layer to add a specified network layer at a specified location in a large language model with initial parameters. Then, the electronic device can input sample prompts into the added large language model, which can then infer and generate an answer (i.e., a predicted answer) based on the sample prompts.
[0226] Understandably, regarding step S304 above, after obtaining the predicted answer, the electronic device can calculate the loss value based on the difference between the predicted answer and the sample answers of the set of candidate information. Then, based on the calculated loss value, it can perform gradient adjustments on the current model parameters of the specified network layer in the large language model.
[0227] Based on the above processing, compared to directly adjusting the model parameters of each network layer in the large language model, the answer generation method provided in this application adds an additional network layer (a specified network layer) to the large language model and adjusts only the model parameters of the specified network layer. That is, the number of parameters that need to be adjusted is much smaller than the total number of parameters in the large language model. Therefore, the large language model (i.e., the large language model after adding the specified network layer) can learn the candidate information corresponding to the model parameters of that specified network layer, based on the initial parameters and the adjusted model parameters of the specified network layer. Subsequently, in the process of generating an answer using the large language model with the initial parameters and the target model parameters, it can be ensured that the generated answer is inferred based on the candidate information corresponding to the target model parameters learned by the large language model. This ensures the accuracy of the generated answer.
[0228] In some embodiments, step S104 includes:
[0229] Step S1041: Combine the information in the associated candidate information other than the candidate information corresponding to the target model parameters with the first prompt word.
[0230] Step S1042: Determine whether the obtained concatenation result meets the maximum input information length supported by the large language model.
[0231] If satisfied, proceed to step S1043; if not satisfied, proceed to step S1044.
[0232] Step S1043: Determine the splicing result as the second prompt word.
[0233] Step S1044: Compress the splicing result to obtain the second prompt word.
[0234] In this embodiment of the application, after the electronic device concatenates the information other than the candidate information corresponding to the target model parameter in the associated candidate information with the first prompt word, it can further determine whether the obtained concatenation result (which can be called the initial concatenation result) meets the maximum input information length supported by the large language model.
[0235] The maximum input length supported by the large language model refers to the length of the feature vector that the large language model can process. For example, the maximum input length can be 1K (kilobytes) or 1M (megabytes).
[0236] In other words, electronic devices can determine whether the length of the feature vector corresponding to the initial splicing result exceeds the maximum input information length.
[0237] For example, an electronic device can determine the feature vectors corresponding to each word in the initial splicing result using a pre-set vocabulary. Then, based on these feature vectors, the electronic device can obtain the feature vector corresponding to the initial splicing result. The vocabulary stores the words and their corresponding feature vectors.
[0238] If the initial concatenation result meets the maximum input information length supported by the large language model, it means that the length of the feature vector corresponding to the initial concatenation result does not exceed the maximum input information length. In this case, the large language model can process the second prompt word. That is, the large language model can process the feature vector corresponding to the second prompt word. Therefore, the electronic device can determine the initial concatenation result as the second prompt word.
[0239] If the initial concatenation result does not meet the maximum input information length supported by the large language model, it means that the length of the feature vector corresponding to the initial concatenation result exceeds the maximum input information length. In this case, the large language model cannot process the second prompt word; that is, it cannot process the feature vector corresponding to the second prompt word. Accordingly, the electronic device can compress the initial concatenation result to obtain the second prompt word.
[0240] In some embodiments, step S1044 includes:
[0241] The concatenated result is encoded to obtain an encoded result whose length is no greater than the maximum input information length, which is then used as the second prompt word.
[0242] In this embodiment, the electronic device can use a pre-trained encoding model to encode the splicing result (i.e., the initial splicing result) to a fixed length, so that the length of the encoded result of the initial splicing result is not greater than the maximum input information length. For example, the pre-trained encoding model can be BERT (Bidirectional Encoder Representations from Transformers).
[0243] Accordingly, the electronic device can use the encoded result of the initial splicing result as the second prompt word. That is to say, in this application, the representation of the prompt word input to the large language model is not limited to text, but can also be the encoded result of text (i.e., feature vector).
[0244] Based on the above processing, since the prompt words of the large language model can be represented as feature vectors, if the initial concatenation result does not meet the maximum input information length supported by the large language model, the electronic device can encode the initial concatenation result to obtain an encoded result with a length no greater than the maximum input information length. This can, to a certain extent, ensure the stability of the responses generated by the large language model.
[0245] Alternatively, in some embodiments, step S1044 includes:
[0246] From the associated candidate information, select the candidate information with the highest similarity to the first prompt word. Concatenate the selected candidate information with the first prompt word to obtain the second prompt word.
[0247] Among them, the concatenation result of the selected candidate information and the first prompt word meets the maximum input information length.
[0248] In this embodiment, the electronic device can determine the similarity between the first prompt word and each associated candidate information, thus determining the magnitude relationship between the similarity scores of each associated candidate information. Furthermore, the electronic device can determine the length of the feature vector corresponding to each associated candidate information.
[0249] For example, an electronic device can use a pre-defined vocabulary to determine the feature vectors corresponding to each word in a set of related candidate information. Then, based on the feature vectors corresponding to each word in the related candidate information, the electronic device can obtain the feature vector corresponding to the related candidate information. The vocabulary stores words and their corresponding feature vectors.
[0250] Accordingly, the electronic device can filter out the most similar candidate information in descending order of similarity. The sum of the lengths of the feature vectors corresponding to these candidate information and the feature vector corresponding to the first prompt word should be as close as possible to, but not exceed, the maximum input information length. That is, the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length.
[0251] Based on the above processing, if the initial concatenation result does not meet the maximum input information length supported by the large language model, the electronic device can further filter the associated candidate information and select the candidate information with the highest similarity to the first prompt word for concatenation. In this way, while maximizing the amount of associated candidate information to be concatenated, the length of the prompt word input to the large language model can be further reduced, thus ensuring the stability of the response generated by the large language model to a certain extent.
[0252] See Figure 5 , Figure 5This is a schematic diagram illustrating a process for establishing the correspondence between model parameters and alternative information, provided as an embodiment of this application. Figure 5 In this application, the sample dataset generation method involves the electronic device acquiring at least one of historical dialogue information and knowledge information from a pre-defined knowledge base (i.e., historical dialogue information / knowledge information from the pre-defined knowledge base) to generate a sample dataset. A sample data point within the sample dataset represents a sample prompt word and sample answer corresponding to a set of candidate information. The model parameter training method involves the electronic device using the sample data in the sample dataset to train the model parameters of a specified network layer on a large language model with initial parameters. The association between model parameters and information is then established: for each set of candidate information, the electronic device determines the correspondence between each candidate piece of information in that set and the corresponding model parameters. Finally, an index is created: the electronic device records the correspondence between model parameters and candidate information. This correspondence can be updated periodically.
[0253] See Figure 6 , Figure 6 This is a schematic diagram of a process for generating an answer, provided as an embodiment of this application. Figure 6 In this context, electronic devices can obtain the prompt word entered by the user, that is, the first prompt word.
[0254] The similarity index means that the electronic device can determine the associated alternative information related to the first prompt word from the current alternative information based on the similarity between the first prompt word and each alternative information. The current alternative information includes at least one of the following: historical dialogue information and knowledge information in a preset knowledge base (i.e., historical dialogue information / knowledge information in a preset knowledge base).
[0255] The target model parameter retrieval method involves the electronic device identifying the candidate information with the highest similarity to the first prompt word from the associated alternative information, and using this as the target information. Then, from the pre-established correspondence between model parameters and candidate information (i.e., the index), the model parameters corresponding to the target information are determined and used as the target model parameters.
[0256] Information representation corresponding to the target model parameters is removed: Electronic devices can concatenate other information in the associated candidate information, except for the candidate information corresponding to the target model parameters, with the first prompt word to obtain the concatenation result.
[0257] The optional prompt word compression means that if the obtained concatenation result does not meet the maximum input information length supported by the large language model, the electronic device can compress the concatenation result to obtain a second prompt word.
[0258] If the obtained concatenation result meets the maximum input information length supported by the large language model, the electronic device can use the concatenation result as a second prompt word.
[0259] Loading target model parameters means that the electronic device can obtain the determined target model parameters from the recorded model parameters and use the target model parameters to adjust the large language model with initial parameters.
[0260] Model inference representation: Using a large language model with initial parameters combined with the target model parameters, the second prompt word is processed to generate an answer for the first prompt word.
[0261] Saving dialogue means that electronic devices can record the first prompt word and the generated response to the first prompt word as a historical dialogue message.
[0262] The dashed lines for "historical dialogue information and knowledge information in the preset knowledge base" and "saved dialogue" indicate that the electronic device can add the current dialogue (i.e., the first prompt and the generated response to the first prompt) to the recorded historical dialogue information.
[0263] Based on the same inventive concept, embodiments of this application provide an answer generation apparatus. See also Figure 7 , Figure 7 This application provides a structural diagram of an answer generation device, the device comprising:
[0264] The prompt word acquisition module 701 is used to acquire the prompt word input by the user and use it as the first prompt word;
[0265] The associated alternative information determination module 702 is used to determine associated alternative information related to the first prompt word from the current alternative information based on the similarity between the first prompt word and each alternative information; wherein, each current alternative information includes at least one of the following: historical dialogue information, and knowledge information in a preset knowledge base;
[0266] The model parameter determination module 703 is used to determine the target model parameters from the model parameters corresponding to the associated candidate information based on the pre-established correspondence between model parameters and candidate information; wherein, the model parameters corresponding to a candidate information are: the model parameters of a specified network layer obtained by training a large language model with initial parameters based on the candidate information.
[0267] The splicing module 704 is used to splice the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word;
[0268] The answer generation module 705 is used to process the second prompt word by combining the large language model with the initial parameters and the target model parameters, and generate an answer for the first prompt word.
[0269] In some embodiments, the splicing module 704 includes:
[0270] The concatenation submodule is used to concatenate the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word; the judgment submodule is used to determine whether the obtained concatenation result meets the maximum input information length supported by the large language model; if it meets the requirement, the first unit is triggered; the first unit is used to determine the concatenation result as the second prompt word; if it does not meet the requirement, the second unit is triggered; the second unit is used to compress the concatenation result to obtain the second prompt word.
[0271] In some embodiments, the second unit is specifically used for: encoding the concatenation result to obtain an encoded result with a length not greater than the maximum input information length, as a second prompt word; or, filtering out the candidate information with the highest similarity to the first prompt word from the associated candidate information; wherein the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length; and concatenating the selected candidate information with the first prompt word to obtain the second prompt word.
[0272] In some embodiments, the apparatus further includes: a correspondence establishment module, comprising:
[0273] The segmentation submodule is used to segment the current candidate information according to preset segmentation dimensions to obtain at least one set of candidate information;
[0274] The sample data acquisition submodule is used to determine the sample prompts and sample answers corresponding to each set of candidate information.
[0275] The prediction submodule is used to process the sample prompt words by combining the large language model with the initial parameters and the current model parameters of the specified network layer to obtain the predicted answer;
[0276] The adjustment submodule is used to adjust the current model parameters of the specified network layer based on the difference between the predicted answer and the sample answer, so as to obtain the model parameters corresponding to the set of candidate information.
[0277] In some embodiments, the model parameters of the specified network layer are low-rank adaptive LoRA parameters;
[0278] The prediction submodule is specifically used for:
[0279] The model parameters of the large language model with the initial parameters are corrected using the current model parameters of the specified network layer.
[0280] The sample prompts are processed using the modified large language model to obtain the predicted answer;
[0281] The answer generation module 705 is specifically used for:
[0282] The target model parameters are used to correct the model parameters of the large language model with the initial parameters;
[0283] The modified large language model is used to process the second prompt word to obtain an answer for the first prompt word.
[0284] In some embodiments, the specified network layer is a network layer in the large language model with the initial parameters;
[0285] The answer generation module 705 is specifically used for:
[0286] Replace the model parameters of the specified network layer in the large language model with the target model parameters;
[0287] The second prompt word is processed using the replaced large language model to obtain an answer for the first prompt word.
[0288] In some embodiments, the prediction submodule is specifically used for:
[0289] Add the specified network layer of the current model parameters at the specified position in the large language model with the initial parameters;
[0290] The sample prompts are processed using the added large language model to obtain the predicted answer;
[0291] The answer generation module 705 is specifically used for:
[0292] Add a specified network layer with the target model parameters at a specified position in the large language model with the initial parameters;
[0293] The second prompt word is processed using the added large language model to obtain an answer for the first prompt word.
[0294] In some embodiments, the associated candidate information determination module 702 includes:
[0295] Calculate the similarity between the feature vector of the first prompt word and the feature vector of each alternative information;
[0296] Candidate information with a similarity greater than a preset similarity threshold is identified as associated candidate information related to the first prompt word.
[0297] In some embodiments, the model parameter determination module 703 includes:
[0298] The candidate information with the highest similarity to the first prompt word is determined from the associated candidate information and used as the target information;
[0299] The model parameters corresponding to the target information are determined from the pre-established correspondence between model parameters and candidate information, and are used as the target model parameters.
[0300] In the technical solution of this application, the operations of acquiring, storing, using, processing, transmitting, providing and disclosing user dialogue information are all carried out with the user's authorization.
[0301] It should be noted that the alternative information in this embodiment comes from a publicly available dataset.
[0302] This application also provides an electronic device, such as... Figure 8 As shown, it includes:
[0303] Memory 801 is used to store computer programs;
[0304] The processor 802, when executing the program stored in the memory 801, implements the steps of any of the above-mentioned answer generation methods.
[0305] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 802, communication interface, and memory 801 communicating with each other via the communication bus.
[0306] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.
[0307] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0308] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0309] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0310] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described answer generation methods.
[0311] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the answer generation methods described above.
[0312] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0313] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0314] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for apparatus, electronic devices, and computer-readable storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0315] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method for generating answers, characterized in that, The method includes: Get the suggestion word entered by the user and use it as the first suggestion word; Based on the similarity between the first prompt word and each alternative information, related alternative information related to the first prompt word is determined from the current alternative information; wherein, each current alternative information includes at least one of the following: historical dialogue information, and knowledge information in a preset knowledge base; Based on the pre-established correspondence between model parameters and candidate information, target model parameters are determined from the model parameters corresponding to the associated candidate information; wherein, the model parameters corresponding to a candidate information are: model parameters of a specified network layer obtained by training a large language model with initial parameters based on the candidate information; The information other than the candidate information corresponding to the target model parameters in the associated candidate information is concatenated with the first prompt word to obtain the second prompt word; Using the large language model with the initial parameters and the target model parameters, the second prompt word is processed to generate an answer for the first prompt word.
2. The method according to claim 1, characterized in that, The step of concatenating the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word includes: The information other than the candidate information corresponding to the target model parameters in the associated candidate information is concatenated with the first prompt word; Determine whether the obtained concatenation result meets the maximum input information length supported by the large language model; If the conditions are met, the splicing result will be determined as the second prompt word; If the conditions are not met, the splicing result is compressed to obtain the second prompt word.
3. The method according to claim 2, characterized in that, The compression of the splicing result to obtain the second prompt word includes: The concatenation result is encoded to obtain an encoded result whose length is no greater than the maximum input information length, which is used as the second prompt word; or, From the associated candidate information, the candidate information with the highest similarity to the first prompt word is selected; wherein, the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length; the selected candidate information is concatenated with the first prompt word to obtain the second prompt word.
4. The method according to claim 1, characterized in that, The correspondence is obtained based on the following steps: According to the preset division dimensions, the current candidate information is divided into at least one set of candidate information; For each set of alternative information, determine the corresponding sample prompts and sample responses; By combining the large language model with the initial parameters and the current model parameters of the specified network layer, the sample prompt words are processed to obtain a predicted answer; Based on the difference between the predicted answer and the sample answer, the current model parameters of the specified network layer are adjusted to obtain the model parameters corresponding to the set of candidate information.
5. The method according to claim 4, characterized in that, The model parameters of the specified network layer are low-rank adaptive LoRA parameters; The process of using the large language model with the initial parameters and combining it with the current model parameters of the specified network layer to process the sample prompt words and obtain a predicted answer includes: The model parameters of the large language model with the initial parameters are corrected using the current model parameters of the specified network layer. The sample prompts are processed using the modified large language model to obtain the predicted answer; The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes: The target model parameters are used to correct the model parameters of the large language model with the initial parameters; The modified large language model is used to process the second prompt word to obtain an answer for the first prompt word.
6. The method according to claim 4, characterized in that, The specified network layer is the network layer in the large language model with the initial parameters; The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes: Replace the model parameters of the specified network layer in the large language model with the target model parameters; The second prompt word is processed using the replaced large language model to obtain an answer for the first prompt word.
7. The method according to claim 4, characterized in that, The process of using the large language model with the initial parameters and combining it with the current model parameters of the specified network layer to process the sample prompt words and obtain a predicted answer includes: Add the specified network layer of the current model parameters at the specified position in the large language model with the initial parameters; The sample prompts are processed using the added large language model to obtain the predicted answer; The process of using the large language model with the initial parameters and the target model parameters to process the second prompt word and generate an answer for the first prompt word includes: Add a specified network layer with the target model parameters at a specified position in the large language model with the initial parameters; The second prompt word is processed using the added large language model to obtain an answer for the first prompt word.
8. The method according to claim 1, characterized in that, The step of determining associated candidate information related to the first prompt word from the current candidate information based on the similarity between the first prompt word and each candidate information includes: Calculate the similarity between the feature vector of the first prompt word and the feature vector of each alternative information; Candidate information with a similarity greater than a preset similarity threshold is identified as associated candidate information related to the first prompt word; The process of determining the target model parameters from the model parameters corresponding to the associated candidate information based on the pre-established correspondence between model parameters and candidate information includes: The candidate information with the highest similarity to the first prompt word is determined from the associated candidate information and used as the target information; The model parameters corresponding to the target information are determined from the pre-established correspondence between model parameters and candidate information, and are used as the target model parameters.
9. An answer generation device, characterized in that, The device includes: The prompt word acquisition module is used to acquire the prompt word input by the user and use it as the first prompt word; The associated alternative information determination module is used to determine associated alternative information related to the first prompt word from the current alternative information based on the similarity between the first prompt word and each alternative information; wherein, each current alternative information includes at least one of the following: historical dialogue information and knowledge information in a preset knowledge base; The model parameter determination module is used to determine the target model parameters from the model parameters corresponding to the associated candidate information based on the pre-established correspondence between model parameters and candidate information; wherein, the model parameters corresponding to a candidate information are: the model parameters of a specified network layer obtained by training a large language model with initial parameters based on the candidate information; The splicing module is used to splice the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word to obtain the second prompt word; The answer generation module is used to process the second prompt word by combining the large language model with the initial parameters and the target model parameters, and generate an answer for the first prompt word; The splicing module includes: a splicing submodule, used to splice the information other than the candidate information corresponding to the target model parameters in the associated candidate information with the first prompt word; a judgment submodule, used to judge whether the obtained splicing result meets the maximum input information length supported by the large language model; if it meets the requirement, a first unit is triggered; the first unit is used to determine the splicing result as the second prompt word; if it does not meet the requirement, a second unit is triggered; the second unit is used to compress the splicing result to obtain the second prompt word; And / or, The second unit is specifically used for: encoding the concatenation result to obtain an encoded result with a length not greater than the maximum input information length, as a second prompt word; or, filtering out the candidate information with the highest similarity to the first prompt word from the associated candidate information; wherein the concatenation result of the selected candidate information and the first prompt word satisfies the maximum input information length; and concatenating the selected candidate information with the first prompt word to obtain the second prompt word. And / or, The device further includes: a correspondence establishment module, comprising: a segmentation submodule, used to segment the current candidate information according to a preset segmentation dimension to obtain at least one set of candidate information; a sample data acquisition submodule, used to determine the sample prompt words and sample answers corresponding to each set of candidate information; a prediction submodule, used to process the sample prompt words using the large language model of the initial parameters combined with the current model parameters of the specified network layer to obtain a predicted answer; and an adjustment submodule, used to adjust the current model parameters of the specified network layer based on the difference between the predicted answer and the sample answer to obtain the model parameters corresponding to the set of candidate information. And / or, The model parameters of the specified network layer are low-rank adaptive LoRA parameters; the prediction submodule is specifically used to: correct the model parameters of the initial parameter large language model using the current model parameters of the specified network layer; process the sample prompt word using the corrected large language model to obtain a predicted answer; the answer generation module is specifically used to: correct the model parameters of the initial parameter large language model using the target model parameters; process the second prompt word using the corrected large language model to obtain an answer for the first prompt word; And / or, The specified network layer is a network layer in the large language model with initial parameters; the answer generation module is specifically used to: replace the model parameters of the specified network layer in the large language model with the target model parameters; and process the second prompt word using the replaced large language model to obtain an answer for the first prompt word; And / or, The prediction submodule is specifically used to: add a specified network layer with the current model parameters at a specified position in the large language model with the initial parameters; process the sample prompt word using the large language model after the addition to obtain a predicted answer; the answer generation module is specifically used to: add a specified network layer with the target model parameters at a specified position in the large language model with the initial parameters; process the second prompt word using the large language model after the addition to obtain an answer for the first prompt word; And / or, The associated candidate information determination module includes: calculating the similarity between the feature vector of the first prompt word and the feature vector of each candidate information; and determining the candidate information with a similarity greater than a preset similarity threshold as associated candidate information related to the first prompt word. And / or, The model parameter determination module includes: determining the candidate information with the highest similarity to the first prompt word from the associated candidate information, as the target information; and determining the model parameters corresponding to the target information from the pre-established correspondence between model parameters and candidate information, as the target model parameters.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method of any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.