Large model text generation method and system based on adaptive cue words

Through the adaptive prompt word generation method, using hierarchical clustering and Qwen series models to construct and evaluate prompt words, the problem of insufficient generation effect and adaptability of large language models in the processing of specific problems is solved, and more efficient and accurate text generation is achieved.

CN119623475AInactive Publication Date: 2025-03-14CHANGZHI DAYAN TWIN DIGITAL INTELLIGENCE RESEARCH INSTITUTE CO LTD +1
View PDF 0 Cites 8 Cited by

Patent Information

Application Number
CN202510143884.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-10
Publication Date
2025-03-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When existing large language models deal with specific domains or types of problems, the generation effect and adaptability are defective, and manual design prompt words are prone to selection bias and uncertainty.

Method used

A large model text generation method based on adaptive prompt words is adopted to construct problem clusters with similar characteristics through hierarchical clustering processing, representative problem samples are randomly selected to construct excellent prompt words, candidate prompt words are generated using the Qwen series model, and the prompt evaluation model is trained through the QLoRA fine-tuning method, and the prompt word with the highest score is finally selected as the optimal prompt word.

Benefits of technology

It improves the generation effect of large models when dealing with complex problems, reduces the dependence of manual design prompt words, and ensures that the best prompt words can be selected when facing complex and changeable problem sets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119623475A_ABST
    Figure CN119623475A_ABST
Patent Text Reader

Abstract

The invention provides a large model text generation method and system based on self-adaptive cue words, and belongs to the technical field of large model text generation. The technical problem to be solved is that the current large language model text generation has the defects of selection deviation and uncertainty. According to the technical scheme, hierarchical clustering processing is carried out on problems contained in a large-scale multi-task language understanding MMLU data set, a text embedding and similarity calculation matrix is adopted, and a plurality of problem clusters containing similar features are constructed and obtained; randomly extracting representative problem examples from each problem cluster, and constructing excellent cue words with remarkable guide effects for each problem based on domain knowledge and potential semantic association; a Qwen model is adopted to generate candidate cue words with diversity and pertinence for various question clusters divided in advance, a cue word bank is constructed, and each question and cue word pair in the cue word bank is manually scored; the method is applied to text generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention provides a large model text generation method and system based on adaptive prompt words, belonging to the technical field of large model text generation. Background Art

[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) have become an important tool in the field of natural language processing. Their powerful language understanding and generation capabilities can meet the needs of multiple scenarios such as text creation, question-answering systems, and machine translation. However, despite the wide versatility of large language models, their generation effect and adaptability still have certain defects when dealing with specific fields and specific types of problems. It is necessary to guide large language models to focus on the context of specific problems, accurately capture task requirements, and then generate highly relevant and high-quality texts to improve the accuracy and efficiency of large model applications.

[0003] At present, large language models usually clarify the context and goals of their generation tasks by receiving prompts provided by users. The selection and construction of prompts directly affect the accuracy and effectiveness of the model output. Appropriate prompts can effectively stimulate the deep knowledge of the model and make the content generated by the model more in line with expectations. However, the prompts designed in practice often rely on manual experience, which may lead to selection bias and uncertainty in the selection results. When performing different tasks, a large number of tests are required to come up with better prompts that can activate model parameters. There is a lack of systematic theoretical guidance and automated methods, making it difficult to ensure that the best prompts are always selected when facing complex and changing problem sets.

[0004] In view of the above defects, there is an urgent need to propose an automatic prompt word selection strategy suitable for general large models to cope with challenges such as the diversity and complexity of problems, while reducing dependence on manual labeling. Summary of the invention

[0005] In order to overcome the deficiencies in the prior art, the present invention aims to solve the following technical problem: to solve the defects of selection bias and uncertainty in the current large language model text generation, a large model text generation method and system based on adaptive prompt words are provided.

[0006] In order to solve the above technical problems, the technical solution adopted by the present invention is: a large model text generation method based on adaptive prompt words, comprising the following large model text generation steps: Step S1: Perform hierarchical clustering on the questions contained in the Large-Scale Multi-Task Language Understanding (MMLU) dataset, using text embedding and similarity calculation matrix to construct multiple question clusters containing similar features; Step S2: Randomly extract representative question samples from each question cluster, and construct excellent prompt words with significant guiding effects for each question based on domain knowledge and potential semantic associations; Step S3: Based on the constructed excellent prompt words, the Qwen series model is used to generate diverse and targeted candidate prompt words for various pre-divided question clusters, covering and adapting to the unique attributes of various input questions in the cluster, and constructing a prompt word library. Each question and prompt word pair in the prompt word library is manually scored, and scores are assigned based on the degree of association and guiding ability. The few-shot learning strategy is used to guide the language model to simulate manual scoring, and finally a dedicated dataset is constructed for fine-tuning the prompt evaluation model. Step S4: Use the QLoRA fine-tuning method to adjust the parameters of the prompt evaluation model, quantize the weights of the pre-trained large model, use the low-rank adapter LoRA to reduce memory usage, avoid accuracy compromise by adding adapters at each network layer, and use the Adam optimization algorithm and early stopping strategy to ensure that the model achieves optimal performance within a limited number of training steps; Step S5: Classify the questions according to the clusters they belong to, send the questions and the candidate prompt sets in the corresponding clusters into the evaluation model, and select the prompt word with the highest score as the optimal prompt word for the specific question; Step S6: Based on the selected optimal prompt words, guide the language model to generate high-quality response text for specific questions, and compare it with the standard answers in the MMLU test set to evaluate the generation performance of the model for complex questions based on the optimal prompt word selection method.

[0007] The specific method of constructing similar feature problem clusters in step S1 is: Based on the principle of hierarchical decomposition, data points are recursively divided into smaller and smaller subsets until the preset termination condition is reached, thus realizing the step-by-step aggregation of data points.

[0008] The specific method to achieve the step-by-step aggregation of data points is: Based on the text embedding method, each question in the MMLU dataset is converted into a high-dimensional vector representation, so that the generated vector can effectively capture the semantic association and contextual information of the question; Given a set of positive sample pairs Ω pos And the set of negative sample pairs Ω neg ,definition ∈Ω pos Representing two sentences of positive sample pairs, the corresponding vectors are and ,definition ∈Ω neg Representing two sentences of negative sample pairs, the corresponding vectors are and ; The goal is to maximize the cosine similarity between positive sample pairs and minimize the cosine similarity between negative sample pairs, that is, to satisfy: ; To achieve this goal, the text embedding scheme CoSENT is used to optimize the loss function L of the cos value. uni , the calculation formula is: ; ; Among them, λ is a positive hyperparameter used to control the degree of influence of the difference in cosine similarity between negative sample pairs and positive sample pairs; , Represent the scores of negative sample pairs and positive sample pairs respectively; Based on the generated text embedding vector, the cosine similarity method is used to calculate the similarity between questions to form a similarity matrix. The hierarchical clustering algorithm is executed to merge or split clusters according to the similarity matrix, and a tree structure that reflects the relationship between clusters is constructed. The final similar feature question cluster division is determined based on the termination conditions and pruning strategies.

[0009] The specific method of constructing excellent prompt words in step S2 is: Based on the different types of question clusters obtained in step S1, the Random function is used to randomly sample from each question cluster to ensure that the question samples selected in each question cluster can fully reflect the semantic features and structural characteristics of the question cluster, and to build a prompt word template that can accurately guide the large model to generate high-quality text for different question types.

[0010] The specific method of constructing prompt word templates for different question types is: For the selected samples, based on their domain knowledge, language logic and potential semantic associations, excellent prompt words with significant guiding effects are constructed. The expression for constructing excellent prompt word templates is: Prompt=Instruct+Overall / Detailed Description+Question; Among them, Prompt refers to the input sentence used to guide the large model to generate a specific answer; Instruct contains clear instructions for the model to perform tasks; Overall Description proposes the theme that artificial intelligence should follow when answering certain types of questions; Detailed Description means that the specific task steps are described in detail in a point-by-point manner, and Question is the specific question raised by the user.

[0011] The specific steps of constructing a dedicated dataset for the fine-tuning prompt evaluation model in step S3 are: Based on the divided clusters and the corresponding excellent prompt words, the word library and fine-tuning dataset are constructed. Referring to the constructed excellent prompt word library, the Qwen model is used to generate targeted excellent prompt words for various pre-divided question clusters, covering the unique attributes of various input questions in the cluster, and then the generated questions, candidate prompt words and corresponding answers are integrated to finally construct a candidate prompt word library; Each pair of question-prompt word combination in the prompt word library is evaluated and scored based on the relevance between the question and the prompt word, the ability to guide the model to generate the expected answer, and the comprehensive quality of the language and professional dimensions; A few-shot learning strategy is adopted, and the Qwen model is used to simulate the manual scoring process. For the prompt word evaluation task, the K-way and N-shot forms are adopted. K-way refers to dividing the questions into K different categories, each category represents a specific question type or subject area, and N-shot refers to selecting N examples in each category as training sets. These examples are manually annotated data with scores, which are used to guide the model to learn how to correctly evaluate the quality of prompt words.

[0012] The specific steps of the QLoRA fine-tuning method used in step S4 are: The 4-bit normal floating point NF quantization data type is used for calculation. The quantized weights are updated by fine-tuning the gradient of the adapter. The update adopts the weight quantization and weight dequantization processing methods. The corresponding calculation formulas are: ; ; In the formula, the 32-bit floating point number is converted to an 8-bit integer, c is the quantization constant or quantization scale, and X Int8 Represents the quantized integer data, X FP32 Represents the original single-precision floating-point data, c FP32 represents a constant or scale factor used for quantization; Then, the low-rank adapter LoRA is used to optimize the loss function by fixing the gradient of the pre-trained model weights. In traditional neural networks, the forward propagation of each layer is expressed as a standard linear projection expression Y=XW. In the LoRA calculation formula, the linear projection is enhanced by introducing an additional decomposition projection sXL1L2, so the calculation formula is: ; Where X represents the input matrix, and its size is R b×h , where b is the batch size, h is the number of hidden units; W represents the original weight matrix with size R h×o, where o is the number of output features; L1 represents the first low-rank matrix, r is the size of the low-rank factor; L2 represents the second low-rank matrix; s is a scalar that controls the influence of the low-rank term; Combining the above components, QLoRA defines a LoRA adapter on the single linear layer of the quantized base model. The calculation formula used by the LoRA adapter to process data is: ; ; In the formula, NF4 is selected as the data format of W, FP8 is used as the data format of c2, 64 blocks are used for W, and 256 blocks are used for c2; X BF16 With Y BF16 are the input and output results represented by BF16-bit floating point format; c1 FP32 The first calibration factor expressed in FP32 single-precision floating point format, c2 k-bit is the second calibration factor expressed in k-bit format; W NF4 Indicates the weight matrix using NF4 format, L1 BF16 and L2 BF16 They are two LoRA adapter layers in BF16 format, W 4-bit is the k-bit format weight matrix, W BF16 is the final BF16 weight matrix; The doubleDequant function converts the storage data type to the calculation data type through two dequantization operations.

[0013] A generation system is provided for realizing a large-model text generation method based on adaptive prompt words, including a server for performing clustering processing, building prompt words and data sets, and generating response texts, an adapter for performing data processing at the network layer, and a storage device for storing data processing models and text generation evaluation conclusions.

[0014] The beneficial effects of the present invention compared with the prior art are as follows: the large model text generation method based on the adaptive prompt word technology provided by the present invention specifically designs a set of adaptive framework models with a hierarchical clustering algorithm, a candidate prompt word library and a special prompt evaluation model as the core, aiming to improve the generation effect of the large model when processing various problems, and can overcome the problem of insufficient universality of manually designed prompt words, and provide a structured basis for the subsequent generation and optimization of prompt words; the present invention uses an online large language model to generate multiple groups of candidate prompts for the questions in each cluster based on the constructed excellent prompt words, ensuring that the diversity of various problem features is covered to cope with complex task requirements, and better alleviates the limitations that may be brought about by a fixed number of adjustable parameters, and can achieve refined selection by training a special prompt evaluation model using the QLoRA fine-tuning method. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The present invention will be further described below in conjunction with the accompanying drawings: Figure 1 A flowchart of the steps of the large model text generation method based on the adaptive prompt word technology of the present invention; Figure 2 A schematic diagram of a prompt word template structure based on optimal prompt word selection according to the present invention; Figure 3 A flow chart of the steps for generating and fine-tuning candidate prompts according to the present invention. DETAILED DESCRIPTION

[0016] like Figure 1 As shown, the present invention relates to a natural language processing technology, specifically a large model text generation method based on adaptive prompt words, which can solve the technical problem that the existing prompt word design relies on manual experience, lacks systematic theoretical guidance and automation methods, and is difficult to select the best prompt when facing a complex and changeable problem set; the text generation method proposed in the present invention aims to systematically optimize the prompt word generation and selection process to ensure that the best prompt is selected as much as possible when facing a complex and changeable problem set, further explore the potential of the large language model, and thus improve its performance in various tasks.

[0017] The large model text generation method proposed in the present invention mainly includes: Step S1: Perform hierarchical clustering on the questions contained in the Massive Multitask Language Understanding (MMLU) dataset to construct multiple clusters representing different question characteristics; Step S2: Select some representative samples and design excellent prompt words that have a high degree of matching with the corresponding question types; Step S3: Generate multiple sets of candidate prompt word sets for the questions in each cluster according to the excellent prompt words constructed above, and construct a fine-tuning dataset based on the sets; Step S4: Using the Quantized Low-Rank Adaptation (QLoRA) method to train the prompt word evaluation model; Step S5: Screening candidate prompt words through the trained evaluation model to determine the prompt words with the highest relevance to the input question and the best effectiveness; Step S6: Generate high-quality text responses using a large language model guided by adaptive prompt word technology.

[0018] The above method integrates technical means such as hierarchical clustering analysis, prompt word generation technology, and prompt word evaluation model fine-tuning to construct an adaptive prompt word optimization framework model suitable for large language models, thereby significantly enhancing the quality of generated text when facing complex problems.

[0019] To ensure that the objectives, technical solutions and advantages of the embodiments of the present invention are fully understood, the technical solutions in the embodiments will be explained in detail and accurately below. It should be clear that the embodiments only constitute a part of the many embodiments of the present invention, not all of them, and their purpose is to further illustrate the characteristics and advantages of the present invention, rather than to constitute a limitation on the claims of the present invention. Based on the embodiments disclosed in the present invention, all other embodiments that can be derived by those skilled in the art without the need for creative work fall within the scope of protection of this application. Subsequently, the practical application of the present invention will be further described in detail in combination with the accompanying drawings and specific embodiments. The following embodiments are intended to illustrate rather than limit the scope of application of the present invention.

[0020] The large model text generation method based on adaptive prompt words provided by the present invention specifically includes the following text generation steps: Step S1: Construct clusters of similar feature questions: Specifically based on the principle of hierarchical decomposition, the data points are recursively divided into smaller and smaller subsets until the preset termination conditions are reached, so as to achieve step-by-step aggregation of data points, so as to overcome the limitations of the K-means algorithm in processing complex distribution and high-dimensional data, and improve the clustering effect, stability and the ability to reveal the intrinsic structure of the data.

[0021] Furthermore, the specific steps for constructing clusters of similar feature problems are as follows: Based on the text embedding method, each question in the MMLU dataset is converted into a high-dimensional vector representation to ensure that the generated vector can effectively capture the semantic association and contextual information between questions; Given a set of positive sample pairs Ω pos And the set of negative sample pairs Ω neg,definition ∈Ω pos Representing two sentences of positive sample pairs, the corresponding vectors are and ,definition ∈Ω neg Representing two sentences of negative sample pairs, the corresponding vectors are and The goal is to maximize the cosine similarity between positive sample pairs and minimize the cosine similarity between negative sample pairs, that is, to satisfy the following expression: ; (1) Based on this goal, the present invention adopts the text embedding scheme CoSENT (Cosine Sentence) with the following calculation formula: ; (2) ; (3) The above formula is the loss function for optimizing the cosine value, where formula (2) is a general contrast loss function used to compare the scores of positive sample pairs and negative sample pairs. , Represent the scores of negative sample pairs and positive sample pairs respectively. By minimizing this loss function, the score of the positive sample pair is Higher score than negative sample pairs ; Formula (3) is a loss function designed specifically for sentence similarity tasks. In sentence similarity tasks, we generally only care about the cosine similarity of two sentences. Specifically, cos( , ) represents the positive sample pair ( , ), and cosine similarity of , ) represents the negative sample pair ( , ). By minimizing this loss function, the cosine similarity of the positive sample pair is made higher than the cosine similarity of the negative sample pair; λ is a positive hyperparameter used to control the degree of influence of the difference in cosine similarity between the negative sample pair and the positive sample pair; Based on the generated text embedding vector, the cosine similarity method is used to calculate the similarity between questions to form a similarity matrix. Then, a hierarchical clustering algorithm is executed to merge or split clusters according to the similarity matrix, and a tree structure that reflects the relationship between clusters is constructed. The final similar feature question cluster division is determined based on the termination conditions and pruning strategies.

[0022] Step S2: Construct prompt word templates for different question types: Based on step S1, clusters of different question types are obtained, and random sampling is performed from each cluster using the Random function to ensure that the question samples selected in each cluster can fully demonstrate the semantic features and structural characteristics within the cluster. For the selected samples, excellent prompt words with significant guiding effects are constructed based on their domain knowledge, language logic, and potential semantic associations. These prompt words are designed to accurately trigger the large model to exert its optimal generation potential when processing the corresponding question categories. The expression of the excellent prompt word template is: Prompt=Instruct+Overall / Detailed Description+Question; (4) Among them, Prompt refers to the input sentence used to guide the large model to generate a specific answer; Instruct contains clear instructions for the model to perform the task; Overall Description proposes the theme that artificial intelligence should follow when answering a certain type of question; Detailed Description means that the specific task steps are detailed in a point-by-point manner, and Question is the specific question raised by the user. Figure 2 shown.

[0023] like Figure 3 As shown, the method for generating and fine-tuning candidate prompts of the present invention comprises the following steps: Step S3: Construct a dedicated dataset for fine-tuning the prompt evaluation model: Refer to the existing prompt word library and use the Qwen model to generate new prompt corpus to ensure that all question categories are covered. Provide a variety of candidate prompts for the large language model by systematically integrating question instances and prompt words; carefully score each set of question-prompt words in the prompt word library, considering the relevance, the ability to guide the model to generate the expected answer, and the comprehensive quality of the language and professional dimensions, so as to establish a high standard reference benchmark; The Few-shot learning strategy is adopted, and the Qwen model is used to simulate the manual scoring process. For the evaluation task of prompt words, the K-way and N-shot forms are adopted. K-way refers to dividing the questions into K different categories, each category represents a specific question type or subject area, and N-shot refers to selecting N examples in each category as training sets. These examples are manually annotated and scored data, which are used to guide the model to learn how to correctly evaluate the quality of prompt words. In this way, even with a limited sample size, the model can effectively learn the scoring criteria and apply them to new and unseen question-prompt word combinations.

[0024] Step S4: By using the QLoRA fine-tuning method to quantize the weights of the large language model, and using the low-rank adapter LoRA to reduce memory usage, the performance is maintained comparable to full 16-bit fine-tuning while having low memory requirements, so that the model can quickly adapt to new tasks under limited resources; by adjusting the low-rank matrix and model hyperparameters, the closeness of the prompt validity score to the manual annotation standard is optimized.

[0025] The specific steps of the QLoRA fine-tuning method are: First, the 4-bit normal floating point NF quantization data type is used for calculation. NF4 is a new data type that provides an information-theoretically optimal quantization scheme for normally distributed weights. QLoRA uses NF4 to quantize the weights of the pre-trained model, and then updates these quantized weights by fine-tuning the gradient of the adapter. Equations (5) and (6) are the weight quantization formula and weight dequantization formula, respectively: ; (5) ; (6) Equations (5) and (6) represent the conversion from 32-bit floating point numbers to 8-bit integers, where c is the quantization constant or quantization scale, and X Int8 Represents the quantized integer data, X FP32 Represents the original single-precision floating-point data, c FP32 represents a constant or scale factor used for quantization; In order to maximize the use of the limited bit width of the target data type, the conventional practice is to normalize the input data to adapt it to the target range. Through the normalization process, a FP32 format tensor can be effectively quantized into an Int8 tensor with a value range between [-127, 127], that is, equations (5) and (6); To further reduce memory usage, QLoRA uses a dual quantization method DQ to quantize constants. By using the constants of the first layer quantization as the input of the second layer quantization and using fewer bits to represent these constants, each parameter saves about 0.37 bits of memory on average. Use NVIDIA's unified memory feature to manage memory peaks by automatically paging between the CPU and GPU, avoiding out-of-memory errors when processing long mini-batches; Then, the low-rank adapter LoRA is used to optimize the loss function by fixing the gradient of the pre-trained model weights. In traditional neural networks, the forward propagation of each layer is expressed as a standard linear projection expression Y=XW. In the LoRA calculation formula, the linear projection is enhanced by introducing an additional decomposition projection sXL1L2. Therefore, the calculation formula is as follows (7): ; (7) In formula (7), the linear projection is enhanced by introducing an additional decomposition projection, X represents the input matrix, and the size is R b×h , where b is the batch size, h is the number of hidden units; W represents the original weight matrix with size R h×o , where o is the number of output features; L1 represents the first low-rank matrix, r is the size of the low-rank factor; L2 represents the second low-rank matrix; s is a scalar that controls the influence of the low-rank term; Combining the above components, QLoRA defines a LoRA adapter on the single linear layer of the quantized base model. The specific calculation formula is defined as follows: ; (8) ; (9) In equations (8) and (9), NF4 is selected as the data format of W, and FP8 is used as the data format of c2. In order to pursue higher quantization accuracy and save memory, W uses a 64-block size and c2 uses a 256-block size; X BF16 With Y BF16 are the input and output results represented by BF16-bit floating point format; c1 FP32 The first calibration factor expressed in FP32 single-precision floating point format, c2 k-bit is the second calibration factor expressed in k-bit format; W NF4 Represents a weight matrix using NF4 (NormalFloat 4-bit) format, L1 BF16 and L2 BF16 They are two LoRA adapter layers in BF16 format, W 4-bit is the k-bit format weight matrix, W BF16 is the final BF16 weight matrix; The doubleDequant function converts the storage data type to the calculation data type through two dequantization operations.

[0026] Step S5: Adaptive prompt word selection: When a new question is randomly selected, the present invention converts it into a high-dimensional vector form based on the text embedding method, so as to subsequently calculate its similarity using a hierarchical clustering algorithm; By using equations (1) and (3) to calculate the cosine similarity between the new question and the center of each cluster, the new question can be assigned to the cluster with the highest similarity, further narrowing the scope of the optimal prompt words that may correspond to the question; Finally, the fine-tuned dedicated prompt evaluation model is used to evaluate the adaptability of candidate prompt words to the new question; the input of the prompt evaluation model is the combination of the new question and each candidate prompt word, and the output is a score that indicates the matching degree of the prompt word to the question or the expected improvement effect. Based on the output of the evaluation model, the prompt word with the highest score is selected as the final adaptive prompt word. This prompt word is not only relevant to the content of the new question, but also enables the large model to provide more accurate and high-quality answers.

[0027] Step S6: Generate text response based on adaptive prompt words: The optimal prompt word is logically integrated with the corresponding question text to form a question statement containing clear prompt information, and it is passed to the downstream large model as a unified input to drive the downstream large model to generate high-quality text based on this input.

[0028] After the model generation is completed, the answers generated by the model are compared with the standard answers to the corresponding questions in the MMLU test set to evaluate the generation performance of the model for complex questions based on the adaptive prompt word technology. If the model answer performs well in multiple indicators, it means that it has achieved a high standard of accuracy when generating text answers using adaptive prompt words. On the contrary, if some indicators score low, it may indicate that the generation ability of the model in some aspects needs to be improved, or the matching degree between the prompt word and the question still needs to be optimized.

[0029] Unlike typical retrieval question-answering scenarios, the original large language model is difficult to be used directly to solve arithmetic and logical deduction problems. Therefore, the embodiment of the present invention focuses on the MMLU test set and complex problems in its STEM field. MMLU is a benchmark designed to evaluate the performance of language models on multiple tasks. There are 15,908 questions covering 57 different fields. The present invention divides the corpus of the data set into a training set and a test set according to a certain ratio, and automatically asks and answers them based on the Qwen series model to evaluate the pros and cons of the method.

[0030] The comparison results of the MMLU test set indicators are shown in Table 1 below:

[0031] Table 1 Comparison results of MMLU test set indicators The comparison results of the STEM field test set indicators are shown in Table 2:

[0032] Table 2 Comparison results of STEM field test set indicators The present invention also provides a large model text generation system based on adaptive prompt words, which specifically includes a server for performing clustering processing, building prompt words and data sets, and generating response texts, an adapter for performing data processing at the network layer, and a storage device for storing data processing models and text generation evaluation conclusions. The above-mentioned device is deployed before use, and when in use, the text generation program is executed through the evaluation model built into the server, and the generation performance is evaluated.

[0033] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A large model text generation method based on adaptive prompt words, characterized by: The steps for generating large model text are as follows: Step S1: Perform hierarchical clustering on the questions contained in the Large-Scale Multi-Task Language Understanding (MMLU) dataset, using text embedding and similarity calculation matrix to construct multiple question clusters containing similar features; Step S2: Randomly extract representative question samples from each question cluster, and construct excellent prompt words with significant guiding effects for each question based on domain knowledge and potential semantic associations; Step S3: Based on the constructed excellent prompt words, the Qwen series model is used to generate diverse and targeted candidate prompt words for various pre-divided question clusters, covering and adapting to the unique attributes of various input questions in the cluster, and constructing a prompt word library. Each question and prompt word pair in the prompt word library is manually scored, and scores are assigned based on the degree of association and guiding ability. The few-shot learning strategy is used to guide the language model to simulate manual scoring, and finally a dedicated dataset is constructed for fine-tuning the prompt evaluation model. Step S4: Use the QLoRA fine-tuning method to adjust the parameters of the prompt evaluation model, quantize the weights of the pre-trained large model, use the low-rank adapter LoRA to reduce memory usage, avoid accuracy compromise by adding adapters at each network layer, and use the Adam optimization algorithm and early stopping strategy to ensure that the model achieves optimal performance within a limited number of training steps; Step S5: Classify the questions according to the clusters they belong to, send the questions and the candidate prompt sets in the corresponding clusters into the evaluation model, and select the prompt word with the highest score as the optimal prompt word for the specific question; Step S6: Based on the selected optimal prompt words, guide the language model to generate high-quality response text for specific questions, and compare it with the standard answers in the MMLU test set to evaluate the generation performance of the model for complex questions based on the optimal prompt word selection method.

2. The method for generating large model text based on adaptive prompt words according to claim 1, characterized in that: The specific method of constructing similar feature problem clusters in step S1 is: Based on the principle of hierarchical decomposition, data points are recursively divided into smaller and smaller subsets until the preset termination condition is reached, thus realizing the step-by-step aggregation of data points.

3. The method for generating large model text based on adaptive prompt words according to claim 2, characterized in that: The specific method to achieve the step-by-step aggregation of data points is: Based on the text embedding method, each question in the MMLU dataset is converted into a high-dimensional vector representation, so that the generated vector can effectively capture the semantic association and contextual information of the question; Given a set of positive sample pairs Ω pos And the set of negative sample pairs Ω neg ,definition ∈Ω pos Representing two sentences of positive sample pairs, the corresponding vectors are and ,definition ∈Ω neg Representing two sentences of negative sample pairs, the corresponding vectors are and ; The goal is to maximize the cosine similarity between positive sample pairs and minimize the cosine similarity between negative sample pairs, that is, to satisfy: ; To achieve this goal, the text embedding scheme CoSENT is used to optimize the loss function L of the cos value. uni , the calculation formula is: ; ; Among them, λ is a positive hyperparameter used to control the degree of influence of the difference in cosine similarity between negative sample pairs and positive sample pairs; , Represent the scores of negative sample pairs and positive sample pairs respectively; Based on the generated text embedding vector, the cosine similarity method is used to calculate the similarity between questions to form a similarity matrix. The hierarchical clustering algorithm is executed to merge or split clusters according to the similarity matrix, and a tree structure that reflects the relationship between clusters is constructed. The final similar feature question cluster division is determined based on the termination conditions and pruning strategies.

4. The method for generating large model text based on adaptive prompt words according to claim 1, characterized in that: The specific method of constructing excellent prompt words in step S2 is: Based on the different types of question clusters obtained in step S1, the Random function is used to randomly sample from each question cluster to ensure that the question samples selected in each question cluster can fully reflect the semantic features and structural characteristics of the question cluster, and to build a prompt word template that can accurately guide the large model to generate high-quality text for different question types.

5. The method for generating large model text based on adaptive prompt words according to claim 4, characterized in that: The specific method of constructing prompt word templates for different question types is: For the selected samples, based on their domain knowledge, language logic and potential semantic associations, excellent prompt words with significant guiding effects are constructed. The expression for constructing excellent prompt word templates is: Prompt=Instruct+Overall / Detailed Description+Question; Among them, Prompt refers to the input sentence used to guide the large model to generate a specific answer; Instruct contains clear instructions for the model to perform tasks; Overall Description proposes the theme that artificial intelligence should follow when answering certain types of questions; Detailed Description means that the specific task steps are described in detail in a point-by-point manner, and Question is the specific question raised by the user.

6. The method for generating large model text based on adaptive prompt words according to claim 1, characterized in that: The specific steps of constructing a dedicated dataset for the fine-tuning prompt evaluation model in step S3 are: Based on the divided clusters and the corresponding excellent prompt words, the word library and fine-tuning dataset are constructed. Referring to the constructed excellent prompt word library, the Qwen model is used to generate targeted excellent prompt words for various pre-divided question clusters, covering the unique attributes of various input questions in the cluster, and then the generated questions, candidate prompt words and corresponding answers are integrated to finally construct a candidate prompt word library; Each pair of question-prompt word combination in the prompt word library is evaluated and scored based on the relevance between the question and the prompt word, the ability to guide the model to generate the expected answer, and the comprehensive quality of the language and professional dimensions; A few-shot learning strategy is adopted, and the Qwen model is used to simulate the manual scoring process. For the prompt word evaluation task, the K-way and N-shot forms are adopted. K-way refers to dividing the questions into K different categories, each category represents a specific question type or subject area, and N-shot refers to selecting N examples in each category as training sets. These examples are manually annotated data with scores, which are used to guide the model to learn how to correctly evaluate the quality of prompt words.

7. The method for generating large model text based on adaptive prompt words according to claim 1, characterized in that: The specific steps of the QLoRA fine-tuning method used in step S4 are: The 4-bit normal floating point NF quantization data type is used for calculation. The quantized weights are updated by fine-tuning the gradient of the adapter. The update adopts the weight quantization and weight dequantization processing methods. The corresponding calculation formulas are: ; ; In the formula, the 32-bit floating point number is converted to an 8-bit integer, c is the quantization constant or quantization scale, and X Int8 Represents the quantized integer data, X FP32 Represents the original single-precision floating-point data, c FP32 represents a constant or scale factor used for quantization; Then, the low-rank adapter LoRA is used to optimize the loss function by fixing the gradient of the pre-trained model weights. In traditional neural networks, the forward propagation of each layer is expressed as a standard linear projection expression Y=XW. In the LoRA calculation formula, the linear projection is enhanced by introducing an additional decomposition projection sXL1L2, so the calculation formula is: ; Where X represents the input matrix, and its size is R b×h , where b is the batch size, h is the number of hidden units; W represents the original weight matrix with size R h×o , where o is the number of output features; L1 represents the first low-rank matrix, r is the size of the low-rank factor; L2 represents the second low-rank matrix; s is a scalar that controls the influence of the low-rank term; Combining the above components, QLoRA defines a LoRA adapter on the single linear layer of the quantized base model. The calculation formula used by the LoRA adapter to process data is: ; ; In the formula, NF4 is selected as the data format of W, FP8 is used as the data format of c2, 64 blocks are used for W, and 256 blocks are used for c2; X BF16 With Y BF16 are the input and output results represented by BF16-bit floating point format; c1 FP32 The first calibration factor expressed in FP32 single-precision floating point format, c2 k-bit is the second calibration factor expressed in k-bit format; W NF4 Indicates the weight matrix using NF4 format, L1 BF16 and L2 BF16 They are two LoRA adapter layers in BF16 format, W 4-bit is the k-bit format weight matrix, W BF16 is the final BF16 weight matrix; The doubleDequant function converts the storage data type to the calculation data type through two dequantization operations.

8. A generation system for realizing the large model text generation method based on adaptive prompt words as described in claim 1, characterized in that: It includes a server for performing clustering processing, building prompt words and data sets, and generating response texts, an adapter for performing data processing at the network layer, and a storage device for storing data processing models and text generation evaluation conclusions.

Citation Information

Cited By

  • LoRA-based large model task optimization adjustment method and system

    CN120106165A

  • AI model performance evaluation method and system based on big data analysis

    CN120123714A

  • An AI model performance evaluation method and system based on big data analysis

    CN120123714B

  • Text factuality proofreading method and system, electronic equipment and medium

    CN120278145A

  • User question intention analysis method under AI platform

    CN120951095A