Text rewriting cue word generation method and device, electronic equipment and storage medium
By constructing text pairs and calculating matching degrees to determine the rules for target prompt words, the problem of low accuracy in the generation of prompt words in the prior art is solved, and higher accuracy and adaptability are achieved.
Patent Information
- Application Number
- CN202411487451.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-18
AI Technical Summary
In the prior art, the accuracy of the prompt word generation results is low and cannot effectively adapt to different application scenarios, resulting in a large difference between the generated prompt word and the actual needs.
By obtaining the initial rewrite text corresponding to the original text, constructing text pairs and determining prompt labels, calculating the matching degree between the initial prompt word and the text pair, determining the rules for target prompt words based on the matching degree, including based on the initial prompt word and prompt labels, or Based on prompt tags and preset prompt words.
It improves the accuracy and relevance of prompt word generation, ensuring that the target prompt word not only matches the text pair, but also summarizes the key information in the text pair to adapt to the needs of different application scenarios.
Smart Images

Figure CN119476213A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text rewriting, and in particular to a method, device, electronic device and storage medium for generating prompt words for text rewriting. Background Art
[0002] Text rewriting refers to the process of restating an original text content using different wording, sentence patterns or structures. The rewritten text retains the original meaning but the language expression is different. Text rewriting can be used for content optimization, simplification of complex content, translation and localization. The demand for text rewriting is increasing in scenarios such as news reporting, marketing advertising, chatbots and data enhancement. This has led to a gradual increase in the requirements for text rewriting. In order to meet the needs, large language models are used for text rewriting.
[0003] The rewriting process of the large language model relies on high-quality prompt words, but the existing prompt word generation results are quite different from the actual needs, and the corresponding prompt words cannot be generated based on different application scenarios, resulting in low accuracy of the prompt word generation results of the existing technology. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a method, device, electronic device and storage medium for generating prompt words for text rewriting, so as to solve the problem of low accuracy of prompt word generation results in the prior art.
[0005] In a first aspect of an embodiment of the present application, a method for generating prompt words for text rewriting is provided, comprising:
[0006] The method comprises the following steps: obtaining an initial rewritten text corresponding to the original text; constructing a text pair according to the original text and the initial rewritten text, and determining a prompt label corresponding to the text pair; determining an initial prompt word according to the text pair, and calculating a matching degree between the initial prompt word and the text pair; and obtaining a determination rule of a target prompt word based on the matching degree, wherein the determination rule includes determining a target prompt word based on the initial prompt word and the prompt label, and determining a target prompt word based on the prompt label and a preset prompt word.
[0007] According to a second aspect of an embodiment of the present application, a device for generating prompt words for text rewriting is provided, comprising: an acquisition module, configured to acquire an initial rewritten text corresponding to an original text; a first determination module, configured to construct a text pair according to the original text and the initial rewritten text, and to determine a prompt label corresponding to the text pair; a second determination module, configured to determine an initial prompt word according to the text pair, and to calculate a matching degree between the initial prompt word and the text pair; a third determination module, configured to obtain a determination rule for a target prompt word based on the matching degree, wherein the determination rule comprises determining a target prompt word based on the initial prompt word and the prompt label, and determining a target prompt word based on the prompt label and a preset prompt word.
[0008] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0009] According to a fourth aspect of an embodiment of the present application, a storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0010] The beneficial effects of the embodiments of the present application are:
[0011] By obtaining the initial rewritten text corresponding to the original text, a text pair for generating the initial prompt word can be obtained, and the corresponding prompt tag is determined based on the text pair. The tag can represent a word or phrase used to summarize or describe the important content or keywords in the text pair. After obtaining the initial prompt word, the model is used to calculate the matching degree between the initial prompt word and the text pair. According to the calculated matching degree, the rule for generating the final target prompt word is determined, that is, if the matching degree is high, the final target prompt word is determined based on the initial prompt word and the prompt tag, and if the matching degree is low, the target prompt word is determined based on the prompt tag and the preset prompt word template. In this way, the quality of the generated initial prompt word can be dynamically evaluated by calculating the matching degree to improve the accuracy and relevance of the final generated target prompt word, and the generated prompt word can be better aligned with the core content of the text pair by introducing the prompt tag, ensuring that the final target prompt word not only matches the text pair, but also can summarize the key information in the text pair, so that not only the flexibility of generating the target prompt word is maintained, but also the accuracy of the target prompt word is ensured. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 It is a flowchart of a method for generating prompt words for text rewriting provided in an embodiment of the present application;
[0014] Figure 2 It is a flowchart of another method for generating prompt words for text rewriting provided by an embodiment of the present application;
[0015] Figure 3 It is a flowchart of another method for generating prompt words for text rewriting provided in an embodiment of the present application;
[0016] Figure 4It is a structural schematic diagram of a prompt word generating device for text rewriting provided by an embodiment of the present application;
[0017] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0019] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0020] In addition, it should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "includes..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0021] Text rewriting can be understood as rewriting the original text in scenes such as news reports, marketing advertisements, chatbots, and data enhancement so that the original text meets the needs of the target audience. Text rewriting can be based on emotional expression, text description, or different styles corresponding to the question type. The effect of text rewriting often depends on the guidance of high-quality rewriting prompt words to the large language model. However, the prompt words generated in the prior art are quite different from the actual needs, resulting in the generated text not meeting expectations, which is mainly reflected in the lack of accuracy of prompt word generation, poor adaptability, inefficient prompt word verification, single prompt words, and lack of label information utilization. Therefore, the present invention fine-tunes the large language model to predict complete prompt words, combines the label prediction model with prompt words that meet specific styles and contexts to enhance adaptability, quickly filters wrong prompt words through the gating model, improves verification efficiency, and generates diversified prompt words by combining the label prediction model to meet different needs.
[0022] A method and device for generating prompt words for text rewriting according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0023] Figure 1 Schematic diagram of a method for generating prompt words for text rewriting provided in an embodiment of the present application. Figure 1 As shown, the prompt word generation method for text rewriting includes:
[0024] S101, obtaining an initial rewritten text corresponding to the original text;
[0025] S102, constructing a text pair according to the original text and the initial rewritten text, and determining a prompt tag corresponding to the text pair;
[0026] S103, determining an initial prompt word according to the text pair, and calculating a matching degree between the initial prompt word and the text pair;
[0027] S104, based on the matching degree, obtaining a determination rule of the target prompt word, wherein the determination rule includes determining the target prompt word based on the initial prompt word and the prompt label, and determining the target prompt word based on the prompt label and the preset prompt word.
[0028] Specifically, first, an initial rewritten text can be obtained based on the input original text and the rewriting requirements, a text pair can be formed based on the original text and the initial rewritten text, and a prompt label and an initial prompt word can be determined based on the text pair, wherein the initial rewritten text can represent the initial rewritten text obtained by the text rewriting system after a preliminary rewriting of the original text and the user's rewriting intention.
[0029] Among them, the text rewriting system can be understood as a system including a prompt word optimization network, which uses the target prompt words generated by the prompt word optimization network based on the text rewriting system to rewrite the original text to obtain a rewritten text. It should be noted that the text rewriting system can be used to rewrite original texts with different requirements, such as rewriting based on different rewriting requirements of the original text and user input; it can also be used to rewrite original texts with specific requirements, such as a poetry rewriting system, which is used to rewrite the input original text into a rewritten text with news features.
[0030] Furthermore, the text pair can be input into the prompt word optimization network for processing to obtain the prompt label and the initial prompt word. The prompt word optimization network may include a mean prompt model, a prompt word generation model, a gating model and a label model. The prompt word generation model can be used to process the text pair to generate the initial prompt word, and the gating model can filter the initial prompt word, that is, the initial prompt word that meets the requirements (for example, the matching degree with the text pair reaches a preset value) is retained and merged with the prompt label to generate the target prompt word, and the initial prompt word that does not meet the requirements (for example, the matching degree with the text pair does not reach the preset value) is deleted, and the prompt label is merged with the preset prompt word to generate the target prompt word, wherein the mean prompt model can be understood as a model for generating the preset prompt word.
[0031] According to the solution provided in the above embodiment, an initial prompt word and a prompt label are generated through a text pair, and then a target prompt word is determined according to a selection rule based on the matching degree between the initial prompt word and the text pair. This not only increases the robustness of the system but also improves the accuracy and relevance of the target prompt word.
[0032] In some embodiments, calculating the degree of match between the initial prompt word and the text pair includes: calculating the degree of match between the initial prompt word and the text pair through a gating model, the gating model representing a model for calculating the degree of match and filtering the initial prompt word according to the degree of match; if the degree of match is greater than a preset value, retaining the initial prompt word; if the degree of match is not greater than the preset value, not retaining the initial prompt word.
[0033] Specifically, a gating model can be used to calculate the match between the initial prompt word and the text pair. The gating model can be a fine-tuned model for evaluating the match and relevance between the initial prompt word and the corresponding text pair. By analyzing the relationship between the initial prompt word, the original text, and the rewritten text, a matching model is given. For example, the MistralForSequenceClassification model can be used as a gating model for training to learn to distinguish between reasonable and unreasonable prompt word predictions.
[0034] Furthermore, when the gating model calculates that the matching degree between the initial prompt word and the text pair is higher than a preset value (eg, 0.5), the initial prompt word and the text pair are considered to be the original content, and thus the prompt word is not retained.
[0035] According to the solution provided in the above embodiment, the matching degree is accurately calculated by the gating model, which can effectively filter out irrelevant or inaccurate initial prompt words, ensuring that the retained prompt words are highly consistent with the content of the team. Such a screening mechanism can help the model improve the accuracy of generating target prompt words.
[0036] In some embodiments, before obtaining the initial rewritten text corresponding to the original text, it also includes: obtaining a data set, the data set includes sample original text, sample rewritten text and sample prompt words; using the data set to train an initial prompt word generation model to obtain a prompt word generation model, and the prompt word generation model is used to determine the initial prompt word according to the text pair; constructing a classification data set based on the data set, and using the classification data set to fine-tune the initial gating model to obtain the gating model; constructing a label data set based on the data set, and using the label data set to fine-tune the initial label generation model to obtain a label generation model, and the label generation model is used to determine the prompt label according to the text pair.
[0037] Specifically, in the prompt word generation process, the prompt word generation model can be used to process the text pair to obtain the initial prompt word, the gating model can be used to calculate the matching degree of the initial prompt word, and the label generation model can be used to process the text pair to obtain the prompt label corresponding to the text pair. Before performing the prompt word optimization task, each model can also be trained and fine-tuned to support the subsequent initial prompt word generation and screening process.
[0038] Furthermore, a data set containing samples can be first obtained, and the data set can include sample original text, sample rewritten text and sample prompt words, wherein the sample original text can represent the original text data, that is, the content that needs to be rewritten, the sample rewritten text can represent the rewritten version of the corresponding sample original text, and the sample prompt words can represent the prompt words associated with the text pair, which are used to guide or summarize the text content.
[0039] Using the data set, a model for generating initial prompt words can be trained to obtain a prompt word generation model, so that it can generate preliminary prompt words based on text pairs.
[0040] Furthermore, a classification dataset can be constructed based on the dataset to fine-tune the initial gating model to obtain a gating model, so that the gating model can distinguish whether the initial prompt words are reasonable and evaluate the quality of the initial prompt words by matching, thus ensuring that the gating model can accurately filter out inappropriate initial prompt words.
[0041] It is also possible to construct a label dataset based on the dataset, and use the label dataset to fine-tune the initial label generation model to obtain a label generation model, so that the label generation model can generate a prompt label that matches the text pair, ensuring that the prompt label can accurately summarize the text content.
[0042] According to the solution provided in the above embodiment, the corresponding model can be obtained through early model fine-tuning and training, so that the entire prompt word generation process can be more accurate and efficient, and can flexibly cope with different data situations and generation tasks.
[0043] In some embodiments, the initial prompt word generation model is trained using the data set to obtain the prompt word generation model, including:
[0044] Formatting the sample original text, the sample rewritten text and the sample prompt word to obtain a training pair in a target format, wherein the training pair in the target format includes an input string and an output string in the target format, wherein the input string includes the sample original text and the sample rewritten text corresponding to each other, and the output string represents the sample prompt word corresponding to the input string;
[0045] Using low-rank adaptation technology, the initial prompt word generation model is fine-tuned through training pairs in the target format to obtain the prompt word generation model.
[0046] Specifically, the data set can be converted into input-output pairs suitable for model training (i.e., including input strings and output strings), that is, the sample original text, sample rewritten text, and sample prompt words can be formatted to obtain a standard training data structure, where the input string can be composed of the sample original text and the corresponding sample rewritten text, and the output string can represent the sample prompt words corresponding to the input string, which can represent the target output that the model should learn to generate.
[0047] Furthermore, the formatted input-output pairs can be used to fine-tune the initial prompt word generation model (such as the initial mistral model) through a standard language model training method to obtain a prompt word generation model. The initial prompt word generation model can be fine-tuned using low-rank adaptation technology (LoRA), where LoRA can be applied to the key weight matrix of the model to reduce the amount of parameters that need to be adjusted during fine-tuning, thereby improving the training efficiency of the model and allowing the model to better adapt to new tasks while retaining its original capabilities.
[0048] According to the solution provided in the above embodiment, the initial prompt word generation model is fine-tuned by LoRA technology to obtain a prompt word generation model, which can reduce the computational cost and time of model fine-tuning, and also ensure the generation quality of the prompt word generation model. The formatted input and output pairs are used for training, so that the prompt word generation model can clearly learn the relationship between the input text and the prompt word, thereby helping the model to generate accurate target prompt words.
[0049] In some embodiments, a classification data set is constructed based on a data set, and an initial gating model is fine-tuned using the classification data set to obtain a gating model, including: constructing a classification data set based on the data set, the classification data set including positive samples, simple negative samples, and difficult negative samples; allocating the classification data set according to a preset time, fine-tuning the initial gating model to obtain the gating model; wherein the preset time allocation represents the time allocation for training the initial gating model for positive samples, simple negative samples, and difficult negative samples, respectively.
[0050] Specifically, first, a classification data set can be constructed from the data set for training the initial gating model to obtain the gating model, wherein the classification data set may include positive samples, simple negative samples, and difficult negative samples, and the positive sample may represent a sample consisting of an original text and its corresponding correct prompt word and a rewritten text, and may represent an ideal sample prompt word and sample text pair; a simple negative sample may represent a sample with a weak correlation between a sample prompt word and a sample text pair; a difficult negative sample may be a negative sample constructed by finding a prompt word that is closer to the positive sample prompt word in the T5 embedding space, and a difficult negative sample is semantically closer to the positive sample, but is actually an incorrect prompt word, wherein the positive sample, the simple negative sample, and the difficult negative sample may be generated based on random numbers, that is, a random number of 0-1 is generated, and the random numbers of 0-0.4 are integrated into positive samples, the random numbers of 0.4-0.6 are integrated into simple negative samples, and the random numbers of 0.6-1 are integrated into difficult negative samples, to obtain a classification data set for training the gating model.
[0051] Furthermore, the MistralForSequenceClassification model can be selected as the initial gating model for fine-tuning, and the LoRA method can also be used for fine-tuning, so that the initial gating model can learn how to judge the matching degree between the initial prompt word and the text pair through the classification data set, and output a probability value between 0 and 1. This probability value can reflect whether the initial prompt word is a suitable prompt for the text pair.
[0052] Furthermore, when fine-tuning the initial gating model using the classification dataset, the positive samples, simple negative samples, and difficult negative samples can be trained according to the time allocation. For example, 40% of the training time is used for correct positive samples, 20% of the training time is used for simple negative samples, and 40% of the training time is used for training the initial gating model, so as to obtain a gating model that can accurately distinguish the rationality of the initial prompt words.
[0053] In the solution provided in the above embodiment, the initial gating model is trained by using positive samples, simple negative samples and difficult negative samples through the LoRA technology to obtain the gating model, which not only enables the gating model to better filter out inappropriate initial prompt words, but also makes the model training process efficient and low-cost.
[0054] In some embodiments, a label data set is constructed based on a data set, and an initial label generation model is fine-tuned using the label data set to obtain a label generation model, including: labeling corresponding sample prompt labels for sample original text and sample rewritten text to obtain a label data set, the label data set includes the sample original text, the sample rewritten text and the sample prompt labels, and the label data set is divided into a label training set and a label verification set; the initial label generation model is fine-tuned based on the label training set to obtain a fine-tuned initial label generation model; the fine-tuned initial label generation model is evaluated based on the label verification set, and if the evaluation result is qualified, the label generation model is obtained, and the qualified evaluation result indicates that the similarity between the predicted prompt label and the sample prompt label is greater than a preset threshold, and the predicted prompt label indicates the processing result of the fine-tuned initial label generation model on the sample original text and the sample rewritten text.
[0055] Specifically, a labeled dataset can be constructed based on the dataset, that is, sample original text and sample rewritten text can be extracted from the dataset, and the sample original text and sample rewritten text can be annotated based on manual or algorithmic methods to obtain sample prompt word labels. In this way, a labeled dataset can be obtained, which includes sample original text, sample rewritten text and sample prompt word labels.
[0056] Furthermore, the label data set can be divided into a label training set and a label verification set. The label training set is used to fine-tune the initial label generation model (for example, the MistralForCausalLM model) to obtain the fine-tuned initial label generation model, and the sample label verification set is used to verify the fine-tuned initial label generation model. If the model performs well on the verification set, that is, the evaluation result is qualified, it means that the model training is complete and the label generation model is obtained.
[0057] It should be noted that a qualified evaluation result can indicate that the input sample original text and the sample rewritten text can obtain the corresponding sample prompt labels in the verification set, that is, the output prediction prompt label is consistent with the corresponding sample prompt label. Of course, for the flexibility of model training, the prediction prompt label of the verification output can be a prompt label whose similarity with the sample prompt label is greater than a preset threshold (for example, 0.7), and the similarity can be the semantic similarity between the two.
[0058] According to the solution provided in the above embodiment, the initial label generation model is fine-tuned and evaluated by constructing a label data set, so that the label generation model can generate prompt labels that are highly relevant to the original text and the rewritten text, so that in the text rewriting task process, accurate prompt word labels can be generated to assist the system in generating accurate target prompt words.
[0059] In some embodiments, determining the target prompt word based on the prompt label and the preset prompt word includes: fusing the prompt label and the preset prompt word to obtain the target prompt word; wherein the preset prompt word is obtained by performing clustering and beam search processing on the data set.
[0060] Specifically, when the initial prompt word does not meet the preset requirements, the preset prompt word can be merged with the prompt label to obtain the target prompt word.
[0061] It should be noted that the preset prompt words can represent a basic structure and can be obtained based on the data set. During the model training process, the data set can be clustered, that is, the data set can be clustered based on the sample prompt words for similarity, and text grouping of similar sample prompt words can be obtained to capture the patterns and features between similar texts. Afterwards, in each cluster, the beam search algorithm is applied to find the best prompt word combination in each cluster, and the best prompt word combination of each cluster generates an initial mean prompt template, which is the preset prompt word.
[0062] In this way, when the initial prompt word is judged to be invalid, the prompt label can be merged with the preset prompt word. The fusion method can be to insert the prompt label into the specific position of the preset prompt word, or to adjust the structure and content of the preset prompt word according to the prompt label. The fusion of the initial prompt word and the prompt label is similar. There is no limitation here. Of course, a large language model can also be used to adaptively fuse the prompt label and the preset prompt word, or the prompt label with the initial prompt word.
[0063] According to the solution provided in the above embodiment, by performing beam search and clustering on the data set, common information in the data set is obtained to form an optimized preset prompt word, and the prompt label is merged with the preset prompt word so that the finally generated target prompt word can better fit the specific text content.
[0064] Figure 2This is a flow chart of another method for generating prompt words for text rewriting provided by an embodiment of the present application. Figure 2 The embodiments of the present application are described.
[0065] First, we can obtain public data from public data sets or data sets generated by large language models, and then clean, filter and deduplicate the public data to obtain a data set. The data set includes original text (i.e., the sample original text in the training process), rewritten text (i.e., the sample rewritten text in the training process) and rewrite prompt words (i.e., the sample prompt words in the training process).
[0066] The prompt generation model is trained and saved using the dataset to obtain the prompt word generation model mentioned above, and a classification dataset is constructed from the dataset based on random numbers ranging from 0 to 1 to obtain positive samples, simple negative samples, and difficult negative samples. The obtained classification dataset is used to train and save the gating model.
[0067] The data set can also be used to train the label generation model. In the process of building the label data set, the large model can be used to generate labels corresponding to the sample original text and the sample rewritten text. The label data set is then used to train and evaluate the initial label generation model to obtain the label generation model and save it.
[0068] Similarly, in the process of using the data set to train each model, a mean prompt, that is, a preset prompt word, can also be generated based on the data set, and the preset prompt word can be saved for subsequent generation of a target prompt word.
[0069] In this way, various models can be obtained through training, so that the target prompt word generation process can be more accurate and efficient.
[0070] Figure 3 This is a flow chart of another method for generating prompt words for text rewriting provided in an embodiment of the present application. Figure 3 The embodiments of the present application are further described.
[0071] First, the original text (i.e., original text) and the initial rewritten text (i.e., rewritten text) are obtained to obtain a text pair, and the preset prompt word (i.e., mean prompt) and the prompt word generation model are loaded. The prompt word generation model is used to process the original text and the initial rewritten text to obtain the initial prompt word. Then, the gating model is used to judge the rationality of the initial prompt word, that is, the matching degree between the initial prompt word and the text pair is calculated. If the matching degree is greater than 0.5, the initial prompt word can be regarded as qualified, and the initial prompt word is fused with the prompt label to obtain the target prompt word. If the matching degree is not greater than 0.5, the initial prompt word can be regarded as unqualified, and the target prompt word is not generated based on the initial prompt word, but the preset prompt word and the prompt label are fused to obtain the target prompt word.
[0072] According to the solution provided by the above embodiment, the rationality of the initial prompt word can be verified by calculating the matching degree between the initial prompt word and the text pair, which helps the model to generate target prompt words that are more consistent with the text content, thereby improving the output quality of the text rewriting model. By adaptively selecting different fusion methods to generate the target prompt word based on the matching degree of the initial prompt word, it is possible to avoid affecting the output quality of the target prompt word due to unqualified initial prompt words, thereby improving the flexibility and accuracy of the target prompt word generation results.
[0073] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0074] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0075] Figure 4 Schematic diagram of a prompt word generation device for text rewriting provided by an embodiment of the present application. Figure 4 As shown, the prompt word generating device for text rewriting includes:
[0076] An acquisition module 401 is configured to acquire an initial rewritten text corresponding to the original text;
[0077] A first determination module 402 is configured to construct a text pair according to the original text and the initial rewritten text, and determine a prompt tag corresponding to the text pair;
[0078] The second determination module 403 is configured to determine the initial prompt word according to the text pair and calculate the matching degree between the initial prompt word and the text pair;
[0079] The third determination module 404 is configured to obtain a determination rule of the target prompt word based on the matching degree, wherein the determination rule includes determining the target prompt word based on the initial prompt word and the prompt label, and determining the target prompt word based on the prompt label and the preset prompt word.
[0080] In some embodiments, the second determination module 403 is specifically used to calculate the matching degree between the initial prompt word and the text pair through a gating model, and the gating model represents a model used to calculate the matching degree and filter the initial prompt word according to the matching degree; if the matching degree is greater than a preset value, the initial prompt word is retained; if the matching degree is not greater than the preset value, the initial prompt word is not retained.
[0081] In some embodiments, the acquisition module 401 is specifically used to acquire a data set, which includes a sample original text, a sample rewritten text, and a sample prompt word; use the data set to train an initial prompt word generation model to obtain a prompt word generation model, and the prompt word generation model is used to determine the initial prompt word according to the text pair; construct a classification data set based on the data set, and use the classification data set to fine-tune the initial gating model to obtain a gating model; construct a label data set based on the data set, and use the label data set to fine-tune the initial label generation model to obtain a label generation model, and the label generation model is used to determine the prompt label according to the text pair.
[0082] In some embodiments, the acquisition module 401 is specifically used to format the sample original text, the sample rewritten text and the sample prompt words to obtain a training pair in a target format, the training pair in the target format includes an input string and an output string in a target format, the input string includes the corresponding sample original text and the sample rewritten text, and the output string represents the sample prompt words corresponding to the input string; using low-rank adaptation technology, the initial prompt word generation model is fine-tuned through the training pair in the target format to obtain a prompt word generation model.
[0083] In some embodiments, the acquisition module 401 is specifically used to construct a classification data set based on the data set, and the classification data set includes positive samples, simple negative samples, and difficult negative samples; the classification data set is fine-tuned according to a preset time allocation to obtain a gating model; wherein the preset time allocation represents the time allocation for training the initial gating model for positive samples, simple negative samples, and difficult negative samples, respectively.
[0084] In some embodiments, the acquisition module 401 is specifically used to annotate the sample original text and the sample rewritten text with corresponding sample prompt labels to obtain a label data set, which includes the sample original text, the sample rewritten text and the sample prompt labels, and divides the label data set into a label training set and a label verification set; fine-tuning the initial label generation model based on the label training set to obtain a fine-tuned initial label generation model; evaluating the fine-tuned initial label generation model based on the label verification set, and if the evaluation result is qualified, the label generation model is obtained, and the qualified evaluation result indicates that the similarity between the predicted prompt label and the sample prompt label is greater than a preset threshold, and the predicted prompt label indicates the processing result of the fine-tuned initial label generation model on the sample original text and the sample rewritten text.
[0085] In some embodiments, the third determination module 404 is specifically used to fuse the prompt label and the preset prompt word to obtain the target prompt word; wherein the preset prompt word is obtained by performing clustering and beam search processing on the data set.
[0086] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0087] Figure 5 Schematic diagram of an electronic device 5 provided in an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501. When the processor 501 executes the computer program 503, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 501 executes the computer program 503, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0088] The electronic device 5 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 5 may include, but is not limited to, a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5 The electronic device 5 is merely an example and does not limit the electronic device 5 , and may include more or less components than those shown in the figure, or different components.
[0089] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0090] The memory 502 may be an internal storage unit of the electronic device 5, for example, a hard disk or memory of the electronic device 5. The memory 502 may also be an external storage device of the electronic device 5, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. The memory 502 may also include both an internal storage unit of the electronic device 5 and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the electronic device.
[0091] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0092] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0093] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for generating prompt words for text rewriting, characterized in that: include: Get the initial rewritten text corresponding to the original text; constructing a text pair according to the original text and the initial rewritten text, and determining a prompt tag corresponding to the text pair; Determine an initial prompt word according to the text pair, and calculate a matching degree between the initial prompt word and the text pair; Based on the matching degree, a determination rule of the target prompt word is obtained, wherein the determination rule includes determining the target prompt word based on the initial prompt word and the prompt label, and determining the target prompt word based on the prompt label and a preset prompt word.
2. The method according to claim 1, characterized in that The calculating the matching degree between the initial prompt word and the text pair includes: Calculating the degree of match between the initial prompt word and the text pair through a gating model, wherein the gating model represents a model for calculating the degree of match and filtering the initial prompt word according to the degree of match; If the matching degree is greater than a preset value, the initial prompt word is retained; If the matching degree is not greater than the preset value, the initial prompt word is not retained.
3. The method according to claim 2, characterized in that Before obtaining the initial rewritten text corresponding to the original text, the method further includes: Acquire a data set, the data set comprising a sample original text, a sample rewritten text, and a sample prompt word; Using the data set to train an initial prompt word generation model to obtain a prompt word generation model, wherein the prompt word generation model is used to determine the initial prompt word according to the text pair; constructing a classification data set based on the data set, and using the classification data set to fine-tune the initial gating model to obtain the gating model; A label data set is constructed based on the data set, and an initial label generation model is fine-tuned using the label data set to obtain a label generation model, wherein the label generation model is used to determine the prompt label according to the text pair.
4. The method according to claim 3, characterized in that The method of using the data set to train the initial prompt word generation model to obtain the prompt word generation model includes: Formatting the sample original text, the sample rewritten text, and the sample prompt word to obtain a training pair in a target format, wherein the training pair in the target format includes an input string and an output string in a target format, wherein the input string includes the sample original text and the sample rewritten text corresponding to each other, and the output string represents the sample prompt word corresponding to the input string; The initial prompt word generation model is fine-tuned by using low-rank adaptation technology through training pairs in the target format to obtain the prompt word generation model.
5. The method according to claim 3, characterized in that: The step of constructing a classification data set based on the data set, and fine-tuning an initial gating model using the classification data set to obtain the gating model comprises: Constructing the classification data set based on the data set, wherein the classification data set includes positive samples, simple negative samples, and difficult negative samples; Allocating the classification data set according to a preset time, and fine-tuning the initial gating model to obtain the gating model; The preset time allocation represents the time allocation for training the initial gating model respectively for the positive samples, the simple negative samples and the difficult negative samples.
6. The method according to claim 3, characterized in that The step of constructing a label data set based on the data set and fine-tuning an initial label generation model using the label data set to obtain a label generation model includes: Annotating the sample original text and the sample rewritten text with corresponding sample prompt labels to obtain the label data set, wherein the label data set includes the sample original text, the sample rewritten text and the sample prompt label, and dividing the label data set into a label training set and a label verification set; Fine-tuning the initial label generation model based on the label training set to obtain a fine-tuned initial label generation model; The fine-tuned initial label generation model is evaluated based on the label verification set. If the evaluation result is qualified, the label generation model is obtained. The qualified evaluation result indicates that the similarity between the predicted prompt label and the sample prompt label is greater than a preset threshold. The predicted prompt label indicates the processing result of the fine-tuned initial label generation model on the sample original text and the sample rewritten text.
7. The method according to claim 3, characterized in that The determining the target prompt word based on the prompt label and the preset prompt word includes: Merging the prompt label with the preset prompt word to obtain the target prompt word; The preset prompt words are obtained by performing clustering and beam search processing on the data set.
8. A device for generating prompt words for text rewriting, characterized in that: include: An acquisition module, configured to acquire an initial rewritten text corresponding to the original text; A first determination module is configured to construct a text pair according to the original text and the initial rewritten text, and determine a prompt tag corresponding to the text pair; A second determination module is configured to determine an initial prompt word according to the text pair, and calculate a matching degree between the initial prompt word and the text pair; The third determination module is configured to obtain a determination rule of the target prompt word based on the matching degree, wherein the determination rule includes determining the target prompt word based on the initial prompt word and the prompt label, and determining the target prompt word based on the prompt label and a preset prompt word.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Multi-stage semantic reordering fine tuning method and device applied to vertical field
CN120181097A
Communication method and device based on multi-modal data, equipment and storage medium
CN120455540A