Method and device for adapting prompt words for large language model
By calculating the discrimination of large language models and compressing and interpreting prompt words, the problem of low adaptation efficiency of large language model prompt words in the existing technology is solved, and more efficient adaptation and better output effects are achieved.
Patent Information
- Application Number
- CN202410845879.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-06-27
AI Technical Summary
In the existing technology, the efficiency of adapting prompt words for large language models is low and the effect is poor. It lacks versatility and automation, requires a lot of manual intervention and trial and error, leads to increased complexity, and the adaptation process is time-consuming, labor-intensive, and inefficient.
The problem is determined by obtaining the historical input of the first largest language model, and the distinction between the first largest language model and the second largest language model is calculated. When the distinction is greater than the threshold, the prompt words are compressed and the vocabulary explanation content is added to generate an appropriate Prompt words with the second largest language model.
It improves the efficiency of prompt word adaptation, improves the effect of prompt words guiding the model to generate specific output, reduces manual intervention, and simplifies the adaptation process.
Smart Images

Figure CN118396124B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of large language models, and in particular to a method and device for adapting prompt words for a large language model. Background Art
[0002] In the development of artificial intelligence, large language models have become an important basic technology and have demonstrated excellent performance in natural language processing tasks. However, these models often need to adapt appropriate prompt words for specific tasks in order to better adapt to different application scenarios. A prompt word is a short text fragment that guides the model to generate a specific output. For a specific model, good results can be achieved through carefully designed prompt words, but when the model is replaced, these prompt words often become invalid, resulting in a decrease in model performance. The current prompt word adaptation process lacks universality and automation, and requires a lot of manual intervention and trial and error, which is not only time-consuming and labor-intensive, but also inefficient. In addition, the internal mechanisms and parameter differences of different language models lead to the complexity of adaptation and increase the difficulty of adaptation. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a method, device, electronic device and computer-readable storage medium for adapting prompt words for a large language model to solve the problem of low efficiency and poor effect of adapting prompt words for a large language model in the prior art.
[0004] In a first aspect of an embodiment of the present application, a method for adapting prompt words for a large language model is provided, comprising: obtaining prompt words adapted for a first large language model, determining multiple questions from historical inputs of the first large language model; inputting prompt words and each question into the first large language model, outputting multiple first results corresponding to each question, inputting prompt words and each question into a second large language model, outputting multiple second results corresponding to each question; calculating the discrimination between the first large language model and the second large language model based on the multiple first results and multiple second results corresponding to each question; when the discrimination is greater than a threshold, compressing the prompt words using the first large language model and adding vocabulary explanation content to the prompt words; and using the prompt words after compression and adding vocabulary explanation content as prompt words adapted for the second large language model.
[0005] According to a second aspect of an embodiment of the present application, there is provided a device for adapting prompt words to a large language model, comprising: an acquisition module, configured to acquire prompt words adapted to a first large language model, and determine multiple questions from the historical input of the first large language model; a model module, configured to input prompt words and each question into the first large language model, output multiple first results corresponding to each question, input prompt words and each question into the second large language model, and output multiple second results corresponding to each question; a calculation module, configured to calculate the discrimination between the first large language model and the second large language model based on the multiple first results and multiple second results corresponding to each question; a processing module, configured to compress the prompt words using the first large language model and add vocabulary explanation content to the prompt words when the discrimination is greater than a threshold; and a determination module, configured to use the prompt words after compression and the addition of vocabulary explanation content as the prompt words adapted to the second large language model.
[0006] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0007] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0008] Compared with the prior art, the embodiments of the present application have the following beneficial effects: obtaining prompt words adapted for the first language model, determining multiple questions from the historical input of the first language model; inputting prompt words and each question into the first language model, outputting multiple first results corresponding to each question, inputting prompt words and each question into the second language model, outputting multiple second results corresponding to each question; calculating the discrimination of the first language model and the second language model based on the multiple first results and multiple second results corresponding to each question; when the discrimination is greater than the threshold, compressing the prompt words using the first language model and adding vocabulary explanation content to the prompt words; using the prompt words after compression and adding vocabulary explanation content as the prompt words adapted for the second language model. The above technical means can solve the problem of low efficiency and poor effect of adapting prompt words for large language models in the prior art, thereby improving the efficiency of adapting prompt words and improving the effect of prompt words guiding the model to generate specific outputs. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 It is a flowchart of a method for adapting prompt words for a large language model provided by an embodiment of the present application;
[0011] Figure 2 It is a flowchart of another method for adapting prompt words for a large language model provided by an embodiment of the present application;
[0012] Figure 3 The present invention provides a schematic diagram of a device structure for adapting prompt words to a large language model according to an embodiment of the present invention;
[0013] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0015] A method and device for adapting prompt words for a large language model according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0016] Figure 1 It is a flowchart of a method for adapting prompt words for a large language model provided in an embodiment of the present application. Figure 1 The method for adapting prompt words for a large language model can be executed by a computer or a server, or by software on the computer or the server. Figure 1 As shown, the method for adapting prompt words for a large language model includes:
[0017] S101, obtaining prompt words adapted for a first language model, and determining a plurality of questions from historical inputs of the first language model;
[0018] S102, inputting the prompt word and each question into the first large language model, outputting a plurality of first results corresponding to each question, inputting the prompt word and each question into the second large language model, outputting a plurality of second results corresponding to each question;
[0019] S103, calculating the discrimination degree of the first largest language model and the second largest language model based on the multiple first results and the multiple second results corresponding to each question;
[0020] S104, when the discrimination is greater than the threshold, compressing the prompt word using the first language model and adding vocabulary explanation content to the prompt word;
[0021] S105, using the prompt words after compression and addition of vocabulary explanation content as prompt words adapted for the second largest language model.
[0022] The first language model is a verified language model, that is, using the prompt words adapted for the first language model can guide the first language model to generate content that satisfies the user. The second language model is a language model for which suitable prompt words have not been adapted. If a large language model directly uses prompt words adapted for other large language models, it may cause the large language model to be unable to accurately understand the meaning of the prompt words, and then the generated content quality is poor. The prior art often manually tries and adjusts the effects of different prompt words on a large language model, and then adapts suitable prompt words for the large language model. The embodiment of the present application is to automatically adapt suitable prompt words to the second language model through a series of processes with the help of the first language model and the prompt words adapted for the first language model. The first language model and the second language model can be any commonly used large language model, such as BERT (BidirectionalEncoder Representations from Transformers) and GPT-4V (GPT-4 with vision) and other models.
[0023] The prompt words and each question are input into the first language model, and the first language model can output multiple first results for each question. The prompt words and each question are input into the second language model, and the second language model can output multiple first results for each question. For each question: based on the multiple first results and multiple second results corresponding to the question, the discrimination of the first language model and the second language model can be calculated. If the discrimination is greater than the threshold, the prompt words are compressed using the first language model and the vocabulary explanation content is added to the prompt words. Compression can be a summary or extraction method to simplify the prompt words. For example, input "Please compress the prompt words for the following prompt information: Be sure to follow 1. Try to delete unimportant words 2. Keep the original word order and do not add new words 3. Be as concise as possible while ensuring sufficient information" to the first language model. Adding vocabulary explanation content is to add explanation content to some words in the prompt words. For example, there is a person's name "Zhang San" in the prompt word, and its explanation content is "Zhang San is a well-known Internet celebrity". If the discrimination is greater than the threshold, the prompt word is directly used as the prompt word adapted for the second language model.
[0024] In an exemplary embodiment, the prompt words are "You are a hotel waiter, familiar with hotel common sense, and can provide detailed answers to customers' questions", and a question is "What does the dark windows of the hotel written in the product mean?" The first language model outputs multiple results in order, "Dear, let me explain your question this way. Some windows face the corridor, so they are dark windows", "Hello, dark windows mean that they may face the corridor", and "The dark windows of the hotel refer to some room types with corridors outside the windows."
[0025] According to the technical solution provided by the embodiment of the present application, a prompt word adapted for the first language model is obtained, and multiple questions are determined from the historical input of the first language model; the prompt word and each question are input into the first language model, and multiple first results corresponding to each question are output; the prompt word and each question are input into the second language model, and multiple second results corresponding to each question are output; based on the multiple first results and multiple second results corresponding to each question, the discrimination of the first language model and the second language model is calculated; when the discrimination is greater than the threshold, the prompt word is compressed by the first language model and the vocabulary explanation content is added to the prompt word; the prompt word after compression and the addition of the vocabulary explanation content is used as the prompt word adapted for the second language model. The above technical means can solve the problem of low efficiency and poor effect of adapting prompt words for large language models in the prior art, thereby improving the efficiency of adapting prompt words and improving the effect of prompt words guiding the model to generate specific outputs.
[0026] Furthermore, when the discrimination is greater than the threshold, the following loop is executed: using the first largest language model to compress the prompt word and add vocabulary explanation content to the prompt word; updating the discrimination based on the prompt word after compression and adding vocabulary explanation content; until the discrimination is less than or equal to the threshold, the prompt word after compression and adding vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited, otherwise the loop continues.
[0027] If the updated discrimination is less than or equal to the threshold, the prompt word after compression and adding vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop can be exited at this time. If the updated discrimination is still greater than the threshold, the first largest language model is reused to compress the prompt word and add vocabulary explanation content to the prompt word, and then continue with subsequent operations.
[0028] Furthermore, updating the discrimination degree based on the prompt words after compression and addition of vocabulary explanation content includes: inputting the prompt words and each question after compression and addition of vocabulary explanation content into the first largest language model to update multiple first results corresponding to each question, inputting the prompt words and each question after compression and addition of vocabulary explanation content into the second largest language model to update multiple second results corresponding to each question; updating the discrimination degree based on the updated multiple first results and multiple second results corresponding to each question.
[0029] After the prompt word is updated, the updated prompt word and each question are input into the first language model, and multiple first results corresponding to each updated question are output. Multiple second results corresponding to each question will also be updated accordingly, and then the discrimination will also be updated accordingly.
[0030] When the discrimination is greater than the threshold, the following loop is executed: the prompt word is compressed using the first largest language model, and the discrimination is updated based on the compressed prompt word; if the updated discrimination is less than or equal to the threshold, the compressed prompt word is used as the prompt word adapted for the second largest language model, and the loop is exited; if the updated discrimination is greater than the threshold, the first largest language model is used to add vocabulary explanation content to the compressed prompt word, and the discrimination is updated based on the prompt word with the added vocabulary explanation content; if the updated discrimination is less than or equal to the threshold, the prompt word with the added vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited; if the updated discrimination is greater than the threshold, the loop is continued.
[0031] The above embodiments can refer to Figure 2 The flowchart provided is understood. Figure 2 FIG. 1 is a flow chart of another method for adapting prompt words for a large language model provided by an embodiment of the present application. Figure 2 As shown, the method includes:
[0032] When the discrimination is greater than the threshold, execute the following loop:
[0033] S201, compressing the prompt word using the first language model, and updating the discrimination degree according to the compressed prompt word;
[0034] S202, determining whether the updated discrimination is less than or equal to a threshold;
[0035] S203, if the value is less than or equal to , the compressed prompt word is used as the prompt word adapted for the second largest language model, and the loop is exited;
[0036] S204, if greater than, then using the first largest language model to add vocabulary explanation content to the compressed prompt word, and updating the discrimination degree according to the prompt word after adding the vocabulary explanation content;
[0037] S205, determining whether the updated discrimination is less than or equal to a threshold;
[0038] S206, if the value is less than or equal to the given value, the prompt word after the vocabulary explanation content is added is used as the prompt word adapted for the second largest language model, and the loop is exited;
[0039] S207, if greater than, the prompt word is restored and the cycle continues.
[0040] Restoring the prompt words means updating the prompt words after adding vocabulary explanation content to the original prompt words (the prompt words without any processing).
[0041] Furthermore, when the discrimination is greater than a threshold value: the prompt word is compressed using the first largest language model, and the discrimination is updated based on the compressed prompt word; if the updated discrimination is less than or equal to the threshold value, the compressed prompt word is used as the prompt word adapted for the second largest language model; if the updated discrimination is greater than the threshold value, the first largest language model is used to add vocabulary explanation content to the compressed prompt word, and the discrimination is updated based on the prompt word with the added vocabulary explanation content; if the updated discrimination is less than or equal to the threshold value, the prompt word with the added vocabulary explanation content is used as the prompt word adapted for the second largest language model, otherwise the first largest language model is reused to add vocabulary explanation content to the compressed prompt word.
[0042] It is not necessarily reasonable for the first language model to add vocabulary explanation content to the compressed prompt word. The first language model can be used multiple times to add vocabulary explanation content to the compressed prompt word and find the moment when the updated discrimination is less than or equal to the threshold, that is, to add reasonable vocabulary explanation content to the compressed prompt word.
[0043] Furthermore, based on the multiple first results and the multiple second results corresponding to each question, the discrimination of the first largest language model and the second largest language model is calculated, including: there are N questions in total, each question corresponds to K first results and K second results; a second result of each question and its K first results are taken as a group to obtain K groups of answer sets for each question; each second result is identified from each group of answer sets using the first largest language model, and the number of correct identifications T by the first largest language model is counted; and the discrimination P is calculated by the following formula: P=T / (N*K).
[0044] The first language model identifies the answer of the second language model to the question from each set of answers. If the identification is correct, T increases by 1. If the identification is wrong, T remains unchanged and the initial value of T is 0. The greater the discrimination, the greater the difference between the answers of the first language model and the second language model to the question, and vice versa.
[0045] Furthermore, the first largest language model is used to add vocabulary explanation content to the prompt word, including: extracting multiple keywords in the prompt word; using the first largest language model and the second largest language model to interpret each keyword respectively, to obtain the first explanation content and the second explanation content of each keyword, wherein the vocabulary explanation content includes the first explanation content and the second explanation content of each keyword; calculating the similarity between the first explanation content and the second explanation content of each keyword, and adding the first explanation content of the keyword whose similarity is less than the preset similarity to the prompt word.
[0046] If the similarity between the first explanation content and the second explanation content of a keyword is greater than or equal to the preset similarity, it means that the first explanation content and the second explanation content of the keyword are close, indicating that the first language model and the second language model have similar understandings of the keyword, then the keyword does not need to add explanation content. If the similarity between the first explanation content and the second explanation content of a keyword is less than the preset similarity, it means that the first explanation content and the second explanation content of the keyword are far apart, indicating that the first language model and the second language model have different understandings of the keyword, then the understanding of the first language model shall prevail, and the first explanation content of the keyword shall be added to the prompt word.
[0047] All the above-mentioned optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0048] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0049] Figure 3 FIG. 1 is a schematic diagram of a device for adapting prompt words for a large language model provided by an embodiment of the present application. Figure 3 As shown, the device for adapting prompt words for a large language model includes:
[0050] An acquisition module 301 is configured to acquire prompt words adapted for the first language model, and determine a plurality of questions from historical inputs of the first language model;
[0051] Model module 302, configured to input prompt words and each question into a first large language model, output a plurality of first results corresponding to each question, input prompt words and each question into a second large language model, output a plurality of second results corresponding to each question;
[0052] A calculation module 303 is configured to calculate the discrimination degree of the first language model and the second language model based on the multiple first results and the multiple second results corresponding to each question;
[0053] The processing module 304 is configured to compress the prompt word using the first language model and add vocabulary explanation content to the prompt word when the discrimination degree is greater than the threshold;
[0054] The determination module 305 is configured to use the prompt word after compression and addition of vocabulary explanation content as the prompt word adapted for the second largest language model.
[0055] According to the embodiment of the present application, a technical solution is provided. According to the embodiment of the present application, a technical solution is provided to obtain prompt words adapted for the first language model, and multiple questions are determined from the historical input of the first language model; the prompt words and each question are input into the first language model, and multiple first results corresponding to each question are output; the prompt words and each question are input into the second language model, and multiple second results corresponding to each question are output; based on the multiple first results and multiple second results corresponding to each question, the discrimination of the first language model and the second language model is calculated; when the discrimination is greater than the threshold, the prompt words are compressed by the first language model and the vocabulary explanation content is added to the prompt words; the prompt words after compression and the addition of vocabulary explanation content are used as prompt words adapted for the second language model. The above technical means can solve the problem of low efficiency and poor effect of adapting prompt words for large language models in the prior art, thereby improving the efficiency of adapting prompt words and improving the effect of prompt words guiding the model to generate specific outputs.
[0056] In some embodiments, the determination module 305 is further configured to compress the prompt word using the first largest language model and add vocabulary explanation content to the prompt word; update the discrimination based on the prompt word after compression and adding vocabulary explanation content; until the discrimination is less than or equal to the threshold, the prompt word after compression and adding vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited, otherwise the loop continues.
[0057] In some embodiments, the determination module 305 is also configured to input the prompt words and each question after compression and addition of vocabulary explanation content into the first large language model to update multiple first results corresponding to each question, and input the prompt words and each question after compression and addition of vocabulary explanation content into the second large language model to update multiple second results corresponding to each question; based on the updated multiple first results and multiple second results corresponding to each question, update the discrimination.
[0058] In some embodiments, the determination module 305 is further configured to compress the prompt word using the first largest language model, and update the discrimination according to the compressed prompt word; if the updated discrimination is less than or equal to the threshold, the compressed prompt word is used as the prompt word adapted for the second largest language model, and the loop is exited; if the updated discrimination is greater than the threshold, the first largest language model is used to add vocabulary explanation content to the compressed prompt word, and the discrimination is updated according to the prompt word with the added vocabulary explanation content; if the updated discrimination is less than or equal to the threshold, the prompt word with the added vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited; if the updated discrimination is greater than the threshold, the loop is continued.
[0059] In some embodiments, the determination module 305 is further configured to compress the prompt word using the first largest language model, and update the discrimination according to the compressed prompt word; if the updated discrimination is less than or equal to the threshold, the compressed prompt word is used as the prompt word adapted for the second largest language model; if the updated discrimination is greater than the threshold, the first largest language model is used to add vocabulary explanation content to the compressed prompt word, and the discrimination is updated according to the prompt word with the added vocabulary explanation content; if the updated discrimination is less than or equal to the threshold, the prompt word with the added vocabulary explanation content is used as the prompt word adapted for the second largest language model, otherwise the first largest language model is reused to add vocabulary explanation content to the compressed prompt word.
[0060] In some embodiments, the determination module 305 is further configured to have a total of N questions, each question corresponding to K first results and K second results; taking a second result of each question and its K first results as a group, to obtain K groups of answer sets for each question; using the first largest language model to identify each second result from each group of answer sets, and counting the number of times T that the first largest language model correctly identifies; and calculating the discrimination P by the following formula: P=T / (N*K).
[0061] In some embodiments, the processing module 304 is further configured to extract multiple keywords from the prompt word; interpret each keyword using the first largest language model and the second largest language model respectively to obtain a first interpretation content and a second interpretation content for each keyword, wherein the vocabulary interpretation content includes the first interpretation content and the second interpretation content for each keyword; calculate the similarity between the first interpretation content and the second interpretation content for each keyword, and add the first interpretation content of the keyword whose similarity is less than a preset similarity to the prompt word.
[0062] It should be understood that the sequence numbers of the steps in the above embodiments do not imply a sequence of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0063] Figure 4 This is a schematic diagram of an electronic device 4 provided in an embodiment of the present application. Figure 4 As shown, the electronic device 4 of this embodiment includes: a processor 401, a memory 402, and a computer program 403 stored in the memory 402 and capable of running on the processor 401. When the processor 401 executes the computer program 403, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 401 executes the computer program 403, the functions of each module / unit in the above-mentioned device embodiments are implemented.
[0064] The electronic device 4 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 4 may include, but is not limited to, a processor 401 and a memory 402. Those skilled in the art will appreciate that Figure 4 The electronic device 4 is merely an example and does not limit the electronic device 4 , which may include more or fewer components than those shown in the figure, or different components.
[0065] The processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0066] The memory 402 may be an internal storage unit of the electronic device 4, for example, a hard disk or memory of the electronic device 4. The memory 402 may also be an external storage device of the electronic device 4, for example, the electronic device 4 is equipped with a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. The memory 402 may also include both an internal storage unit of the electronic device 4 and an external storage device. The memory 402 is used to store computer programs and other programs and data required by the electronic device.
[0067] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the above-mentioned functional units and module divisions are used as examples for illustration. In practical applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. In the embodiment, each functional unit and module can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit, and the above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0068] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the above-mentioned various method embodiment steps when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0069] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. These modifications or replacements do not essentially deviate the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for adapting prompt words for a large language model, characterized in that: include: Obtain prompt words adapted for a first language model, and determine a plurality of questions from historical inputs of the first language model; Input the prompt word and each question into the first large language model, and output a plurality of first results corresponding to each question; input the prompt word and each question into the second large language model, and output a plurality of second results corresponding to each question; Calculating the discrimination degree of the first language model and the second language model based on the multiple first results and the multiple second results corresponding to each question; When the discrimination degree is greater than a threshold, compressing the prompt word by using the first language model and adding vocabulary explanation content to the prompt word; Using the prompt word after compressing and adding the vocabulary explanation content as the prompt word adapted for the second largest language model; Among them, using the first largest language model to add vocabulary explanation content to the prompt word includes: extracting multiple keywords in the prompt word; using the first largest language model and the second largest language model to interpret each keyword respectively, to obtain a first explanation content and a second explanation content of each keyword, wherein the vocabulary explanation content includes the first explanation content and the second explanation content of each keyword; calculating the similarity between the first explanation content and the second explanation content of each keyword, and adding the first explanation content of the keyword whose similarity is less than a preset similarity to the prompt word.
2. The method according to claim 1, characterized in that: When the discrimination is greater than the threshold, the following loop is executed: Using the first language model to compress the prompt word and add vocabulary explanation content to the prompt word; Updating the discrimination degree according to the prompt words after compressing and adding the vocabulary explanation content; Until the discrimination degree is less than or equal to the threshold, the prompt word after the compression and addition of the vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited; otherwise, the loop is continued.
3. The method according to claim 2, characterized in that: Updating the discrimination degree according to the prompt words after compressing and adding the vocabulary explanation content includes: Inputting the prompt words and each question after the compression and addition of the vocabulary explanation content into the first language model to update multiple first results corresponding to each question, and inputting the prompt words and each question after the compression and addition of the vocabulary explanation content into the second language model to update multiple second results corresponding to each question; The degree of differentiation is updated based on the updated plurality of first results and the plurality of second results corresponding to each question.
4. The method according to claim 1, characterized in that: When the discrimination is greater than the threshold, the following loop is executed: compressing the prompt word by using the first largest language model, and updating the discrimination degree according to the compressed prompt word; If the updated discrimination degree is less than or equal to the threshold, the compressed prompt word is used as the prompt word adapted for the second largest language model, and the loop is exited; If the updated discrimination degree is greater than the threshold, using the first largest language model to add vocabulary explanation content to the compressed prompt word, and updating the discrimination degree according to the prompt word after adding the vocabulary explanation content; If the updated discrimination degree is less than or equal to the threshold, the prompt word after adding the vocabulary explanation content is used as the prompt word adapted for the second largest language model, and the loop is exited; If the updated discrimination degree is greater than the threshold, the loop continues.
5. The method according to claim 1, characterized in that: When the discrimination is greater than the threshold: compressing the prompt word by using the first largest language model, and updating the discrimination degree according to the compressed prompt word; If the updated discrimination degree is less than or equal to the threshold, using the compressed prompt word as the prompt word adapted for the second largest language model; If the updated discrimination degree is greater than the threshold, using the first largest language model to add vocabulary explanation content to the compressed prompt word, and updating the discrimination degree according to the prompt word after adding the vocabulary explanation content; If the updated distinction is less than or equal to the threshold, the prompt word after adding the vocabulary explanation content is used as the prompt word adapted for the second largest language model; otherwise, the first largest language model is reused to add the vocabulary explanation content to the compressed prompt word.
6. The method according to claim 1, characterized in that: Calculating the discrimination of the first large language model and the second large language model based on the plurality of first results and the plurality of second results corresponding to each question includes: There are N questions in total, each of which has K first results and K second results. Take a second result of each question and its K first results as a group to obtain K sets of answers for each question; Using the first largest language model to identify each second result from each set of answer sets, and counting the number of times T that the first largest language model correctly identifies the second result; The discrimination degree P is calculated by the following formula: P=T / (N*K).
7. A device for adapting prompt words for a large language model, characterized in that: include: an acquisition module, configured to acquire prompt words adapted for a first language model, and determine a plurality of questions from historical inputs of the first language model; a model module configured to input the prompt word and each question into the first large language model, output a plurality of first results corresponding to each question, input the prompt word and each question into the second large language model, and output a plurality of second results corresponding to each question; A calculation module, configured to calculate the discrimination of the first large language model and the second large language model based on the multiple first results and the multiple second results corresponding to each question; A processing module, configured to compress the prompt word using the first language model and add vocabulary explanation content to the prompt word when the discrimination degree is greater than a threshold; a determination module configured to use the prompt word after the compression and addition of the vocabulary explanation content as the prompt word adapted for the second largest language model; The processing module is also configured to extract multiple keywords from the prompt word; use the first largest language model and the second largest language model to interpret each keyword respectively to obtain a first interpretation content and a second interpretation content of each keyword, wherein the vocabulary interpretation content includes the first interpretation content and the second interpretation content of each keyword; calculate the similarity between the first interpretation content and the second interpretation content of each keyword, and add the first interpretation content of the keyword whose similarity is less than a preset similarity to the prompt word.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
