Prompt word generation method and device, program product and storage medium
By extracting target task description information and using multiple network models to work together to generate prompt words, the problem of insufficient diversity and accuracy of prompt words is solved, and better task adaptability and performance are achieved.
Patent Information
- Application Number
- CN202510152961.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-11
- Publication Date
- 2025-09-23
AI Technical Summary
In the existing technology, prompt word generation relies on the initial generation of a large model, resulting in insufficient diversity, a single optimization dimension, a lack of flexible quality evaluation, and difficulty in meeting specific task requirements.
By obtaining the target task description information, using the pre-trained network model to extract the meta-prompt set, and through the collaborative work of multiple network models to perform mapping and quality assessment, the target prompt words with a comprehensive score higher than the threshold are screened out.
The generated prompt words are both diverse and accurate, which can better adapt to the needs of specific tasks and improve the performance of the model in specific tasks.
Smart Images

Figure CN120688456A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and more specifically, to a method and device for generating prompt words, a program product, and a storage medium. Background Art
[0002] With current pre-training technology, model input often requires the support of prompt words, which are primarily used to improve the performance of language models in specific tasks. The goal of prompt word optimization technology is to dynamically adjust the input prompt words so that the model can more accurately and efficiently complete downstream tasks such as text generation, text classification, machine translation, and question-answering systems. This avoids the model's over-reliance on general knowledge, thereby improving model performance.
[0003] Currently, prompt words are typically generated using a large model, then optimized based on semantic reflection, and finally further optimized based on sentence editing to ultimately obtain the optimal prompt word. This means that prompt word generation relies entirely on the initial prompt words generated by the large model, which can lead to insufficient prompt word diversity. This is especially true when the quality of the initially generated prompt words is poor, which can limit the effectiveness of subsequent optimization. Furthermore, optimization based solely on semantic reflection and sentence editing has a relatively single optimization dimension, which can limit the effectiveness of prompt word optimization. Furthermore, the lack of flexible quality evaluation metrics can cause prompt word optimization to deviate from actual application requirements, making it difficult to ensure that the generated prompt words perform well in specific applications.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] The embodiments of the present application provide a method and device for generating prompt words, a program product, and a storage medium to at least solve the problem in the related art that accurate prompt words cannot be generated.
[0006] According to one embodiment of the present application, a method for generating prompt words is provided, comprising: obtaining task description information of a target task; performing a prompt word generation operation on the task description information using a pre-trained target network model to obtain a target prompt word; wherein the generation operation comprises: extracting multiple meta-prompts from the task description information to obtain a meta-prompt set, wherein the multiple meta-prompts each include an overview of the target task; performing a target mapping operation on the meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, wherein the target mapping operation comprises constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; and extracting the target prompt words whose quality features are greater than a preset threshold from the candidate prompt word set.
[0007] In an exemplary embodiment, the target network model is a model obtained by using a sample task description information set to perform supervised learning training on an initial network model, the initial network model including a first network model, a second network model, and a third network model, and the supervised learning training process includes: for a target sample description information in the sample task description information set, inputting the target sample description information into the first network model, and outputting a sample meta-prompt set including a plurality of sample meta-prompts from the first network model, wherein the plurality of sample meta-prompts each include an outline of a target sample task, and the target sample task is the task described by the target sample description information; The above-mentioned sample meta-prompt set is input into the above-mentioned second network model, and the above-mentioned second network model performs a sample mapping operation on the above-mentioned sample meta-prompt set, and outputs a sample candidate prompt word set including multiple sample candidate prompt words, wherein the above-mentioned sample mapping operation includes constructing a mapping relationship between the multiple sample candidate prompt words and a mapping relationship between the multiple sample candidate prompt words and preset sample candidate prompt words; the above-mentioned sample candidate prompt word set is input into the above-mentioned third network model, and the above-mentioned third network model performs a prompt word extraction operation on the above-mentioned sample candidate prompt word set to extract target sample prompt words whose quality characteristics are greater than a preset sample threshold from the above-mentioned sample candidate prompt word set.
[0008] In an exemplary embodiment, the target sample description information is input into the first network model, and the first network model outputs a sample meta-prompt set including multiple sample meta-prompt information, including: inputting the target sample description information into the first network model to obtain the sample meta-prompt set determined by the first network model in the following manner: obtaining the task requirements of the target sample task from the target sample description information; generating an initial meta-prompt set including multiple initial meta-prompts according to the task requirements, wherein the multiple initial meta-prompts each include task background information and output requirement information corresponding to the task requirements; performing aggregation operations on the task background information and the output requirement information included in the multiple initial meta-prompts based on the enhanced attention mechanism to obtain the sample meta-prompt set.
[0009] In an exemplary embodiment, based on the enhanced attention mechanism, aggregation operations are performed on the task context information and the output requirement information included in the multiple initial meta-cues to obtain the sample meta-cue set, including: converting the task context information and the output requirement information included in the multiple initial meta-cues into vector representations to obtain a first meta-cue vector set; associating weight vectors for the multiple first meta-cue vectors included in the first meta-cue vector set to obtain a second meta-cue vector set; determining the weight value of each initial meta-cue based on the normalized inner product between the second meta-cue vector set and the global attention vector; selecting multiple target sample meta-cue vectors from the multiple first meta-cue vectors included in the first meta-cue vector set using the corresponding weight values; and determining the multiple initial meta-cues corresponding to the multiple target sample meta-cue vectors as the sample meta-cue set.
[0010] In an exemplary embodiment, the sample meta-prompt set is input into the second network model, and the second network model performs a sample mapping operation on the sample meta-prompt set to output a sample candidate prompt word set including multiple sample candidate prompt words, including: inputting the multiple sample meta-prompts into the second network model to obtain the sample candidate prompt word set determined by the second network model in the following manner, wherein a target sample candidate prompt vector determined each time is used as the sample candidate prompt word, and the target sample candidate prompt vector corresponds to the sample candidate prompt word; performing a vector conversion operation on the multiple sample meta-prompts to obtain multiple sample meta-prompt vectors; constructing a mapping relationship between the multiple sample meta-prompt vectors and a mapping relationship between the multiple sample meta-prompt vectors and multiple preset sample candidate prompt vectors of the multiple preset sample candidate prompt words to obtain the sample candidate prompt word set, wherein the multiple preset sample candidate prompt words are candidate prompt words of historical sample description information that matches the target sample description information.
[0011] In an exemplary embodiment, a vector conversion operation is performed on the plurality of the above-mentioned sample meta-hints to obtain a plurality of sample meta-hint vectors, including: performing a data enhancement operation on the plurality of the above-mentioned sample meta-hints to obtain a plurality of target sample meta-hints; dividing the plurality of the above-mentioned target sample meta-hints into positive sample meta-hints and negative sample meta-hints to obtain a positive sample meta-hint set and a negative sample meta-hint set, wherein the difference value between the above-mentioned positive sample meta-hints and the above-mentioned negative sample meta-hints is greater than a preset difference value; converting the above-mentioned positive sample meta-hint set and the above-mentioned negative sample meta-hint set into vector representations, respectively, to obtain a first positive sample meta-hint vector set and a first negative sample meta-hint vector set; performing a semantic encoding operation and a syntactic analysis operation on the above-mentioned first positive sample meta-hint vector set and the above-mentioned first negative sample meta-hint vector set, respectively, to obtain a second positive sample meta-hint vector set and a second negative sample meta-hint vector set; performing a data screening operation on the above-mentioned second positive sample meta-hint vector set and the above-mentioned second negative sample meta-hint vector set, respectively, to obtain a plurality of the above-mentioned sample meta-hint vectors.
[0012] In an exemplary embodiment, the sample candidate prompt word set is input into the third network model, and the third network model performs a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set, including: inputting multiple sample candidate prompt words into the third network model to obtain target sample prompt words whose quality features are greater than the preset sample threshold from the sample candidate prompt word set by the third network model in the following manner: determining multiple predefined sample feature indicators; assigning a weight value to each of the sample feature indicators to obtain the weight of each of the sample feature indicators; calculating the quality features of each of the sample candidate prompt words using the weight of each of the sample feature indicators; and extracting the target sample prompt words whose quality feature sets are greater than the preset sample threshold from the sample candidate prompt word set based on the quality feature sets of each of the sample candidate prompt words.
[0013] In an exemplary embodiment, the loss function of the first network model includes a first loss function and a second loss function, wherein the first loss function is used to distinguish the meta-prompt types of the multiple sample meta-prompts, and the second loss function is used to align the multiple sample meta-prompts with the task requirements of the target sample task; the second loss function is determined by: converting the sample meta-prompt, the first meta-prompt and the second meta-prompt into vector representations respectively to obtain a sample meta-prompt vector, a first meta-prompt vector and a second meta-prompt vector; calculating the first cosine similarity between the sample meta-prompt vector and the first meta-prompt vector; calculating the sample meta-prompt vector and the second meta-prompt vector. ; calculating a first distance threshold between the first meta prompt vector and the second meta prompt vector; constructing the first loss function using the first cosine similarity, the second cosine similarity and the distance threshold; determining the second loss function in the following manner: determining a similarity difference value between the first meta prompt vector and the second meta prompt vector; calculating a first similarity measure between the sample meta prompt vector and the first meta prompt vector; calculating a second similarity measure between the sample meta prompt vector and the second meta prompt vector; constructing the second loss function using the similarity difference value, the first similarity measure and the second similarity measure.
[0014] In an exemplary embodiment, the loss function of the second network model includes a third loss function and a fourth loss function, wherein the third loss function is used to verify the semantic and grammatical features of the plurality of sample candidate prompt words, and the fourth loss function is used to distinguish the text types of the plurality of sample candidate prompt words. The third loss function is determined by: converting the plurality of sample candidate prompt words into vector representations to obtain a plurality of sample candidate prompt vectors; converting the plurality of sample prompt words into vector representations to obtain a plurality of sample prompt vectors; determining the probability of generating the next second sample candidate prompt word using contextual information of the target sample description information and the plurality of sample prompt words; constructing the third loss function using the plurality of sample candidate prompt vectors, the plurality of sample prompt vectors, and the probabilities; and determining the fourth loss function by: converting the plurality of sample candidate words into a plurality of embedding vectors, wherein the plurality of embedding vectors each include semantic features and structural information of the plurality of sample candidate prompt words; calculating similarities between the plurality of sample candidate words; and constructing the fourth loss function using the plurality of embedding vectors, the similarities, and preset parameters, wherein the preset parameters are parameters for controlling the smoothness of the distribution of the candidate prompt words.
[0015] In an exemplary embodiment, the loss function of the third network model is determined in the following manner: determining the first hyperparameter of the plurality of sample candidate prompt words set, and the output performance value of the third network model corresponding to the first hyperparameter; and constructing the loss function of the third network model using the sample candidate prompt word set, the first hyperparameter and the output performance value.
[0016] In an exemplary embodiment, the loss function of the target network model is: total =α·Loss contrastive +β·Loss align +γ·Loss gen +δ·Loss embed +λ·Loss BO ; Among them, the above Loss contrastive and the above Loss align are all loss functions in the first network model mentioned above. gen and the above Loss embed are all loss functions in the second network model mentioned above. BO is the loss function of the third network model, and the α, β, γ, δ, and λ all represent preset second hyperparameters for balancing the influences among the various loss functions.
[0017] According to another embodiment of the present application, a prompt word generation device is provided, including: a first acquisition module, used to obtain task description information of a target task; a first determination module, used to use a pre-trained target network model to perform a prompt word generation operation on the above-mentioned task description information to obtain a target prompt word; wherein the above-mentioned generation operation includes: extracting multiple meta-prompts from the above-mentioned task description information to obtain a meta-prompt set, and the multiple meta-prompts all include an overview of the above-mentioned target task; performing a target mapping operation on the above-mentioned meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, and the above-mentioned target mapping operation includes constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; and extracting the above-mentioned target prompt words whose quality characteristics are greater than a preset threshold from the above-mentioned candidate prompt word set.
[0018] According to another embodiment of the present application, a computer program product is provided, including a computer program, which implements the steps of any of the above method embodiments when executed by a processor.
[0019] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.
[0020] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0021] Through this application, by obtaining the task description information of the target task, using the target network model to extract a meta-prompt set including multiple meta-prompts from the task description information, performing a target mapping operation on the meta-prompt set, mapping these meta-prompts into a candidate prompt word set including multiple candidate prompt words, and extracting target prompt words from the candidate prompt word set with a total score greater than a preset score. This ensures the diversity of prompt words, which ensures a wide range of prompt words and can better adapt to the diverse needs of specific tasks. At the same time, the target prompt words selected by the total score can more accurately match the summary information of the target task, improving the performance of the model in specific tasks. Therefore, the problem of the inability to generate accurate prompt words in related technologies can be solved, and the accuracy of prompt word generation can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a hardware structure block diagram of a server device for a method for generating prompt words according to an embodiment of the present application;
[0023] Figure 2 is a flowchart of a method for generating prompt words according to an embodiment of the present application;
[0024] Figure 3 is a flowchart of a method for generating prompt words according to a specific embodiment of the present application;
[0025] Figure 4 4 is a structural block diagram of a device for generating prompt words according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0028] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 This is a hardware structure diagram of a server device for a method of generating prompt words according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the above-mentioned server device may also include a transmission device 106 for communication functions and an input and output device 108. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0029] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for generating prompt words in the embodiments of the present application. The processor 102 executes the computer program stored in the memory 104 to execute various functional applications and data processing, thereby implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0030] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by a communication provider of the server device. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0031] In this embodiment, a method for generating prompt words is provided. Figure 2 is a flow chart of a method for generating prompt words according to an embodiment of the present application, such as Figure 2As shown, the process includes the following steps:
[0032] Step S202, obtaining task description information of the target task;
[0033] Optionally, the task description information in this embodiment is a detailed description of a specific task to be completed, including information such as the task's objectives, context, and requirements. For example, in a product recommendation prompt word generation task, the task description information may include product features, target customer groups, and information points that are expected to be conveyed.
[0034] Step S204: using the pre-trained target network model to perform a prompt word generation operation on the task description information to obtain a target prompt word;
[0035] Among them, the above-mentioned generation operation includes: extracting multiple meta-prompts from the above-mentioned task description information to obtain a meta-prompt set, and the multiple meta-prompts all include the summary of the above-mentioned target task; performing a target mapping operation on the above-mentioned meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, and the above-mentioned target mapping operation includes constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; extracting the above-mentioned target prompt words whose quality characteristics are greater than a preset threshold from the above-mentioned candidate prompt word set.
[0036] Optionally, the pre-trained target network model in this embodiment refers to a model that has been pre-trained on a large amount of text data, such as the GPT (Generative Pre-trained Transformer) series, BERT (Bidirectional Encoder Representations from Transformers), T5 (Text-to-Text Transfer Transformer) in deep learning models, which have strong language understanding and generation capabilities. The target network model is used here to generate prompt words that match the task description information.
[0037] Optionally, the meta-prompt in this embodiment is a summary instruction generated based on the task description information to guide the generation of subsequent prompt words. The meta-prompt may include information such as the core requirements of the task, the target audience, or the expected output style.
[0038] Optionally, the meta-prompt set in this embodiment is a set consisting of multiple meta-prompts, each meta-prompt reflects certain aspects or summaries of the target task, and is used to increase the diversity and flexibility of prompt word generation.
[0039] Optionally, the target mapping operation in this embodiment includes generating a set of candidate prompt words from a set of meta-prompts using a prompt word mapping model. The mapping model learns how to convert meta-prompts into specific, high-quality candidate prompt words, while also considering mapping relationships with pre-set candidate prompt words (i.e., known high-quality prompt words) to further optimize the generated prompt words.
[0040] Optionally, the candidate prompt word set in this embodiment is a series of possible prompt words generated by a target mapping operation, and these prompt words are obtained based on a mapping relationship between meta-prompts and preset candidate prompt words.
[0041] Optionally, the quality features in this embodiment are used to evaluate multiple indicators of the effects of candidate prompt words, including but not limited to fluency, semantic relevance, diversity, preference alignment, etc. These features are used to screen out high-quality prompt words.
[0042] Optionally, the preset threshold in this embodiment is the minimum standard or requirement used when screening the target prompt word from the candidate prompt word set. Only when the comprehensive quality score of the candidate prompt word exceeds the preset threshold will it be selected as the target prompt word.
[0043] For example, in one specific embodiment, assume there is a task to design a recommendation prompt for a newly released smartwatch to attract potential customers. The following is an example of the specific implementation process:
[0044] Step S302: The obtained task description information includes "designing a series of attractive recommendation prompts to highlight the health monitoring function, smart assistant function and fashionable appearance of the new smart watch. The target audience is technology enthusiasts and people with strong health awareness."
[0045] Step S304: Use the pre-trained target network model to extract meta-cues from the task description information. The meta-cue set may include: "New smart watch: technology and health, fashion and intelligence, attracting technology enthusiasts", "Smart assistant: health management, all-weather monitoring, automatic reminders, fashionable design".
[0046] The meta-cue is fed into a Transformer-based prompt word mapping model. This model has been trained to map meta-cues to candidate prompt words and also considers the mapping of pre-set candidate prompt words (e.g., known high-quality recommended prompt words). The resulting candidate prompt word set might include "Explore fashionable technology, new smartwatch, health monitoring, smart life," "All-weather escort, new smartwatch, health management, the perfect fusion of technology and fashion," and "Smart assistant, new smartwatch, health reminder, fashionable appearance, the first choice for technology enthusiasts."
[0047] Each candidate cue word is scored by the evaluation module using metrics such as fluency, semantic relevance, diversity, and preference alignment (e.g., whether it appeals to the target audience). Assuming a preset threshold of 0.8, after evaluation, "Explore fashionable technology, new smartwatches, health monitoring, smart living" scored 0.85; "All-weather escort, new smartwatches, health management, the perfect fusion of technology and fashion" scored 0.90; and "Smart assistant, new smartwatches, health reminders, stylish appearance, the top choice for tech enthusiasts" scored 0.82. Therefore, "All-weather escort, new smartwatches, health management, the perfect fusion of technology and fashion" was selected as the target cue word because it scored above the preset threshold of 0.8 and had the highest quality score among the candidate set.
[0048] The execution subject of the above steps may be a terminal, a server, a specific processor provided in the terminal or server, or a processor or processing device provided relatively independently from the terminal or server, etc., but is not limited thereto.
[0049] Alternatively, the prompt word generation method of this embodiment can be applied to scenarios where text needs to be automatically generated or optimized through natural language processing technology. For example, in scenarios where content is automatically generated, a news summary system can use this method to automatically generate news headlines or summaries that are highly generalizable and fluent in language. A machine translation system can utilize this prompt word generation method to generate prompt words that are more in line with target language habits based on the source language text, thereby improving the accuracy and naturalness of the translation. For example, in the translation process from English to Chinese, the generated prompt words can help the model better understand and generate Chinese-specific expressions. In a chatbot or intelligent customer service system, this method can generate more natural, more user-friendly dialogue prompt words, improve the quality of interaction with the user, and make the dialogue more fluent and humane.
[0050] Through the above steps, task description information for the target task is obtained, and a target network model is used to extract a set of meta-cues comprising multiple meta-cues from the task description information. A target mapping operation is then performed on the set of meta-cues, mapping these meta-cues into a set of candidate cue words comprising multiple candidate cue words. Target cue words with a total score greater than a preset score are then extracted from the set of candidate cue words. This ensures the diversity of cue words, which covers a wide range and can better meet the diverse needs of specific tasks. Furthermore, the target cue words selected by total score can more accurately match the summary information of the target task, improving the model's performance in specific tasks. Therefore, the problem of the inability to generate accurate cue words in related technologies can be resolved, achieving the effect of improving the accuracy of cue word generation.
[0051] In an exemplary embodiment, the target network model is a model obtained by performing supervised learning training on an initial network model using a set of sample task description information, wherein the initial network model includes a first network model, a second network model, and a third network model. The supervised learning training process includes:
[0052] For a target sample description information in the sample task description information set, input the target sample description information into the first network model, and the first network model outputs a sample meta-hint set including a plurality of sample meta-hints, wherein the plurality of sample meta-hints each include an outline of a target sample task, and the target sample task is the task described by the target sample description information;
[0053] Inputting the sample meta-prompt set into the second network model, the second network model performing a sample mapping operation on the sample meta-prompt set to output a sample candidate prompt word set including a plurality of sample candidate prompt words, wherein the sample mapping operation includes establishing a mapping relationship between the plurality of sample candidate prompt words and a mapping relationship between the plurality of sample candidate prompt words and preset sample candidate prompt words;
[0054] The sample candidate prompt word set is input into the third network model, and the third network model performs a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set.
[0055] Optionally, this embodiment mainly trains the target network model through the collaborative work of three network models. The initial network model includes three parts: the first network model, the second network model, and the third network model, which are responsible for meta-prompt generation, meta-prompt mapping, and prompt word quality assessment and extraction, respectively.
[0056] Optionally, the first network model is a meta-prompt generation model, which is mainly used to generate a set of sample meta-prompts from the target sample task description information, that is, a set of general instructions or sentences that contain the core elements and goals of a specific task. The sample meta-prompt set is crucial for guiding the generation of subsequent prompt words. They provide a high-level semantic framework for the model, helping the model to focus on the key aspects of the task. The generation of meta-prompts can be rule-based or achieved through learning. The first network model is able to generate more targeted meta-prompts based on the specific context of the target sample task description.
[0057] Optionally, the first network model can select a Transformer model with an attention mechanism, introduce assignable negative, positive, and minimum attention weights, and flexibly allocate dynamic attention. Among them, negative weights are assigned to tokens that need to be deleted, thereby reducing the influence of the token during generation. Positive weights are assigned positive weights to important tokens to increase their attention during the generation process. Minimum weights are assigned minimum weights to irrelevant or neutral information to ensure that the model pays less attention to it. The weight allocation strategy can be trained to obtain appropriate weights through model learning. For example, the model assigns minimum weights to commonly used stop words or low-impact tags, and assigns positive weights to words that are highly relevant to user preferences. The weight learning process in the model includes: using the quality score generated by the prompt word as a supervisory signal to guide the model to adjust the negative, positive, and minimum weight allocation strategies during training to ensure that it pays correct attention to good and bad prompt words.
[0058] Optionally, the second network model is used to perform a sample mapping operation. Based on the sample meta-cue set generated by the first network model, it learns different mapping relationships to generate a diverse set of sample candidate cue words. The second network model is a mapping model that learns the mapping relationship from the original cue words to the new cue words in order to generate new cue words. A Transformer model based on an encoder-decoder structure can be selected to efficiently handle the mapping from the original cue words to the new cue words.
[0059] Optionally, the third network model is used to evaluate the quality characteristics of each prompt word in the sample candidate prompt word set, and screen out target sample prompt words whose quality is higher than a preset sample threshold.
[0060] The first network model may include a contrastive learning submodule and a Bayesian optimization module, wherein the contrastive learning submodule is used to help the model generate new prompt words by utilizing the differences between good answers or bad answers. A dual-tower structure is introduced in the contrastive learning submodule to encode "good" and "bad" prompt words separately and learn the differences between them. The embedding space is designed to separate the embeddings of good prompt words and bad prompt words, ensuring that the model can effectively distinguish between high-quality and low-quality prompt words. Input encoding: In each batch of data, the original prompt words, "good" prompt words, and "bad" prompt words are encoded separately, corresponding to three types of embeddings: original prompt word embedding: encodes the original prompt words to capture their basic semantics and task information; good prompt word embedding: encodes the good prompt words to capture the characteristics of high-quality prompt words; bad prompt word embedding: encodes the bad prompt words to capture the characteristics of low-quality prompt words.
[0061] The Bayesian optimization module is a Bayesian optimization algorithm that integrates "memory perception" to efficiently search the hyperparameter space for prompt word generation and fine-tuning within a limited time. Bayesian optimization steps:
[0062] Hyperparameter definition: Set the hyperparameter range required for the optimization goal, including the length of the prompt word, grammatical structure, and keyword weight distribution. Initialize the prior distribution for Bayesian optimization to facilitate intelligent search in the candidate space.
[0063] Define the objective function: The objective function combines the fluency, semantic relevance, and alignment of the prompt word with user preferences. The model performs experiments on each prompt word in the target task and generates a score.
[0064] Multi-dimensional indicator weighting: In order to measure the performance of prompt words in different dimensions, multiple indicators are weighted and synthesized to obtain a single target score.
[0065] Memory perception mechanism: The module's built-in memory perception mechanism saves and reuses the scoring results of historical prompt words. This mechanism avoids repeated evaluation of verified prompt words and saves computing resources.
[0066] Bayesian Update Strategy: After each round of scoring, Bayesian optimization updates the posterior distribution to approximate the optimal prompt word. The update process uses the prompt word performance data stored in the cache system to dynamically adjust the prompt word generation strategy.
[0067] Optionally, in this embodiment, the sample task description information set is a series of task description information used to train the target network model, and each piece of information describes a specific task in detail, including the background, objectives, and expected output of the task.
[0068] Optionally, in this embodiment, the sample mapping operation is performed in the second network model, including constructing a mapping relationship between sample candidate prompt words, and a mapping relationship with preset sample candidate prompt words (known high-quality prompt words) to guide the generation and optimization of sample candidate prompt words.
[0069] Optionally, in this embodiment, the quality features are used to evaluate multiple indicators of the effectiveness of the sample candidate prompt words, including but not limited to grammatical fluency, semantic relevance, diversity, preference alignment, etc.
[0070] Optionally, in this embodiment, the preset sample threshold is the minimum standard or requirement used when screening target sample prompt words from the sample candidate prompt word set. Only when the comprehensive quality score of the candidate prompt word exceeds the preset sample threshold will it be considered as the target sample prompt word.
[0071] For example, in a specific embodiment, assuming that a target network model needs to be trained to generate high-quality description text for e-commerce products, the following is a specific training process:
[0072] Step S402 , collect descriptive information of a series of e-commerce products, including detailed specifications, target markets, selling points, etc. of the products, as training data for supervised learning.
[0073] In step S404, for each sample task description, the first network model generates a plurality of generalized meta-prompts, such as "generate product descriptions that attract the target market", "emphasize the unique selling points of the product", etc. These meta-prompts may include key attributes of the product and characteristics of the target audience.
[0074] In step S406, the sample meta-cue set is input into a second network model, which generates a variety of sample candidate cues by learning different mapping relationships. These relationships may involve converting the meta-cues into specific product descriptions while also considering their relevance to pre-set high-quality description samples.
[0075] In step S408, the third network model evaluates the quality characteristics of each sample candidate prompt word, such as grammatical fluency, semantic relevance to the product's selling point, descriptive diversity, and alignment with target market preferences. A preset sample threshold, such as 0.8, is set as the minimum requirement for prompt word quality. The model then selects target sample prompt words with a quality characteristic score above 0.8 from the sample candidate prompt word set as a reference for the optimization process.
[0076] In step S410, the high-quality target sample prompts obtained in the above steps, along with their corresponding original task descriptions, are used for supervised learning to train the target network model. By optimizing loss functions such as fluency loss, semantic relevance loss, and preference alignment loss, the model gradually learns how to generate high-quality prompts that meet task requirements.
[0077] In step S412, the training process may require multiple loop iterations. In each iteration, the model adjusts its generation and optimization strategies based on feedback information, thereby continuously improving the quality of generated prompt words and their matching degree with task requirements.
[0078] Through the above training steps, the target network model obtained in this embodiment will have a high degree of automation and flexibility in generating and optimizing prompt words, and can generate high-quality and diverse prompt words based on the input task description information.
[0079] In an exemplary embodiment, the target sample description information is input into the first network model, and the first network model outputs a sample meta-prompt set including multiple sample meta-prompt information, including: inputting the target sample description information into the first network model to obtain the sample meta-prompt set determined by the first network model in the following manner: obtaining the task requirements of the target sample task from the target sample description information; generating an initial meta-prompt set including multiple initial meta-prompts according to the task requirements, wherein the multiple initial meta-prompts each include task background information and output requirement information corresponding to the task requirements; performing aggregation operations on the task background information and the output requirement information included in the multiple initial meta-prompts based on the enhanced attention mechanism to obtain the sample meta-prompt set.
[0080] Optionally, in this embodiment, task requirements refer to specific conditions or goals that need to be met to complete the task indicated by the target sample description information. For example, in a text generation task, task requirements may include maintaining grammatical correctness, maintaining content relevance, generating text with specific emotional colors, etc.
[0081] Optionally, in this embodiment, the initial meta-prompt set is a preliminary meta-prompt set automatically generated based on the understanding of task requirements, and each initial meta-prompt contains summary information of the task, which can be a description of the task background, target output, or an indication of the expected result.
[0082] Optionally, in this embodiment, the enhanced attention mechanism is improved on the basis of the traditional attention mechanism. For example, strategies such as dynamic weight adjustment, multi-head attention, or contrastive learning attention can be introduced to more accurately capture the association between task background information and output requirement information, thereby generating more optimized meta-cues.
[0083] For example, in a specific application scenario, suppose we are developing an intelligent customer service system that automatically generates high-quality responses to customer inquiries. To improve the quality of the system's responses to specific questions, we selected a Transformer model with attention mechanism adjustment to optimize the distribution of token weights when generating responses. The following steps are involved:
[0084] In step S502, a large number of customer service conversation records are collected, including customer questions and high-quality customer service responses. Each response is scored to reflect its fluency, relevance, and degree of satisfaction with the customer's query. Natural language processing technology is also used to identify important vocabulary (such as product names and FAQ terms), stop words, and neutral words involved in the conversations.
[0085] In step S504, a pre-trained Transformer model is selected as a basis, which has the ability to customize attention weight distribution.
[0086] In step S506, at the beginning of the model, a neutral attention weight, i.e., a minimum weight, is assigned to all words to ensure that the model's initial attention to all words is equal.
[0087] Step S508: During the training phase, the model learns to adjust the weights of tokens based on the quality score of each answer. For example, for high-quality responses to customers asking “How do I set up a wireless network?”, the model will recognize the importance of words such as “setup” and “wireless network” and learn to assign higher positive weights. For irrelevant words that appear in low-quality responses, such as “weather” and “news”, the model will assign smaller minimum weights. In some cases, if the responses generated by the model contain some completely irrelevant words, such as “coffee”, which have a negative impact on generating high-quality responses, the model will learn to assign negative weights to these words, thereby avoiding these words as much as possible in the subsequent generation process.
[0088] By introducing a Transformer model that can assign negative, positive, and minimum attention weights, the above steps can specifically adjust the model's lexical focus during the generation process, significantly improving the quality and relevance of the generated text. In an example of an intelligent customer service system, this strategy enables the system to understand and respond to customer questions more accurately and efficiently, improving customer satisfaction and system performance.
[0089] Optionally, the aggregation operation in this embodiment is to aggregate the task context information and output requirement information in each meta-prompt in the initial meta-prompt set under the enhanced attention mechanism to generate a more comprehensive and representative sample meta-prompt set to guide the prompt word generation of subsequent models.
[0090] In a specific embodiment, assume that an intelligent writing assistant is being developed to help users quickly generate high-quality article openings. The specific goal is to generate an attractive article opening meta-hint based on the article topic and expected style provided by the user. The steps include:
[0091] Step S602, obtaining target sample description information: the user provides the following description: "Write a popular science article about environmental protection. I hope the beginning of the article can attract readers' attention and convey the importance and urgency of environmental protection."
[0092] In step S604, the first network model extracts task requirements from the target sample description information through natural language processing technology, that is, the article theme is environmental protection, the expected style is popular science, and the goal is to generate an article opening that attracts readers and conveys importance and urgency.
[0093] Step S606, generating an initial meta-prompt set: the first network model generates multiple initial meta-prompts based on task requirements, such as: "On our planet, environmental protection is of vital importance", "Facing environmental challenges, science education is key", "Environmental protection: our common responsibility and challenge".
[0094] Step S608, aggregation operation under the enhanced attention mechanism: the first network model uses the enhanced attention mechanism to aggregate the task background information (environmental protection, popular science) and output requirement information (attractive, conveying importance) in each initial meta-prompt to generate an optimized meta-prompt set, for example: "Environmental protection popular science articles, aimed at attracting readers, emphasizing the urgency of environmental protection", "Popular science perspective, exploring the necessity of environmental protection, stimulating readers' interest".
[0095] Step S610, sample meta-prompt set output: The first network model outputs a sample meta-prompt set containing optimized meta-prompt information. As shown in the above example, these meta-prompts can more accurately reflect task requirements and expected outputs, providing more powerful guidance for subsequent prompt word generation and optimization processes.
[0096] Through the above steps, the first network model of this embodiment can generate a series of high-quality sample meta-prompt sets based on the target sample description information input by the user, providing accurate data for the subsequent prompt word generation and optimization process.
[0097] In an exemplary embodiment, based on the enhanced attention mechanism, aggregation operations are performed on the task context information and the output requirement information included in the multiple initial meta-cues to obtain the sample meta-cue set, including: converting the task context information and the output requirement information included in the multiple initial meta-cues into vector representations to obtain a first meta-cue vector set; associating weight vectors for the multiple first meta-cue vectors included in the first meta-cue vector set to obtain a second meta-cue vector set; determining the weight value of each initial meta-cue based on the normalized inner product between the second meta-cue vector set and the global attention vector; selecting multiple target sample meta-cue vectors from the multiple first meta-cue vectors included in the first meta-cue vector set using the corresponding weight values; and determining the multiple initial meta-cues corresponding to the multiple target sample meta-cue vectors as the sample meta-cue set.
[0098] Optionally, in this embodiment, a weight vector is used to measure the importance of each first-element prompt vector in the final aggregated result. In the enhanced attention mechanism, the weight vector is calculated based on the degree of correlation between each vector and the global attention vector, which can help the model understand and identify which information is more critical to completing a specific task.
[0099] Optionally, in this embodiment, the second set of meta-cue vectors is obtained by associating a weight vector with each first meta-cue vector. The weight vector here directly affects the influence of each meta-cue vector in subsequent calculations, thereby making some meta-cue information more prominent and some information less prominent.
[0100] Optionally, in this embodiment, the global attention vector is a comprehensive representation of the entire set of meta-cues, reflecting the global characteristics of all meta-cue information. When calculating the weight value of each initial meta-cue, the weight is determined based on the normalized inner product of this vector with each meta-cue vector, ensuring that the meta-cues most relevant to the global characteristics are given higher weights.
[0101] Optionally, in this embodiment, after the aggregation operation, meta-prompt vectors are selected from the first meta-prompt vector set according to the weight value of each initial meta-prompt. These vectors are considered to best reflect the core information of the task requirements and output requirements.
[0102] Optionally, in this embodiment, the final sample meta-prompt set can be a set converted back into text form by the above-mentioned target sample meta-prompt vector, or it can be a vector representation. These meta-prompts are optimized in terms of task background information and output requirement information, and are more suitable as guiding information for generating prompt words.
[0103] For example, in a specific example of optimizing market recommendation copy, you need to write a recommendation copy for a new product to highlight the product's innovation, user experience, and unique selling points. The following steps are involved:
[0104] Step S702, generating an initial meta-prompt set: Based on the product description and marketing strategy, the first network model generates multiple initial meta-prompts, such as: "Innovative technology, changing life experience", "Unique selling point, exceeding your expectations", and "The future of design starts here".
[0105] Step S704, converting into a first-element prompt vector set: word embedding is performed through a pre-trained BERT model, and the above text is converted into a corresponding vector representation to form a first-element prompt vector set.
[0106] Step S706 , associating the weight vectors to obtain a set of second meta-prompt vectors: In the enhanced attention mechanism, a weight vector is associated with each first meta-prompt vector, and the weight vector reflects the importance of the meta-prompt in completing the task.
[0107] Step S708: Calculate weights: Determine the weight of each initial meta-cue by calculating the normalized inner product between the second set of meta-cue vectors and the global attention vector (which integrates the features of all meta-cue vectors). Assuming that "Innovative technology, changing life experience" is most relevant to the global features, it will be given the highest weight.
[0108] Step S710 , selecting target sample meta-prompt vectors: according to the calculated weight values, selecting several first meta-prompt vectors with the highest weight values as target sample meta-prompt vectors.
[0109] Step S712, determine the sample meta-prompt set: convert the target sample meta-prompt vector back into text form to form a final sample meta-prompt set, such as: "Innovative technology, changing life experience", "Unique selling point, exceeding your expectations".
[0110] Through the above steps, this embodiment, based on the enhanced attention mechanism, can filter and aggregate the meta-prompt set that best meets the task requirements from multiple initial meta-prompts, providing a more precise direction for the next step of prompt word generation and optimization.
[0111] In an exemplary embodiment, the sample meta-prompt set is input into the second network model, and the second network model performs a sample mapping operation on the sample meta-prompt set to output a sample candidate prompt word set including multiple sample candidate prompt words, including: inputting the multiple sample meta-prompts into the second network model to obtain the sample candidate prompt word set determined by the second network model in the following manner, wherein a target sample candidate prompt vector determined each time is used as the sample candidate prompt word, and the target sample candidate prompt vector corresponds to the sample candidate prompt word; performing a vector conversion operation on the multiple sample meta-prompts to obtain multiple sample meta-prompt vectors; constructing a mapping relationship between the multiple sample meta-prompt vectors and a mapping relationship between the multiple sample meta-prompt vectors and multiple preset sample candidate prompt vectors of the multiple preset sample candidate prompt words to obtain the sample candidate prompt word set, wherein the multiple preset sample candidate prompt words are candidate prompt words of historical sample description information that matches the target sample description information.
[0112] Optionally, in this embodiment, the sample mapping operation involves converting sample meta-prompts into sample candidate prompt words. This process utilizes the mapping learning ability of the model to map abstract meta-prompt information into specific, optimized prompt words.
[0113] Optionally, in this embodiment, after performing the vector conversion operation, each sample meta-cue is converted into a vector representation, which contains the key information and features of the meta-cue, facilitating subsequent mapping and processing by the model.
[0114] Optionally, in this embodiment, the mapping relationship constructed in the model is used to connect sample meta-cue vectors and preset sample candidate cue vectors, as well as the relationship between sample meta-cue vectors. This helps the model understand and generate new cue words, especially those that can be aligned with excellent samples in historical data.
[0115] Optionally, in this embodiment, the preset sample candidate prompt words are a set of prompt words known in historical data that perform well in specific tasks. They will serve as a reference to help the model build a mapping relationship and generate new candidate prompt words.
[0116] For example, in a specific embodiment of optimizing responses in an intelligent customer service system, the goal is to optimize the response quality of the intelligent customer service system so that it can generate more personalized and relevant responses when handling customer inquiries. Specifically, it is necessary to generate a series of optimized response prompts (sample candidate prompts) based on the customer's question (target sample description information) to guide the customer service robot to generate higher-quality responses. The specific steps include:
[0117] Step S802 , a sample meta-prompt set: multiple optimized meta-prompts based on the customer's question, such as: "Provide detailed instructions for using Product A", "Explain the main differences between Product A and Product B".
[0118] Step S804, vector conversion operation: Use word embedding technology to convert the above sample meta-prompts into sample meta-prompt vectors. For example, using a pre-trained BERT model, each meta-prompt is converted into a vector containing semantic information.
[0119] Step S806: Constructing Mapping Relationships: The second network model constructs mapping relationships between sample meta-prompt vectors, for example, understanding the connection and difference between "Product A Instructions" and "Differences between Product A and Product B." The model also learns mapping relationships between sample meta-prompt vectors and pre-set sample candidate prompt vectors. Pre-set sample candidate prompt vectors are vector representations of high-quality responses known from historical data, such as "Product A usage steps are as follows: 1. Turn on... 2. Set up..." and "Product A has X more features than Product B, but Y less."
[0120] Step S808: Output a set of sample candidate prompt words. After mapping learning, the model generates a series of optimized candidate prompt words related to the customer's question. For example, "Detailed instructions for using Product A" or "Compare Products A and B, highlighting their respective features." Each generated sample candidate prompt word corresponds to a target sample candidate prompt vector. These vectors are generated based on the mapping relationships learned by the model and represent the optimized response direction.
[0121] Through the above steps, the second network model of this embodiment can convert abstract meta-prompts into specific and optimized candidate prompt words, and can generate prompt words that are more accurate and meet customer needs.
[0122] In an exemplary embodiment, a vector conversion operation is performed on the plurality of the above-mentioned sample meta-hints to obtain a plurality of sample meta-hint vectors, including: performing a data enhancement operation on the plurality of the above-mentioned sample meta-hints to obtain a plurality of target sample meta-hints; dividing the plurality of the above-mentioned target sample meta-hints into positive sample meta-hints and negative sample meta-hints to obtain a positive sample meta-hint set and a negative sample meta-hint set, wherein the difference value between the above-mentioned positive sample meta-hints and the above-mentioned negative sample meta-hints is greater than a preset difference value; converting the above-mentioned positive sample meta-hint set and the above-mentioned negative sample meta-hint set into vector representations, respectively, to obtain a first positive sample meta-hint vector set and a first negative sample meta-hint vector set; performing a semantic encoding operation and a syntactic analysis operation on the above-mentioned first positive sample meta-hint vector set and the above-mentioned first negative sample meta-hint vector set, respectively, to obtain a second positive sample meta-hint vector set and a second negative sample meta-hint vector set; performing a data screening operation on the above-mentioned second positive sample meta-hint vector set and the above-mentioned second negative sample meta-hint vector set, respectively, to obtain a plurality of the above-mentioned sample meta-hint vectors.
[0123] Optionally, in this embodiment, data augmentation is used to increase the diversity and richness of training data, thereby improving the generalization ability of the model. For example, in text data augmentation, the following augmentation operations can be performed: synonym replacement, semantically preserved sentence transformation, vocabulary deletion and addition, random insertion, word order adjustment, noise introduction, context expansion, and text style conversion.
[0124] Optionally, in this embodiment, positive sample meta-cues and negative sample meta-cues are sample meta-cues divided according to the degree of matching with task requirements. Positive sample meta-cues refer to those meta-cues that are more consistent with task objectives and more likely to generate high-quality prompt words, while negative sample meta-cues are just the opposite. They do not meet task requirements in some aspects and may generate lower-quality prompt words. The first positive sample meta-cue vector set and the first negative sample meta-cue vector set are positive sample meta-cues and negative sample meta-cues sets that have been converted to vector representations. The vector representation is usually generated by word embedding or more advanced semantic coding technology, which can capture the semantic features of the meta-cues. The second positive sample meta-cue vector set and the second negative sample meta-cue vector set are the positive and negative sample meta-cues vector sets that are further processed after semantic coding and syntactic analysis operations to enhance their feature representation in semantics and syntax. This helps the model to more accurately understand and distinguish high-quality and low-quality meta-cues.
[0125] This embodiment combines data augmentation, vector representation, semantic enhancement and syntactic analysis, positive and negative sample division, and data screening to improve the accuracy of generating meta-hint vectors.
[0126] In an exemplary embodiment, the sample candidate prompt word set is input into the third network model, and the third network model performs a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set, including: inputting multiple sample candidate prompt words into the third network model to obtain target sample prompt words whose quality features are greater than the preset sample threshold from the sample candidate prompt word set by the third network model in the following manner: determining multiple predefined sample feature indicators; assigning a weight value to each of the sample feature indicators to obtain the weight of each of the sample feature indicators; calculating the quality features of each of the sample candidate prompt words using the weight of each of the sample feature indicators; and extracting the target sample prompt words whose quality feature sets are greater than the preset sample threshold from the sample candidate prompt word set based on the quality feature sets of each of the sample candidate prompt words.
[0127] Optionally, in this embodiment, the sample feature indicators are a series of indicators used to evaluate the quality of sample candidate prompt words, including but not limited to grammatical fluency, semantic relevance, information richness, syntactic structure rationality, and sentiment tendency. These indicators are used to quantify various attributes of the sample, helping the model make more accurate evaluations and selections.
[0128] Optionally, in this embodiment, after determining the sample feature indicators, the third network model assigns weights to each indicator. The weights reflect the importance of different feature indicators in the overall evaluation, allowing the model to prioritize certain feature indicators based on task requirements and expected results. For example, for recommended copywriting, grammatical fluency and emotional tendency may be given higher weights.
[0129] Optionally, in this embodiment, the third network model uses the weights of various sample feature indicators to comprehensively evaluate the sample candidate prompt words and calculate their quality features. This typically involves converting text features into numerical scores using a mathematical function (such as a linear combination), reflecting the comprehensive performance of the prompt word across multiple dimensions.
[0130] For example, in a specific example of social media content recommendation, suppose we are developing a content recommendation system for a social media platform, aiming to recommend high-quality posts or comments to users. The system needs to be able to filter the most engaging and relevant posts from a list of candidate prompt words to increase user engagement and satisfaction. Specifically, the following steps are involved:
[0131] In step S902, the system determines several key sample feature indicators, including semantic relevance, grammatical fluency, information richness, emotional tendency, and user preference matching.
[0132] In step S904, in order to give priority to content related to user interaction and attraction, the system assigns higher weights to emotional tendency and user preference matching, and assigns lower weights to other indicators.
[0133] In step S906, each candidate prompt word (such as a post title or comment opening) is input into the third network model. The model calculates the quality characteristics of each prompt word based on predefined weights. For example, the sentence "Double Eleven Specials, Super Values Don't Miss Out!" has a semantic relevance score of 0.9, a grammatical fluency score of 0.95, a sentiment score of 0.9, and a user preference match score of 0.8.
[0134] In step S908 , assuming that the preset sample threshold is 0.85, it means that only when the comprehensive quality feature score of the sample candidate prompt word is higher than 0.85 will it be considered as a high-quality prompt word.
[0135] In step S910, based on the calculated quality feature set, the third network model selects prompt words with scores above a preset sample threshold. For example, "Double 11 Special Offers, Super Values Don't Miss Out!" is selected as a target sample prompt word because its overall score is above 0.85. This target sample prompt word is used to guide the system in generating or recommending posts or comments that are most appealing to users and best suit their preferences.
[0136] This embodiment uses the third network model to comprehensively evaluate and screen the quality of candidate prompt words, thereby ensuring high quality of recommended content and user satisfaction.
[0137] In an exemplary embodiment, the loss function of the first network model includes a first loss function and a second loss function, wherein the first loss function is used to distinguish the meta-prompt types of the multiple sample meta-prompts, and the second loss function is used to align the multiple sample meta-prompts with the task requirements of the target sample task; the first loss function is determined in the following manner: the sample meta-prompt, the first meta-prompt and the second meta-prompt are respectively converted into vector representations to obtain a sample meta-prompt vector, a first meta-prompt vector and a second meta-prompt vector; the first cosine similarity between the sample meta-prompt vector and the first meta-prompt vector is calculated; the sample meta-prompt vector and the second meta-prompt vector are calculated. ; calculating a first distance threshold between the first meta prompt vector and the second meta prompt vector; constructing the first loss function using the first cosine similarity, the second cosine similarity and the distance threshold; determining the second loss function in the following manner: determining a similarity difference value between the first meta prompt vector and the second meta prompt vector; calculating a first similarity measure between the sample meta prompt vector and the first meta prompt vector; calculating a second similarity measure between the sample meta prompt vector and the second meta prompt vector; constructing the second loss function using the similarity difference value, the first similarity measure and the second similarity measure.
[0138] Optionally, in this embodiment, when the first network model includes a contrastive learning submodule and a Bayesian optimization module, the first loss function of the contrastive learning submodule is a contrastive loss function, which is used to distinguish the first meta-cue (e.g., "good" cue word) from the second meta-cue (e.g., "bad" cue word). For example, the first loss function is: Loss contrastive= max(0, d(original cue word, good cue word) - d(original cue word, bad cue word) + margin), where d(.,.) represents cosine similarity (i.e., first and second cosine similarities), which measures directional consistency. Cosine similarity ranges from -1 to 1, with values closer to 1 indicating greater similarity between the two vectors. d({original cue word}_m, {good cue word}) calculates the cosine similarity between the original cue word vector and the high-quality (good) cue word vector, indicating the degree of similarity between the original cue word and the good cue word in feature space. If the value of d({original cue word}_m, {good cue word} - d(original cue word}_m, {bad cue word}) is less than margin (i.e., the first distance threshold), the model needs further learning to better distinguish between good and bad cue words. Margin is a preset distance threshold that controls the minimum distinction between good and bad cue words. This loss function effectively favors "good" cue features and avoids "bad" cue features during training. During training, the goal of the model is to minimize the contrastive loss function. If the similarity between the original prompt word and the good prompt word is greater than the similarity between the original prompt word and the bad prompt word and exceeds the margin, then the loss function value is 0, indicating that the current model weights can effectively distinguish between good and bad prompt words. If the similarity difference is less than the margin, the loss function will calculate a positive value, which forces the model to adjust the weights, increase the similarity between the original prompt word and the good prompt word, and reduce the similarity with the bad prompt word until the difference exceeds the margin. Among them, the original prompt word in the first loss function corresponds to the sample meta-prompt mentioned above, the good prompt word corresponds to the first meta-prompt mentioned above, and the bad prompt word corresponds to the second meta-prompt mentioned above, and all are used for vector representation.
[0139] The second loss function of the Bayesian optimization module is used to guide the model to generate preferred prompt words in contrastive learning. Margin Ranking Loss is used to further achieve alignment: for example, the second loss function is:
[0140] Loss align =
[0141] max(0,margin-(sim(original cue, good cue)-sim(original cue, bad cue))), where sim(.,.) represents the cosine similarity metric (i.e., the first and second similarity metrics), with values ranging from -1 to 1, with values closer to 1 indicating higher similarity. Margin (i.e., similarity difference value) is a preset threshold that controls the minimum difference between the similarity between a good cue and the original cue and the similarity between a bad cue and the original cue. The loss function ensures that "good" cue words have a higher similarity, achieving preference alignment. The original cue in the second loss function corresponds to the sample meta-cue mentioned above, the good cue corresponds to the first meta-cue, and the bad cue corresponds to the second meta-cue, all of which are represented by vectors. When training the preference alignment submodule, each original cue is paired with a good cue and a bad cue, the similarity between them is calculated, and the model parameters are adjusted using the above formula. By minimizing Loss_align, the model's generative ability can be enhanced, making it more inclined to generate high-quality good prompt words that are highly similar to the original prompt words, while avoiding generating low-quality bad prompt words with low similarity.
[0142] Through the above steps, the training process of the first network model in this embodiment can ensure that the generated meta-prompts can not only be effectively distinguished in type, but also be closely aligned with the target task requirements in terms of content, which provides more accurate and effective guidance for subsequent prompt word generation.
[0143] In an exemplary embodiment, the loss function of the second network model includes a third loss function and a fourth loss function, wherein the third loss function is used to verify the semantic and grammatical features of the plurality of sample candidate prompt words, and the fourth loss function is used to distinguish the text types of the plurality of sample candidate prompt words. The third loss function is determined by: converting the plurality of sample candidate prompt words into vector representations to obtain a plurality of sample candidate prompt vectors; converting the plurality of sample prompt words into vector representations to obtain a plurality of sample prompt vectors; determining the probability of generating the next second sample candidate prompt word using contextual information of the target sample description information and the plurality of sample prompt words; constructing the third loss function using the plurality of sample candidate prompt vectors, the plurality of sample prompt vectors, and the probabilities; and determining the fourth loss function by: converting the plurality of sample candidate words into a plurality of embedding vectors, wherein the plurality of embedding vectors each include semantic features and structural information of the plurality of sample candidate prompt words; calculating similarities between the plurality of sample candidate words; and constructing the fourth loss function using the plurality of embedding vectors, the similarities, and preset parameters, wherein the preset parameters are parameters for controlling the smoothness of the distribution of the candidate prompt words.
[0144] Optionally, in this embodiment, the third loss function can ensure the semantics and language quality of the generated content during the prompt generation process. The sample candidate prompt word vectorization is to convert all candidate prompt words into vector representations, which is usually achieved through word embedding models (such as Word2Vec, GloVe, BERT, etc.), and each word or phrase is represented as a fixed-length vector. Similarly, we also convert a series of existing sample prompts (including good prompts and bad prompts) into vector representations for subsequent comparison and probability calculation. Using the vector representations of the sample prompt words and the target sample description information (i.e., the task description and context information), calculate the probability of generating the next second sample candidate prompt word. Specifically: Initializing the input sequence is to use the current good prompt word vector as the starting point of the input sequence for generating the next word. Calculating the conditional probability is that in each step of generation, the model will use the vector representation of the current sequence (including the original prompt word and the generated words) to predict the probability distribution of the next word (P(y_t|y_{<t},x)). Based on the calculated probability distribution, the model adopts a greedy strategy or a sampling strategy to generate the next word, adds it to the sequence, and then repeats this process until a complete second sample candidate prompt word is generated.
[0145] For example, the third loss function can be a cross-entropy loss function. For example, the third loss function is: where T is the length of the target sequence (i.e., the sequence of multiple generated sample prompt words). y t is the t-th generated sample prompt vector, that is, the next word vector in the prompt word sequence. y<t represents the sequence before generating the t-th word, that is, the context information of the model when generating y t . x is the original prompt word (i.e., the sample prompt word), which provides the initial conditions and constraints for generating the sequence. P(y t |y<,x represents the probability that the model generates the next word y t (i.e., the probability of generating the next second sample candidate prompt word) given the context sequence y<t and the original prompt word x. Among them, the parameters in the third loss function are all represented by vectors.
[0146] Optionally, based on the above obtained embedding vectors, the similarity between each pair of sample candidate words can be calculated. The calculation methods of similarity can be cosine similarity, dot product, Euclidean distance, etc. In this embodiment, cosine similarity can be used as the index for calculating similarity because it can effectively measure the angular difference between two vectors rather than just the distance between them.
[0147] The fourth loss function in this embodiment can be a text recognition loss function. The text recognition loss function enhances the text differentiation ability of the output layer through contrastive learning, so that the model output can more clearly distinguish different types of text. The text recognition loss function can be constructed using the calculated similarity and the preset temperature parameter. For example, the fourth loss function is:
[0148] Where Ei and Ej are the embedding vectors (i.e., multiple embedding vectors) of different prompt words. sim(Ei,Ej) represents the similarity (e.g., cosine similarity). τ is a temperature parameter that controls the smoothness of the distribution. The loss helps the model better distinguish between different text embeddings to enhance the recognition effect generated.
[0149] Through the above steps, we constructed a text recognition loss function that accurately measures the similarity between cue word embedding vectors and guides the model to learn how to more effectively distinguish different types of text. During training, this function enables the model to continuously optimize its internal structure, improving its text recognition and classification capabilities when generating new cue words, resulting in more accurate and efficient generated cue words.
[0150] In an exemplary embodiment, the loss function of the third network model is determined in the following manner: determining the first hyperparameter of the plurality of sample candidate prompt words set, and the output performance value of the third network model corresponding to the first hyperparameter; and constructing the loss function of the third network model using the sample candidate prompt word set, the first hyperparameter and the output performance value.
[0151] Optionally, the loss function of the third network model can be a memory-aware Bayesian optimization loss function. During the hyperparameter optimization phase, memory-aware Bayesian optimization is used to improve the effectiveness of generating prompt words through the optimized hyperparameters. For example, the following loss function can be defined to evaluate the performance of different hyperparameter settings:
[0152] Where θ is the current hyperparameter setting (i.e., the first hyperparameter). D is the training dataset (i.e., the set of sample candidate prompt words). yi represents the model's output performance (i.e., the output performance value) under the given θ parameters. Memory-aware Bayesian optimization is used to optimize the generated prompt words by selecting the optimal θ at each iteration.
[0153] Bayesian optimization is an iterative process that uses Bayesian methods to find the optimal settings in the hyperparameter space. The addition of a memory-aware mechanism means that in each optimization iteration, the model considers the results of previous iterations, avoiding repeated exploration of hyperparameter combinations that have been proven to perform poorly, thereby improving optimization efficiency.
[0154] In an exemplary embodiment, the loss function of the target network model is: total =α·Loss contrastive +β·Loss align +γ·Loss gen +δ·Loss embed +λ·Loss BO ; Among them, the above Loss contrastive and the above Loss align are all loss functions in the first network model mentioned above. gen and the above Loss embed are all loss functions in the second network model mentioned above. BO is the loss function of the third network model, and the α, β, γ, δ, and λ all represent preset second hyperparameters for balancing the influences among the various loss functions.
[0155] Optionally, a total loss function is a key task in multi-objective optimization, ensuring that the model balances and optimizes multiple key performance indicators during training. In the technical solution of this embodiment, the total loss function combines contrastive loss, preference alignment loss, generation loss, text recognition loss, and Bayesian optimization loss to improve the quality of generated prompt words while ensuring that these prompt words are highly relevant to the task requirements and easy for the model to recognize.
[0156] The contrastive loss aims to help the model learn to distinguish between high-quality and low-quality cues by maximizing the similarity between good cues and the original cues, while minimizing the similarity between bad cues and the original cues. This loss ensures that the generated cues are more inclined towards the characteristics of good cues, as guided by the preference alignment submodule.
[0157] Preference alignment loss is used to guide the model in contrastive learning to generate preferred prompt words, ensuring that the generated prompt words are highly aligned with the user or task preferences. It is implemented through margin ranking loss, ensuring that the similarity score of good prompt words is higher than that of bad prompt words by a certain threshold.
[0158] The generation loss ensures the semantic and grammatical quality of the generated content. It uses the cross-entropy loss function to guide the model in predicting the probability of the next word, thereby generating fluent and semantically coherent text. This loss term ensures that the generated prompt words are grammatically and semantically reasonable and natural.
[0159] The text recognition loss enhances the text differentiation capability of the output layer through contrastive learning, ensuring that the generated text embedding features have good discriminability at the output layer. This helps the prompt words output by the model more clearly distinguish different types of text, improving the accuracy and discernibility of the generated text.
[0160] During the hyperparameter optimization phase, Bayesian optimization loss is used to evaluate the performance of different hyperparameter settings, improving the effectiveness of prompt word generation through optimized hyperparameters. Using a memory-aware Bayesian optimization loss, we can efficiently search the hyperparameter space for prompt word generation and fine-tuning within a limited timeframe, further improving prompt word quality.
[0161] Optionally, α is the weight of the contrastive loss, which controls the emphasis placed on the model's ability to distinguish between good and bad cues during training. β is the weight of the preference alignment loss, which influences how closely the generated cues align with specific preferences. γ is the weight of the generation loss, which ensures the semantic and grammatical quality of the generated text. δ is the weight of the text identification loss, which enhances the discriminability and recognizability of the generated text. λ is the weight of the Bayesian optimization loss, which guides the model to adjust hyperparameters to improve the efficiency of generating cues.
[0162] By adjusting the values of these hyperparameters, we can balance the model's performance in generating high-quality prompt words, preference alignment, grammatical quality, text recognition, and hyperparameter optimization, thereby achieving the best prompt word generation effect.
[0163] The total loss function in this embodiment takes into account multiple aspects of prompt word generation, from quality to grammar, to task preference and hyperparameter optimization, ensuring a comprehensive optimization framework.
[0164] The following is a specific example to illustrate the above method. This embodiment uses the example of generating prompt words for product recommendations. The following is an optimization model for prompt words in the product recommendation scenario. The model includes: a main model (corresponding to the first network model mentioned above), a prompt word mapping model (corresponding to the second network model mentioned above), a preference alignment submodule, and a Bayesian optimization module (corresponding to the third network model mentioned above), wherein:
[0165] The main model uses a Transformer model with an attention weighting mechanism. It uses positive, negative, and minimum weighting learning to retain key information and deemphasize irrelevant information. Positive weighting assigns positive weights to important tokens, increasing their attention during generation. Negative weighting assigns negative weights to tokens that should be removed, reducing their influence during generation. Minimum weighting assigns minimal weight to irrelevant or neutral information, ensuring the model pays less attention to it.
[0166] The weight assignment strategy involves learning appropriate weights through model training. For example, the model assigns minimal weights to commonly used stop words or low-impact tokens, and assigns positive weights to words that are highly relevant to user preferences.
[0167] The weight learning process in the main model includes: using the quality score generated by the prompt words as a supervision signal to guide the model to adjust the allocation strategies of negative, positive, and minimum weights during training, ensuring that it pays correct attention to good and bad prompt words.
[0168] For example, the mapping generation of the Transformer model with an attention weight allocation mechanism from meta-prompts to recommended prompt words includes:
[0169] 1. Meta-prompt generation includes:
[0170] Input data: Task description, which is the basic information about product recommendation.
[0171] Task description: "Design an eye-catching prompt word to showcase the advantages of the new smartphone, highlighting its high-definition screen and long battery life characteristics";
[0172] Meta-prompt generation: Based on the task description, the model generated the following meta-prompts: "Generate recommended prompt words for the new smartphone to showcase the advantages of the high-definition screen and long battery life", "Please design an attractive prompt word to highlight the high screen resolution and battery life performance of the new smartphone";
[0173] Output data: The above-generated set of meta-prompt candidates provides input for the next mapping model.
[0174] 2. Prompt word mapping model training includes:
[0175] Model architecture: Use a Transformer model with an attention weight allocation mechanism, which can retain key information and weaken irrelevant information by learning positive, negative, and minimum weights.
[0176] Positive, negative, and minimum weight allocation:
[0177] Positive weights: Assign positive weights to key information such as "new smartphone", "high-definition screen", "long battery life", etc., to increase their attention during generation.
[0178] Negative weights: Assign negative weights to the words to be deleted, such as words irrelevant to the task description (e.g., "environment", "weather", etc.), to reduce their influence during generation.
[0179] Minimal weights: Assign minimal weights to unimportant or neutral information (such as "of", "and", etc.) to ensure that the model does not over-focus on these words.
[0180] 3. The mapping relationship learning process includes:
[0181] Training data construction:
[0182] Data sources: prompt word optimization cases in historical recommendation activities, manually constructed prompt word optimization pairs, and prompt words generated using a pre-trained language model and their quality annotations.
[0183] Data format: Each sample contains an input prompt word (meta prompt) and an output prompt word (optimized recommended prompt word).
[0184] Annotated dimensions: optimization goal, fluency, relevance, and preference alignment.
[0185] Preprocessing and feature encoding:
[0186] BERT is used to semantically encode the input prompt words and extract keywords as additional features.
[0187] Perform data enhancement, including synonym replacement, random insertion or deletion of non-key words, and translation and back translation, to increase data diversity.
[0188] Perform data screening, retain high-quality prompt word pairs, and eliminate samples with poor optimization effects.
[0189] Learning mechanism:
[0190] Through supervised learning, the model captures the mapping rules between input prompt words and output prompt words and is optimized through a loss function (such as cross entropy).
[0191] 4. Positive and negative sample comparison includes:
[0192] Positive samples: new prompt words that perform well after optimization.
[0193] Negative samples: prompt words that have poor effects or deviate from the original meaning after optimization.
[0194] Contrastive learning: The model simultaneously learns from positive and negative samples during training. By comparing the differences between positive and negative samples, it enhances its ability to generate optimized prompt words, ensuring that the generated prompt words both reflect product characteristics and attract the target user group.
[0195] 5. Specific implementation steps include:
[0196] Data preparation: Collect and annotate a large number of prompt word pairs to ensure that the data covers various scenarios for product recommendations, including the high-definition screens and long battery life features of new smartphones.
[0197] Model initialization: Use the pre-trained Transformer model, whose internal attention mechanism has positive, negative and minimum weight distribution capabilities.
[0198] Forward propagation: The meta-cue is input into the model. Through the multi-head attention mechanism, the model dynamically assigns attention weights and generates the cue words to be optimized.
[0199] Weight adjustment: During the training process, the model adjusts the distribution strategy of positive, negative, and minimum weights based on the quality evaluation of the prompt word generation (such as fluency and relevance).
[0200] Backpropagation and optimization: Using the quality scores of the annotations as supervision signals, the model parameters are optimized through backpropagation to more accurately distribute the above three weights.
[0201] Evaluation and selection: At the end of each training cycle, the quality of the model-generated prompt words is evaluated, and model parameters or training strategies are adjusted as needed.
[0202] 6. Application examples include:
[0203] The meta tip before optimization was: "Generate recommendation tips for new smartphones, showcasing their high-definition screens and long battery life advantages."
[0204] The optimized prompt is: "Experience the new smartphone, ultra-high-definition screen, long-lasting battery life, and make your digital life more exciting."
[0205] In this specific embodiment, through the learning of positive, negative and minimum weights, the model can more accurately control the generation process. The generated prompt words are not only grammatically fluent but also highly relevant and aligned with user preferences.
[0206] In the above specific embodiment, the input and output formats of the meta-prompt word generation mechanism are respectively:
[0207] Input format: The input for meta-cue word generation consists of the following parts, which aim to capture the contextual information of the current task, the target requirements, and the constraints on the generated cue words:
[0208] Task Description: Type: Text description. Content: The task objective (e.g., information extraction, text summarization) and background information related to the task. Features: Open-ended, allowing large language models to understand the scope and context of the task.
[0209] Prompt Generation Target: Type: Structured instructions or keyword lists. Content: The generation target that the prompt must meet, such as a specific tone, length limit, or structural requirements (e.g., whether it contains a question). Characteristics: Strong constraints, providing specific direction for generating meta-prompts.
[0210] Output format: The output of the meta-prompt word generation is a set of optimized meta-prompt words with the following structure and content characteristics:
[0211] Main Meta-cue Term: Type: Complete text prompt. Content: Core prompt term passed directly to the main prompt mapping model for further optimization. Features: Clear logic, high coverage, and adaptability to the task context. Key Parameters and Settings: Generation method selection. Meta-cue term generation strategies used include: Zero-shot generation: Directly generating meta-cues based on the large model's natural language understanding capabilities for the task. Multi-round interactive generation: Gradually refining the prompt term content through multiple rounds of feedback.
[0212] Generation Length: Sets the maximum / minimum character limit to avoid generating too short or too long prompts. Setting method: Based on the task type (for example, summary tasks tend to have shorter prompts).
[0213] Generation mode: Structured generation: limits the output format, such as "question + background information + goal description". Free generation: allows the model to output flexibly and adapt to a wider range of tasks.
[0214] Language feature control: Control the language style (such as formal / informal tone) of generated prompt words by setting decoder parameters (such as temperature).
[0215] Diversity parameters: Adjust the Top-k sampling and temperature parameters in the generation strategy to ensure that the meta-cue words cover more semantic space.
[0216] Evaluation indicator embedding: During the meta-prompt word generation process, indicators such as fluency and semantic relevance can be embedded in advance to dynamically optimize the quality of the generated prompt words.
[0217] The generation process can be summarized as follows: The meta-cue word generation mechanism uses task requirements as its core input and combines constraints and feedback data to generate a set of initial cues (meta-cues). By optimizing the generation process parameters, such as generation length, diversity, and language characteristics, the generated meta-cues ensure that they not only provide a strong optimization foundation for the cue word mapping model but also adapt to the specific requirements of the target task.
[0218] The prompt word mapping model is a Transformer model based on the Encoder-Decoder structure, which is used to map from the original prompt word to the new prompt word.
[0219] The mapping relationship learning process of the prompt word mapping model includes:
[0220] 1. Training Data Construction: Data Pair Source: Training data consists of a large number of known prompt words and their generated new prompt words. Source: Historical records: prompt words used in actual tasks and their optimized versions. Manual Generation: Domain experts construct optimized prompt word pairs based on task objectives. Generative Model Assistance: Candidate prompt words are generated using a pre-trained language model and annotated with quality (good / bad) to form mapping pairs.
[0221] Data Format: Each data sample consists of two parts: Input: Original prompt word (raw version). Output: New prompt word (optimized version). Annotation Dimensions: Each pair of prompt words is supplemented with relevant meta-information from the optimization process: the optimization target (fluency, relevance). Learning Mechanism: The model is trained through supervised learning to capture the mapping between input prompt words and output prompt words: the input prompt word is encoded as a feature vector. The output prompt word is used as the target and optimized using a loss function (such as cross-entropy or semantic similarity loss).
[0222] The model eventually learns to adjust its generation strategy based on the semantics and goals of the original prompt word.
[0223] Is a large amount of training data required? A large number of training pairs is required to ensure the model generalizes to different task scenarios. A diverse set of training pairs should be constructed to cover various task types (summarization, question-answering, classification, etc.) and prompt word styles. Data size requirements: The data volume required is related to the complexity and diversity of the task. For common tasks, tens of thousands to hundreds of thousands of training pairs are typically required. For domain-specific tasks, high-quality training pairs must be manually annotated.
[0224] 2. Preprocessing steps during training:
[0225] During the training process of the mapping model, the following specific preprocessing steps are used to improve the training effect:
[0226] 1) Data Augmentation: To improve the model's generalization ability across different prompt word forms, commonly used data augmentation methods include: Synonym Replacement: Substitute non-critical content in the original prompt word with a synonym. Random Insertion or Deletion: Randomly insert or delete non-core words in the prompt word to generate diverse input prompt words. Back-Translation: Translate the prompt word into another language and then translate it back to generate semantically equivalent prompt words with different expression forms. Noise Injection: Inject slight random noise (such as spelling errors) into the input prompt word to enhance the robustness of the model.
[0227] 2) Feature Selection: The input features of the mapping model undergo specific processing to ensure that the core information relevant to the mapping task is retained: Semantic Encoding: The input prompt word is encoded into a semantic vector using a pre-trained language model such as BERT to capture the deeper semantics of the prompt word. Keyword Extraction: Keywords in the prompt word are extracted as additional input features to help the model understand the core intent of the prompt word. Syntactic Analysis: The prompt word is subjected to syntactic analysis, annotated with grammatical structure, and helps the model learn sentence transformation rules.
[0228] 3) Data Screening: Filter high-quality prompt word pairs from the original dataset to ensure the consistency and reliability of the training data. Filter low-quality samples: Remove prompt word pairs that have insignificant optimization effects or semantic deviations from the target. Semantic Similarity Screening: Calculate semantic similarity using a pre-trained model and retain samples with high similarity between the original prompt word and the new prompt word.
[0229] 4) Positive and Negative Sample Comparison: To enhance the model's optimization capabilities, we construct positive and negative sample pairs for comparative learning: Positive samples: new prompt words that perform well after optimization. Negative samples: new prompt words generated from low-quality prompt words or irrelevant prompt words randomly generated by the model.
[0230] In this embodiment, the preference alignment submodule includes a contrastive learning mechanism that encodes good / bad cue words through a dual-tower structure to ensure that the model can distinguish between high-quality and low-quality cue words.
[0231] The optimization module is a Bayesian optimization module: it is used to efficiently search the hyperparameter space for prompt word generation and model fine-tuning, and avoids repeated evaluation through a memory-aware mechanism to speed up the optimization process.
[0232] like Figure 3 The above is a specific embodiment of the method for generating prompt words through a prompt word optimization model, which includes the following steps:
[0233] S301, meta-prompt generation stage:
[0234] Input data: Task description information. In this example, it is "Design an eye-catching prompt word to showcase the advantages of the new smartphone, highlighting its high-definition screen and long battery life."
[0235] The meta-prompt generation algorithm analyzes the task description, extracts key information and requirements, and generates a set of meta-prompts. These include the following: "Generate a recommendation prompt for the new smartphone, showcasing its high-definition screen and long battery life" and "Please create an engaging prompt that highlights the high screen resolution and battery life of the new smartphone." Output: A set of meta-prompts. Each meta-prompt is a refined version of the task description, providing guidance for subsequent steps.
[0236] S302, prompt word mapping model stage:
[0237] Input data: a set of meta-hint candidates, including the two meta-hints generated above.
[0238] A Transformer model based on an encoder-decoder architecture is used as the prompt word mapping model. The model learns the mapping relationship between meta-cues and new prompt words to generate multiple candidate prompt words. This mapping process involves the model's in-depth understanding of the meta-cues and, based on this understanding, generates a set of prompt words that meet the task requirements. For example, the candidate prompt words generated by the model might include: "Experience the new smartphone, with a high-definition screen for clearer vision and longer battery life," "Long-lasting use and ultra-clear display, the new smartphone meets all your needs," and "High-definition vision and long battery life, enjoy a new smart experience." The output data: a set of candidate prompt words, each of which is an innovative interpretation of the meta-cue, designed to better engage the target audience and highlight the product's advantages.
[0239] S303, prompt word evaluation stage:
[0240] Input data: a set of candidate prompt words, including the three prompt words generated above.
[0241] The cue evaluation phase determines the quality of each candidate cue by calculating and comparing multiple metrics. In this example, the evaluation metrics include fluency, semantic relevance to the meta-cue, diversity, and preference alignment. The score for each metric reflects the cue's performance on different dimensions:
[0242] Fluency score: assesses the grammatical correctness and language fluency of the prompt words.
[0243] Prompt 1: "Experience the new smartphone, HD screen for clearer vision, longer battery life" -> 0.85, Prompt 2: "Long-term use, ultra-clear display, the new smartphone meets all your needs" -> 0.78, Prompt 3: "HD vision and long battery life, enjoy the new smart experience" -> 0.82;
[0244] Semantic relevance score: Calculates the semantic similarity between the candidate prompt word and the original meta-prompt to ensure that the prompt word closely fits the task objective.
[0245] Prompt word 1: 0.90;
[0246] prompt word 2: 0.88;
[0247] prompt word 3: 0.85;
[0248] Diversity score: measures the differences between candidate prompt words to ensure that the output prompt word set has rich expressions.
[0249] Similarity between prompt word 1 and prompt word 2: 0.75;
[0250] Similarity between prompt word 1 and prompt word 3: 0.80;
[0251] Similarity between prompt word 2 and prompt word 3: 0.78;
[0252] Average diversity score: 0.77;
[0253] Preference alignment score: Through comparative learning, the degree of alignment between prompt words and user expectations is evaluated to ensure that the prompt words not only meet the task description but also meet the user preferences in specific scenarios.
[0254] Prompt word 1: 0.88;
[0255] prompt word 2: 0.85;
[0256] prompt word 3: 0.82;
[0257] Finally, by combining these indicators and using predefined weight parameters (assuming α = 0.3, β = 0.3, γ = 0.2, δ = 0.2), the total score of each prompt word is calculated:
[0258] Total score for prompt word 1: 0.3 × 0.85 + 0.3 × 0.90 + 0.2 × 0.77 + 0.2 × 0.88 = 0.86;
[0259] Total score for prompt word 2: 0.3 × 0.78 + 0.3 × 0.88 + 0.2 × 0.77 + 0.2 × 0.85 = 0.826;
[0260] Total score for prompt word 3: 0.3 × 0.82 + 0.3 × 0.85 + 0.2 × 0.77 + 0.2 × 0.82 = 0.826;
[0261] Output data: prompt word evaluation results, including the total score of each prompt word.
[0262] S304, optimal prompt word selection stage:
[0263] Input data: prompt word evaluation results.
[0264] Based on the total score of the prompt word evaluation phase, the prompt word with the highest score is selected as the optimal prompt word for this round. In this example, prompt word 1 has the highest total score of 0.86.
[0265] Output data: The optimal prompt word is finally determined, namely "Experience the new smartphone, the high-definition screen makes the vision clearer, and the battery life is longer", which is used as the optimal prompt word output for the product recommendation task.
[0266] Through the steps of the above specific embodiments, this embodiment can automatically and efficiently generate and optimize prompt words suitable for specific product recommendation tasks, ensuring that the generated prompt words are not only grammatically and semantically reasonable, but also highly relevant, diverse, and aligned with user preferences, thereby significantly improving the attractiveness and effectiveness of product recommendation information.
[0267] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0268] This embodiment also provides a device for generating prompt words, which is used to implement the above-mentioned embodiments and preferred embodiments. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0269] Figure 4 is a structural block diagram of a device for generating prompt words according to an embodiment of the present application, such as Figure 4 As shown, the device includes:
[0270] A first acquisition module 42 is used to obtain task description information of the target task;
[0271] A first determining module 44 is configured to generate a prompt word for the task description information using a pre-trained target network model to obtain a target prompt word;
[0272] The generation operation includes: extracting multiple meta-prompts from the task description information to obtain a meta-prompt set, wherein the multiple meta-prompts all include a summary of the target task; performing a target mapping operation on the meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, wherein the target mapping operation includes constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; and extracting the target prompt word whose quality feature is greater than a preset threshold from the candidate prompt word set.
[0273] In an exemplary embodiment, the target network model is a model obtained by using a sample task description information set to perform supervised learning training on an initial network model, the initial network model including a first network model, a second network model, and a third network model, and the supervised learning training process includes: for a target sample description information in the sample task description information set, inputting the target sample description information into the first network model, and outputting a sample meta-prompt set including a plurality of sample meta-prompts from the first network model, wherein the plurality of sample meta-prompts each include an outline of a target sample task, and the target sample task is the task described by the target sample description information; The above-mentioned sample meta-prompt set is input into the above-mentioned second network model, and the above-mentioned second network model performs a sample mapping operation on the above-mentioned sample meta-prompt set, and outputs a sample candidate prompt word set including multiple sample candidate prompt words, wherein the above-mentioned sample mapping operation includes constructing a mapping relationship between the multiple sample candidate prompt words and a mapping relationship between the multiple sample candidate prompt words and preset sample candidate prompt words; the above-mentioned sample candidate prompt word set is input into the above-mentioned third network model, and the above-mentioned third network model performs a prompt word extraction operation on the above-mentioned sample candidate prompt word set to extract target sample prompt words whose quality characteristics are greater than a preset sample threshold from the above-mentioned sample candidate prompt word set.
[0274] In an exemplary embodiment, the target sample description information is input into the first network model in the following manner, and the first network model outputs a sample meta-prompt set including multiple sample meta-prompt information: the target sample description information is input into the first network model to obtain the sample meta-prompt set determined by the first network model in the following manner: the task requirements of the target sample task are obtained from the target sample description information; an initial meta-prompt set including multiple initial meta-prompts is generated according to the task requirements, wherein the multiple initial meta-prompts each include task background information and output requirement information corresponding to the task requirements; based on the enhanced attention mechanism, aggregation operations are performed on the task background information and the output requirement information included in the multiple initial meta-prompts to obtain the sample meta-prompt set.
[0275] In an exemplary embodiment, the above-mentioned task context information and the above-mentioned output requirement information included in the multiple above-mentioned initial meta-cues are respectively aggregated based on the enhanced attention mechanism in the following manner to obtain the above-mentioned sample meta-cue set: the above-mentioned task context information and the above-mentioned output requirement information included in the multiple above-mentioned initial meta-cues are respectively converted into vector representations to obtain a first meta-cue vector set; weight vectors are associated with the multiple first meta-cue vectors included in the above-mentioned first meta-cue vector set to obtain a second meta-cue vector set; the weight value of each above-mentioned initial meta-cue is determined according to the normalized inner product between the above-mentioned second meta-cue vector set and the global attention vector; multiple target sample meta-cue vectors are selected from the multiple first meta-vectors included in the above-mentioned first meta-cue vector set using the corresponding above-mentioned weight values; and the multiple above-mentioned initial meta-cues corresponding to the multiple above-mentioned target sample meta-cue vectors are determined as the above-mentioned sample meta-cue set.
[0276] In an exemplary embodiment, the sample meta-prompt set is input into the second network model in the following manner, and the second network model performs a sample mapping operation on the sample meta-prompt set to output a sample candidate prompt word set including a plurality of sample candidate prompt words: the plurality of sample meta-prompts are input into the second network model to obtain the sample candidate prompt word set determined by the second network model in the following manner, wherein a target sample candidate prompt vector determined each time is used as the sample candidate prompt word, and the target sample candidate prompt vector corresponds to the sample candidate prompt word: a vector conversion operation is performed on the plurality of sample meta-prompts to obtain a plurality of sample meta-prompt vectors; a mapping relationship is established between the plurality of sample meta-prompt vectors, and a mapping relationship is established between the plurality of sample meta-prompt vectors and a plurality of preset sample candidate prompt vectors of the plurality of preset sample candidate prompt words to obtain the sample candidate prompt word set, wherein the plurality of preset sample candidate prompt words are candidate prompt words of historical sample description information that matches the target sample description information.
[0277] In an exemplary embodiment, a vector conversion operation is performed on the plurality of the above-mentioned sample meta-hints in the following manner to obtain a plurality of sample meta-hints vectors: a data enhancement operation is performed on the plurality of the above-mentioned sample meta-hints to obtain a plurality of target sample meta-hints; the plurality of the above-mentioned target sample meta-hints are divided into positive sample meta-hints and negative sample meta-hints to obtain a positive sample meta-hint set and a negative sample meta-hint set, wherein the difference value between the positive sample meta-hint and the negative sample meta-hint is greater than a preset difference value; the positive sample meta-hint set and the negative sample meta-hint set are respectively converted into vector representations to obtain a first positive sample meta-hint vector set and a first negative sample meta-hint vector set; a semantic encoding operation and a syntactic analysis operation are performed on the first positive sample meta-hint vector set and the first negative sample meta-hint vector set to obtain a second positive sample meta-hint vector set and a second negative sample meta-hint vector set; a data screening operation is performed on the second positive sample meta-hint vector set and the second negative sample meta-hint vector set to obtain a plurality of the above-mentioned sample meta-hint vectors.
[0278] In an exemplary embodiment, the sample candidate prompt word set is input into the third network model in the following manner, and the third network model performs a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set: multiple sample candidate prompt words are input into the third network model to obtain target sample prompt words whose quality features are greater than the preset sample threshold extracted from the sample candidate prompt word set by the third network model in the following manner: multiple predefined sample feature indicators are determined; a weight value is assigned to each of the sample feature indicators to obtain the weight of each of the sample feature indicators; the quality feature of each of the sample candidate prompt words is calculated using the weight of each of the sample feature indicators; and based on the quality feature sets of each of the sample candidate prompt words, the target sample prompt words whose quality feature sets are greater than the preset sample threshold are extracted from the sample candidate prompt word set.
[0279] In an exemplary embodiment, the loss function of the first network model includes a first loss function and a second loss function, wherein the first loss function is used to distinguish the meta-prompt types of the multiple sample meta-prompts, and the second loss function is used to align the multiple sample meta-prompts with the task requirements of the target sample task; the first loss function is determined in the following manner: the sample meta-prompt, the first meta-prompt and the second meta-prompt are respectively converted into vector representations to obtain a sample meta-prompt vector, a first meta-prompt vector and a second meta-prompt vector; the first cosine similarity between the sample meta-prompt vector and the first meta-prompt vector is calculated; the sample meta-prompt vector and the second meta-prompt vector are calculated. ; calculating a first distance threshold between the first meta prompt vector and the second meta prompt vector; constructing the first loss function using the first cosine similarity, the second cosine similarity and the distance threshold; determining the second loss function in the following manner: determining a similarity difference value between the first meta prompt vector and the second meta prompt vector; calculating a first similarity measure between the sample meta prompt vector and the first meta prompt vector; calculating a second similarity measure between the sample meta prompt vector and the second meta prompt vector; constructing the second loss function using the similarity difference value, the first similarity measure and the second similarity measure.
[0280] In an exemplary embodiment, the loss function of the second network model includes a third loss function and a fourth loss function, wherein the third loss function is used to verify the semantic and grammatical features of the plurality of sample candidate prompt words, and the fourth loss function is used to distinguish the text types of the plurality of sample candidate prompt words. The third loss function is determined by: converting the plurality of sample candidate prompt words into vector representations to obtain a plurality of sample candidate prompt vectors; converting the plurality of sample prompt words into vector representations to obtain a plurality of sample prompt vectors; determining the probability of generating the next second sample candidate prompt word using contextual information of the target sample description information and the plurality of sample prompt words; constructing the third loss function using the plurality of sample candidate prompt vectors, the plurality of sample prompt vectors, and the probabilities; and determining the fourth loss function by: converting the plurality of sample candidate words into a plurality of embedding vectors, wherein the plurality of embedding vectors each include semantic features and structural information of the plurality of sample candidate prompt words; calculating similarities between the plurality of sample candidate words; and constructing the fourth loss function using the plurality of embedding vectors, the similarities, and preset parameters, wherein the preset parameters are parameters for controlling the smoothness of the distribution of the candidate prompt words.
[0281] In an exemplary embodiment, the loss function of the third network model is determined in the following manner: determining the first hyperparameter of the plurality of sample candidate prompt words set, and the output performance value of the third network model corresponding to the first hyperparameter; and constructing the loss function of the third network model using the sample candidate prompt word set, the first hyperparameter and the output performance value.
[0282] In an exemplary embodiment, the loss function of the target network model is: total =α·Loss contrastive +β·Loss align +γ·Loss gen +δ·Loss embed +λ·Loss BO ; Among them, the above Loss contrastive and the above Loss align are all loss functions in the first network model mentioned above. gen and the above Loss embed are all loss functions in the second network model mentioned above. BO is the loss function of the third network model, and the α, β, γ, δ, and λ all represent preset second hyperparameters for balancing the influences among the various loss functions.
[0283] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0284] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above method embodiments when run.
[0285] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0286] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0287] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0288] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0289] An embodiment of the present application further provides another computer program product, comprising a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above method embodiments are implemented.
[0290] An embodiment of the present application also provides a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any of the above method embodiments.
[0291] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.
[0292] Obviously, those skilled in the art should understand that the modules or steps of the present application described above can be implemented using a general-purpose computing device, they can be concentrated on a single computing device, or distributed across a network composed of multiple computing devices, they can be implemented using program code executable by the computing device, and thus, they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be performed in a different order than herein, or they can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0293] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application shall be included within the scope of protection of the present application.
Claims
1. A method for generating a prompt word, characterized in that: include: Get the task description information of the target task; Using a pre-trained target network model to perform a prompt word generation operation on the task description information to obtain a target prompt word; The generation operation includes: extracting multiple meta-prompts from the task description information to obtain a meta-prompt set, wherein the multiple meta-prompts all include a summary of the target task; performing a target mapping operation on the meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, wherein the target mapping operation includes constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; and extracting the target prompt word whose quality feature is greater than a preset threshold from the candidate prompt word set.
2. The method according to claim 1, characterized in that The target network model is a model obtained by performing supervised learning training on the initial network model using the sample task description information set, wherein the initial network model includes a first network model, a second network model, and a third network model. The supervised learning training process includes: For a target sample description information in the sample task description information set, input the target sample description information into the first network model, and the first network model outputs a sample meta-hint set including a plurality of sample meta-hints, wherein the plurality of sample meta-hints each include an outline of a target sample task, and the target sample task is the task described by the target sample description information; Inputting the sample meta-cue set into the second network model, and having the second network model perform a sample mapping operation on the sample meta-cue set to output a sample candidate cue word set including a plurality of sample candidate cue words, wherein the sample mapping operation includes establishing a mapping relationship between the plurality of sample candidate cue words and a mapping relationship between the plurality of sample candidate cue words and preset sample candidate cue words; The sample candidate prompt word set is input into the third network model, and the third network model performs a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set.
3. The method according to claim 2, characterized in that The target sample description information is input into the first network model, and the first network model outputs a sample meta prompt set including a plurality of sample meta prompt information, including: Input the target sample description information into the first network model to obtain the sample meta-hint set determined by the first network model in the following manner: Acquire the task requirements of the target sample task from the target sample description information; generating an initial meta-prompt set including a plurality of initial meta-prompts according to the task requirements, wherein the plurality of initial meta-prompts each include task background information and output requirement information corresponding to the task requirements; Based on the enhanced attention mechanism, aggregation operations are performed on the task context information and the output requirement information included in the multiple initial meta-prompts to obtain the sample meta-prompt set.
4. The method according to claim 3, characterized in that Based on the enhanced attention mechanism, an aggregation operation is performed on the task context information and the output requirement information included in the multiple initial meta-prompts to obtain the sample meta-prompt set, including: Converting the task context information and the output requirement information included in the plurality of initial meta-prompts into vector representations respectively to obtain a first meta-prompt vector set; Associating weight vectors with a plurality of first element prompt vectors included in the first element prompt vector set to obtain a second element prompt vector set; determining a weight value of each of the initial meta-cues according to a normalized inner product between the second meta-cue vector set and the global attention vector; Selecting a plurality of target sample meta prompt vectors from a plurality of first meta vectors included in the first meta prompt vector set using the corresponding weight values; A plurality of the initial meta-hints corresponding to a plurality of the target sample meta-hint vectors are determined as the sample meta-hint set.
5. The method according to claim 2, characterized in that The sample meta-prompt set is input into the second network model, and the second network model performs a sample mapping operation on the sample meta-prompt set to output a sample candidate prompt word set including a plurality of sample candidate prompt words, including: Inputting the plurality of sample meta-cues into the second network model to obtain the sample candidate cue word set determined by the second network model in the following manner, wherein a target sample candidate cue vector determined each time is used as the sample candidate cue word, and the target sample candidate cue vector corresponds to the sample candidate cue word: Performing a vector conversion operation on the plurality of sample element prompts to obtain a plurality of sample element prompt vectors; A mapping relationship between the plurality of sample meta-prompt vectors and a mapping relationship between the plurality of sample meta-prompt vectors and the plurality of preset sample candidate prompt vectors of the plurality of preset sample candidate prompt words are constructed to obtain the sample candidate prompt word set, wherein the plurality of preset sample candidate prompt words are candidate prompt words of the historical sample description information that matches the target sample description information.
6. The method according to claim 5, characterized in that Performing a vector conversion operation on the plurality of sample meta-hints to obtain a plurality of sample meta-hint vectors, including: performing a data augmentation operation on the plurality of sample meta-prompts to obtain a plurality of target sample meta-prompts; Dividing the plurality of target sample meta-prompts into positive sample meta-prompts and negative sample meta-prompts to obtain a positive sample meta-prompt set and a negative sample meta-prompt set, wherein a difference value between the positive sample meta-prompt and the negative sample meta-prompt is greater than a preset difference value; Converting the positive sample meta-prompt set and the negative sample meta-prompt set into vector representations respectively to obtain a first positive sample meta-prompt vector set and a first negative sample meta-prompt vector set; Performing a semantic encoding operation and a syntactic analysis operation on the first positive sample meta-hint vector set and the first negative sample meta-hint vector set, respectively, to obtain a second positive sample meta-hint vector set and a second negative sample meta-hint vector set; A data screening operation is performed on the second positive sample meta-prompt vector set and the second negative sample meta-prompt vector set respectively to obtain a plurality of the sample meta-prompt vectors.
7. The method according to claim 2, characterized in that Inputting the sample candidate prompt word set into the third network model, and having the third network model perform a prompt word extraction operation on the sample candidate prompt word set to extract target sample prompt words whose quality features are greater than a preset sample threshold from the sample candidate prompt word set, including: Input the plurality of sample candidate prompt words into the third network model, so as to obtain target sample prompt words whose quality features are greater than a preset sample threshold value, extracted from the sample candidate prompt word set by the third network model in the following manner: Determine a plurality of predefined sample characteristic indicators; Assigning a weight value to each of the sample characteristic indicators to obtain the weight of each of the sample characteristic indicators; Calculating the quality features of each of the sample candidate prompt words using the weights of each of the sample feature indicators; According to the quality feature sets of the sample candidate prompt words, the target sample prompt words whose quality feature sets are greater than the preset sample threshold are extracted from the sample candidate prompt word set.
8. The method according to claim 2, characterized in that The loss function of the first network model includes a first loss function and a second loss function, wherein the first loss function is used to distinguish the meta-prompt types of the plurality of sample meta-prompts, and the second loss function is used to align the plurality of sample meta-prompts with the task requirements of the target sample task; The first loss function is determined by: converting the sample meta-prompt, the first meta-prompt, and the second meta-prompt into vector representations respectively to obtain a sample meta-prompt vector, a first meta-prompt vector, and a second meta-prompt vector; calculating a first cosine similarity between the sample meta-prompt vector and the first meta-prompt vector; calculating a second cosine similarity between the sample meta-prompt vector and the second meta-prompt vector; calculating a first distance threshold between the first meta-prompt vector and the second meta-prompt vector; and constructing the first loss function using the first cosine similarity, the second cosine similarity, and the distance threshold; The second loss function is determined by: determining a similarity difference value between the first meta-prompt vector and the second meta-prompt vector; calculating a first similarity measure between the sample meta-prompt vector and the first meta-prompt vector; calculating a second similarity measure between the sample meta-prompt vector and the second meta-prompt vector; and constructing the second loss function using the similarity difference value, the first similarity measure, and the second similarity measure.
9. The method according to claim 2, characterized in that The loss function of the second network model includes a third loss function and a fourth loss function, wherein the third loss function is used to verify the semantic features and grammatical features of the plurality of sample candidate prompt words, and the fourth loss function is used to distinguish the text types of the plurality of sample candidate prompt words; The third loss function is determined as follows: Converting the plurality of sample candidate prompt words into vector representations to obtain a plurality of sample candidate prompt vectors; Convert multiple sample prompt words into vector representations to obtain multiple sample prompt vectors; Determining the probability of generating a next second sample candidate prompt word by using the context information of the target sample description information and the plurality of sample prompt words; constructing the third loss function using the plurality of sample candidate prompt vectors, the plurality of sample prompt vectors, and the probability; The fourth loss function is determined by: Converting the plurality of sample candidate words into a plurality of embedding vectors, wherein each of the plurality of embedding vectors includes semantic features and structural information of the plurality of sample candidate prompt words; Calculating similarities between a plurality of the sample candidate words; The fourth loss function is constructed using the plurality of embedding vectors, the similarities, and preset parameters, wherein the preset parameters are parameters for controlling the smoothness of the distribution of the candidate prompt words.
10. The method according to claim 2, characterized in that The loss function of the third network model is determined in the following manner: Determining first hyperparameters of the plurality of sample candidate prompt words and output performance values of the third network model corresponding to the first hyperparameters; A loss function of the third network model is constructed using the sample candidate prompt word set, the first hyperparameter, and the output performance value.
11. The method according to claim 2, characterized in that The loss function of the target network model is: Loss total =a·Loss contrastive +b·Loss align +g·Loss gen +d·Loss embed +λ·Loss BO ; Among them, the Loss contrastive and the Loss align are the loss functions in the first network model, the Loss gen and the Loss embed are the loss functions in the second network model, the Loss BO is the loss function of the third network model, and the α, β, γ, δ, and λ all represent preset second hyperparameters for balancing the influences between the respective loss functions.
12. A device for generating prompt words, characterized in that: include: The first acquisition module is used to obtain task description information of the target task; A first determination module is configured to use a pre-trained target network model to perform a prompt word generation operation on the task description information to obtain a target prompt word; The generation operation includes: extracting multiple meta-prompts from the task description information to obtain a meta-prompt set, wherein the multiple meta-prompts all include a summary of the target task; performing a target mapping operation on the meta-prompt set to obtain a candidate prompt word set including multiple candidate prompt words, wherein the target mapping operation includes constructing a mapping relationship between the multiple candidate prompt words and a mapping relationship between the multiple candidate prompt words and preset candidate prompt words; and extracting the target prompt word whose quality feature is greater than a preset threshold from the candidate prompt word set.
13. A computer program product comprising 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 11 are implemented.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 11 are implemented.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Cited By
AI dialogue cue word optimization method and system
CN121029959A
A method and system for optimizing AI dialogue prompts
CN121029959B
Large model Prompt dynamic generation method and device and medium
CN121214462A