Text rewriting cue word generation method and device, electronic equipment and storage medium
By clustering the original text and the initial rewrite text, the target prompt words are generated, and 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
- CN202411487557.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 it is difficult to quickly adapt to changes in different scenarios and needs.
By obtaining the original text and the initial rewrite text, constructing text pairs and clustering, determining the initial prompt words and performing clustering processing, comparing the prompt word clustering category with the text pair clustering category, selecting the appropriate rewrite prompt words and Fusion with the initial prompt word to generate the target prompt word.
It improves the accuracy and credibility of prompt word generation, ensuring that the target prompt word has high adaptability and reliability in different scenarios and needs.
Smart Images

Figure CN119476214A_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] However, the rewriting process of large language models relies on high-quality prompt words. The generation of existing prompt words usually relies on manual experience. When faced with different application scenarios and audience needs, manually generated prompt words are difficult to quickly adapt to changes in different scenarios and needs, resulting in low accuracy of prompt word generation results. Summary of the invention
[0004] In view of this, the present application provides 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 the present application, a method for generating prompt words for text rewriting is provided, comprising: obtaining an initial rewritten text corresponding to an original text; constructing a text pair according to the original text and the initial rewritten text, and clustering the text pair to obtain a text pair clustering category corresponding to the text pair; determining an initial prompt word according to the original text and the initial rewritten text, and clustering the initial prompt word to obtain a prompt word clustering category corresponding to the initial prompt word; comparing the prompt word clustering category with the text pair clustering category to obtain a comparison result, and determining a rewriting prompt word according to the comparison result; fusing the rewriting prompt word according to the initial prompt word to obtain a target prompt word.
[0006] According to a second aspect of the present application, there is provided a device for generating prompt words for text rewriting, comprising: an acquisition module configured to acquire an initial rewritten text corresponding to an original text; a first clustering module configured to construct a text pair according to the original text and the initial rewritten text, and to cluster the text pair to obtain a text pair clustering category corresponding to the text pair; a second clustering module configured to determine an initial prompt word according to the original text and the initial rewritten text, and to cluster the initial prompt word to obtain a prompt word clustering category corresponding to the initial prompt word; a comparison module configured to compare the prompt word clustering category with the text pair clustering category to obtain a comparison result, and to determine a rewriting prompt word according to the comparison result; and a fusion module configured to fuse the rewriting prompt word according to the initial prompt word to obtain a target prompt word.
[0007] According to a third aspect 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.
[0008] According to a fourth aspect 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.
[0009] At least one of the above technical solutions adopted in this application can achieve the following beneficial effects:
[0010] By obtaining the initial rewritten text corresponding to the original text and constructing a text pair, the text pair is clustered to obtain the text pair clustering category corresponding to the text pair, the initial prompt word is determined according to the original text and the initial rewritten text, and the initial prompt word is clustered to obtain the prompt word clustering category corresponding to the initial prompt word, and the prompt word clustering category and the text pair clustering category are compared to obtain the comparison result. If the comparison result indicates that the clustering categories are consistent, the cluster rewrite prompt word corresponding to the cluster category is selected, and the cluster rewrite prompt word is merged with the initial prompt word to obtain the target prompt word. If the comparison result indicates that the clustering categories are inconsistent, a universal global rewrite prompt word is selected and merged with the initial prompt word to obtain the target prompt word. In this way, the initial prompt words and text pairs can be clustered separately, and the rewriting prompt words can be selected based on the comparison results of the two clustering categories. This not only improves the credibility of the rewriting prompt words by improving the accuracy of the clustering results, but also, when the two clustering results are inconsistent, the globally applicable global rewriting prompts are selected to combine with the initial prompt words to generate complete target prompt words. In this way, even if the system identifies the clustering category incorrectly, the target prompt words that meet the current original text rewriting requirements can be obtained, thereby ensuring the reliability and accuracy of the target prompt word generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] 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.
[0012] Figure 1 It is a flowchart of a method for generating prompt words for text rewriting provided in an embodiment of the present application;
[0013] Figure 2 It is a flowchart of another method for generating prompt words for text rewriting provided by an embodiment of the present application;
[0014] Figure 3 It is a flowchart of another method for generating prompt words for text rewriting provided in an embodiment of the present application;
[0015] Figure 4 It is a structural schematic diagram of a prompt word generating device for text rewriting provided by an embodiment of the present application;
[0016] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0017] 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.
[0018] 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.
[0019] 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.
[0020] Text rewriting can be understood as rewriting the original text to meet the needs of the target audience in scenarios such as news reports, marketing advertisements, chatbots, and data augmentation. Text rewriting can be based on emotional expression, text description, or different styles corresponding to question types. The effect of text rewriting depends on the guidance of high-quality rewriting prompts to the large language model, while the current rewriting prompts rely on manual experience. In the existing technology, manual generation of prompts requires a lot of trial and error to find suitable prompts, and the prompts generated by different staff may vary greatly, resulting in unstable text rewriting quality. It is also difficult to quickly adapt to changes in different scenarios and needs based on manual generation.
[0021] Therefore, based on the above problems, the present application proposes a prompt word generation method for text rewriting, which automates and optimizes the prompt word generation process through a double clustering model to overcome the above shortcomings.
[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 1 is a flow chart 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 text pairs according to the original text and the initial rewritten text, and performing clustering processing on the text pairs to obtain text pair clustering categories corresponding to the text pairs;
[0026] S103, determining an initial prompt word according to the original text and the initial rewritten text, and performing clustering processing on the initial prompt word to obtain a prompt word cluster category corresponding to the initial prompt word;
[0027] S104, comparing the prompt word cluster category with the text pair cluster category to obtain a comparison result, and determining the rewriting prompt word according to the comparison result;
[0028] S105, fusing the initial prompt word with the rewritten prompt word to obtain a target prompt word.
[0029] Specifically, first, an initial rewritten text can be obtained based on the input original text and the rewriting requirements, initial prompt words can be obtained based on the original text and the initial rewritten text, a text pair can be constructed between the original text and the initial rewritten text, and the initial prompt words can be further optimized and rewritten based on the text pair to obtain target prompt words, 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 rewriting intention.
[0030] Furthermore, it can be understood that the text rewriting system includes a prompt word optimization network. After obtaining the initial rewritten text, the prompt word optimization network is used to optimize the prompt words of the original text and the initial rewritten text. The text rewriting system can be used to rewrite the original text with different needs, such as rewriting based on different rewriting needs of the original text and user input; it can also be used to rewrite the original text with specific needs, such as a news rewriting system used to rewrite the input original text into a rewritten text with news features. This is only for auxiliary understanding and is not limited.
[0031] Furthermore, the text pair constructed by the original text and the initial rewritten text can be input into the prompt word optimization network for optimization, that is, clustering is performed based on the text pair to obtain the text pair clustering category corresponding to the text pair, and the initial prompt word is generated based on the text pair. The initial prompt word is also clustered to obtain the prompt word clustering category, and the prompt word clustering category and the text pair clustering category are compared. The rewritten prompt word is further determined according to the comparison result, and the target prompt word that better meets the rewriting requirements and conforms to the original text is obtained based on the combination of the rewritten prompt word and the initial prompt word.
[0032] The clustering category may represent the label corresponding to the text pair or prompt word after grouping. Each clustering category may represent a specific grouping feature. For example, the news category may represent that the rewriting prompt word corresponding to the clustering category represents the rewriting of the original text into the news format or news terminology. There is no limitation here.
[0033] It should also be noted that the text pairs and initial prompt words can be clustered respectively through two clustering models to obtain corresponding clustering categories, the initial prompt words can be clustered and identified through the prompt word clustering model, and the text pairs can be clustered and identified through the text pair clustering model. As an example, the K-Means model can be used as the prompt word clustering model, and the MistralForSequenceClassification model can be used as the text pair clustering model. Adaptive unsupervised learning can be performed before the two clustering models perform clustering identification respectively. The K-Means model can first be obtained by similarity clustering learning of sample prompt words. After similarity learning of sample prompt words, the clustering category of the initial prompt words can be accurately identified; similarly, the text pair clustering model can obtain the clustering category of the accurately identified text pair by unsupervised learning of sample text pairs, and then multiple verifications can be performed through the original text, the initial rewritten text and the clustering category of the initial prompt words, and the rewrite prompt words are selected based on the multiple verified clustering categories.
[0034] As an example, the user inputs: "Rewrite 'Artificial intelligence technology is changing the service industry' into news", so an original text will be obtained: "Artificial intelligence technology is changing the service industry" and the rewriting requirement: "Rewrite into news report", and the initial rewritten text is obtained: "Artificial intelligence technology is leading the innovation of the service industry and promoting changes in the entire industry". Based on the original text and the initial rewritten text, a text pair is obtained: "Original text: Artificial intelligence technology is changing the service industry, initial rewritten text: Artificial intelligence technology is leading the innovation of the service industry and promoting changes in the entire industry"; the system further generates initial prompt words based on the text pair by the prompt word optimization network: "Emphasis the impact of artificial intelligence in the service industry", and clusters the text pair and the initial prompt words respectively. For example, the text pair clustering category is obtained: news rewriting, and the initial prompt word clustering category is obtained: objective description. It can be known that news description has objective description characteristics, and the similarity between objective description and news description is greater than a preset threshold (for example, the threshold is 0.5). It can be regarded that "news rewriting" and "objective description" belong to similar clustering categories, and the similarity is greater than 0.5. Based on the flexibility of the system, when the similarity of the two clustering categories is greater than the preset threshold, rewriting prompt words corresponding to both clustering categories can be obtained, for example, the original text is rewritten into an objective expression with news characteristics. Of course, what is the specific clustering category comparison result, that is, whether the rewriting prompt words can be jointly generated when the two clustering categories are different but similar, can be determined based on specific system requirements or developer requirements. For example, if the developer hopes that the system has an absolute judgment standard, similar categories such as "news rewriting" and "objective description" can be regarded as situations where rewriting prompt words cannot be jointly generated, and then a globally applicable rewriting prompt word needs to be determined. If the developer hopes that the system is more flexible, the two categories such as "news rewriting" and "objective description" whose similarity is greater than the preset threshold can be used to jointly generate rewriting prompt words, which is not limited here.
[0035] According to the solution provided by the above embodiment, by comprehensively considering the clustering categories of the initial prompt word and the text pair, a target prompt word that better fits the context can be generated, thereby avoiding the problem of inaccurate generation of the target initial prompt word.
[0036] In some embodiments, a rewrite prompt word is determined based on the comparison result, including: if the comparison result represents that the prompt word cluster category is the same as the text pair cluster category, then the cluster rewrite prompt word corresponding to the prompt word cluster category is determined as the rewrite prompt word, the cluster rewrite prompt word represents the rewrite prompt that is common to the corresponding cluster category, and the cluster rewrite prompt word is obtained by clustering the sample prompt words; if the comparison result represents that the prompt word cluster category is different from the text pair cluster category, then the global rewrite prompt word is determined as the rewrite prompt word, the global rewrite prompt word represents the rewrite prompt that is common to each cluster category, and the global rewrite prompt word is obtained by a global search of the sample prompt words.
[0037] Specifically, a rewriting prompt word list may be pre-built based on sample data to cache cluster rewriting prompt words corresponding to different cluster categories and globally applicable global rewriting prompt words.
[0038] When the prompt word cluster category is the same as the text pair cluster category, it can be understood that the initial prompt word generated by the system corresponds to the text pair, which means that the system's preliminary rewriting and the generation of the initial prompt word meet the rewriting requirements. In this way, the cluster rewrite prompt word corresponding to the cluster category can be selected from the rewriting prompt list as the rewriting prompt word. The cluster rewrite prompt word can be obtained through cluster analysis of multiple similar sample prompt words, which can represent the general rewriting strategy under this category. Based on the rewriting prompt word and the initial prompt word, a target prompt word with more details is obtained.
[0039] It should be understood that when the prompt word clustering category is different from the text pair clustering category but similar, it can be determined based on predetermined rules whether the cluster rewrite prompt word corresponding to the corresponding rewrite clustering category can be selected as the rewrite prompt word. If it is pre-set that the prompt word clustering category is similar to the text pair clustering category, the similarity between the two can be determined. If the two similarities are greater than a preset threshold (for example, 0.5), the cluster rewrite prompt word corresponding to the rewrite clustering category whose similarity with the prompt word clustering category and the text pair clustering category is greater than a preset value (for example, 0.7) can be selected from the rewrite prompt word list as the rewrite prompt word. When there are multiple categories in the rewrite prompt list whose similarities with the prompt word clustering category and the text clustering category are greater than 0.7, the cluster rewrite prompt word corresponding to the rewrite clustering category with the greatest similarity can be selected as the rewrite prompt word. There is no restriction here.
[0040] If the prompt word cluster category is different from the text pair cluster category or the similarity is less than 0.5, the system can select a more general rewriting prompt word, namely the global rewriting prompt word. The global rewriting prompt word can be obtained by performing a global search and analysis on all sample prompt words, representing a universal rewriting strategy applicable to all categories.
[0041] According to the scheme provided in the above embodiment, the similarity between the prompt word clustering category and the text pair clustering category can be determined. When the initial prompt word matches the text pair, it indicates that the logical association between the initial prompt word and the text pair is strong. If the prompt word does not match the text pair, it indicates that there is a difference between the two. The target prompt word generated by a globally applicable global rewriting prompt word can maintain the robustness of the rewriting process, so that the target prompt word will not be used due to the mismatch between the initial prompt word and the text pair. In this way, the appropriate rewriting prompt word can be flexibly selected.
[0042] In some embodiments, cluster rewriting prompt words are obtained by clustering sample prompt words, including: obtaining sample prompt words, the sample prompt words include at least two cluster categories, and each cluster category includes at least two sample prompt words; using a prompt word clustering model, clustering the sample prompt words based on the similarity of the sample prompt words to obtain sample clustering results; performing a beam search on the sample clustering results of each cluster category to obtain search results for each cluster category, and extracting the commonalities of the sample prompt words in the search results of each cluster category to obtain cluster rewriting prompt words corresponding to each cluster category.
[0043] Specifically, the sample prompt words may be clustered and analyzed using a prompt word clustering model to obtain clustered rewriting prompt words.
[0044] First, multiple sample prompt words can be obtained, and each sample prompt word belongs to a specific cluster category, including at least two different cluster categories, and each category contains at least two sample prompt words, so that credible cluster rewriting prompt words are generated.
[0045] Using the prompt word clustering model, cluster analysis is performed based on the similarity between sample prompt words to obtain the clustering results of sample prompt words. This process can classify similar sample prompt words into a unified category. Then, beam search is performed on the sample clustering results of each cluster category to obtain the search results of each category. Beam search can be understood as a search strategy for optimizing and selecting prompt words to find the optimal prompt word combination, i.e., the search result.
[0046] After obtaining the optimal prompt word combination in each cluster category, the search results of each cluster category are rewritten for commonality extraction, that is, the universal rewriting strategy reflected in each sample prompt word. In this way, universal rewriting prompt words suitable for the cluster category, namely cluster rewriting prompt words, can be generated.
[0047] According to the solution provided in the above embodiment, based on cluster analysis, beam search and commonality extraction, the sample prompt words can be converted into cluster rewriting prompt words, so that the target prompt words finally generated can better reflect the common characteristics in the corresponding category, so as to obtain more accurate target prompt words.
[0048] In some embodiments, the global rewriting prompt word is obtained by a global search of the sample prompt words, including: performing a beam search on the global sample prompt words to obtain a sample prompt word combination; extracting the commonalities of the sample prompt words in the sample prompt word combination to obtain the global rewriting prompt word.
[0049] Specifically, after obtaining the sample prompt words, all the sample prompt words can be processed as a whole, that is, without considering the clustering category, all the sample prompt words can be searched in combination using the beam search algorithm to find the optimal prompt word combination. The search process is not expanded here. After obtaining the prompt combination with the best overall performance, the rewriting commonality reflected in these sample prompt words is extracted. The rewriting commonality can represent the universal principle or strategy used by this prompt word in different situations. Through this extraction process, universal prompt words that are applicable to different texts and scenarios on a global scale can be found.
[0050] The global rewrite prompt words and cluster rewrite prompt words can be cached to obtain a rewrite prompt word list. When the system executes the rewrite task, the list is loaded and the corresponding rewrite prompt word is searched from the rewrite prompt word list based on the initial prompt word cluster column and the text pair cluster category.
[0051] According to the solution provided in the above embodiment, the global rewriting prompt words extracted after comprehensive search and analysis of all sample prompt words are universal rewriting rules and methods in various text types and scenarios. They can be applied to rewriting requirements without clear classification or across categories, thus providing the system with a universal and flexible text rewriting guidance.
[0052] In some embodiments, before determining the initial prompt word based on the original text and the initial rewritten text, it also includes: obtaining a data set, the data set includes a sample original text, a sample rewritten text and a sample prompt word, and constructing a sample text pair based on the sample original text and the sample rewritten text; formatting the data set to obtain a string set in a target format, each string in the string set includes a corresponding sample text pair and the sample prompt word; using the string set to fine-tune the initial prompt word generation model to obtain the prompt word generation model, and the prompt word generation model is used to determine the initial prompt word based on the original text and the initial rewritten text.
[0053] Specifically, before the system processes the text pair to generate the initial prompt word, a prompt word generation model can be pre-trained.
[0054] First, a data set can be collected, which includes a data set of sample original texts, sample rewritten texts, and sample prompt words. Each group of samples in the data set includes a pair of texts (i.e., sample original texts and sample rewritten texts) and corresponding sample prompt words. These sample prompt words can be generated based on the sample text pairs.
[0055] By pairing the sample original text and the sample rewritten text in the data set, a set of sample text pairs can be constructed, each of which consists of a sample original text and a corresponding sample rewritten text. Afterwards, the sample text pairs and the corresponding sample prompt words can be formatted, and each set of data can be converted into a unified target format so that it can be directly used for model training. The processed data can exist in the form of a string set, each of which contains a sample text pair and a corresponding sample prompt word.
[0056] The initial prompt word generation model is fine-tuned using a string set. Low-rank adaptation technology can be used during the fine-tuning process to improve the performance of the model while reducing computing resources, thereby enabling the initial prompt word generation model to better understand how to generate high-quality initial prompt words based on the original text and the rewritten text. After fine-tuning, an optimized prompt word generation model can be obtained, which can obtain the initial prompt words based on the newly input original text and the initial rewritten text.
[0057] According to the solution provided in the above embodiment, by fine-tuning the model, a prompt word generation model is obtained, and the prompt word generation model can be used to process the original text and the initial rewritten text to generate initial prompt words, thereby providing effective guidance for the subsequent text rewriting process.
[0058] In some embodiments, before clustering the text pairs to obtain the text pair clustering categories corresponding to the text pairs, it also includes: extracting features of each of the sample text pairs to obtain sample text pair features, and learning sample difference features between the sample original text and the sample rewritten text in each sample text pair; clustering the sample text pair features based on the sample difference features to obtain sample text pair clustering results; performing unsupervised learning on the sample text pair clustering results through the initial text pair clustering model to obtain a text pair clustering model, and the text pair clustering model is used to cluster the text pairs to obtain text pair clustering categories.
[0059] Specifically, a text pair clustering model may be trained, and the text pair clustering model may be used to perform clustering recognition on the text pairs to obtain accurate clustering categories.
[0060] The training process may include: analyzing each sample text pair, i.e., the sample original text and the corresponding sample rewritten text, and learning the difference features between them. The difference features may represent the differences between the sample original text and the sample rewritten text, such as vocabulary replacement, syntactic changes, content expansion, etc. Through these difference features, the essence of text rewriting may be better understood.
[0061] It is also possible to extract features of each sample text pair to obtain sample text pair features in multiple dimensions including semantic changes, style adjustments, information additions and deletions, etc., which can characterize the rewriting process and effect of each sample text pair.
[0062] Based on sample differences, clustering algorithms are used to split and cluster sample text pairs. This way, similar sample text pairs can be classified into the same category to form sample text pair clustering results. These clustering results can reflect the patterns and categories of sample text rewriting. The clustering results can then be used to fine-tune the initial text pair clustering model. These clustering results can be further learned and optimized through unsupervised learning to obtain a text pair clustering model, which can quickly classify newly input text pairs and determine their clustering categories.
[0063] According to the solution provided in the above embodiment, a clustering model that can effectively classify text pairs is constructed by learning the difference features of sample text pairs. The model obtains an understanding of text pair clustering through unsupervised learning, and is ultimately used to classify new text pairs into corresponding cluster categories, providing a basis for the subsequent determination of rewriting prompt words and helping the system generate more accurate target prompt words.
[0064] In some embodiments, after the target prompt word is obtained by fusing the initial prompt word with the rewriting prompt word, the method further includes: rewriting the original text based on the target prompt word to obtain a target rewritten text; displaying the target rewritten text through a visual interface and receiving user feedback.
[0065] Specifically, after obtaining the target prompt word, the original text may be rewritten again using the target prompt word to obtain the target rewritten text, and receive feedback input by the user.
[0066] Through the target prompt words, the system can adjust the original text according to the guidance of the target prompt words and generate new text content, namely the target rewritten text, so that the target rewritten text meets the expected effects of rewriting, such as enhancing news features, improving readability, adjusting text format or expanding content.
[0067] After the rewriting of the text is completed, the system can display the target rewritten text to the user through a visual interface. The display method can be a text preview, a text comparison, or other graphical display methods. There is no restriction here. Of course, after the user views the difference between the original text and the target rewritten text through the visual interface, he can also provide feedback or edit again as needed, such as re-entering the rewriting requirements: regenerate. There is no restriction here.
[0068] According to the solution provided in the above embodiment, rewriting guidance is provided through target prompt words, which can ensure that the generated targeted rewritten text is more in line with user needs and the intention of the prompt words. Display through a visual interface can also enable users to easily compare the original text and the target rewritten text. From prompt word generation to text rewriting result display, the consistency and efficiency of the rewriting process are ensured.
[0069] Figure 2 This 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 further described.
[0070] 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).
[0071] The prompt generation model is trained and saved using the data set to obtain the prompt word generation model described above. The sample original text and the sample rewritten text are processed to obtain a data format suitable for model training. The mistral clustering model (i.e., text pair clustering model) is trained to obtain the text pair clustering model described above. Rewrite_prompt (i.e., sample prompt word) is obtained to train the K-Means clustering model to obtain the prompt word clustering model and cluster rewrite prompt words. The cluster rewrite prompt words and the global rewrite prompt words are saved to obtain the rewrite prompt word list for subsequent rewrite prompt word selection. In this way, the trained prompt word clustering model, text pair clustering model, and rewrite prompt word list can be saved for target prompt word generation in the subsequent text rewriting process.
[0072] 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.
[0073] First, the original text (i.e., original text) and the initial rewritten text (i.e., rewritten text) are obtained, and the rewriting prompt word list 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 K-Means clustering model is used to perform clustering category judgment on the initial prompt word, and the mistral clustering model (i.e., MistralForSequenceClassification model) is used to perform clustering category judgment on the original text and the initial rewritten text to obtain the rewriting category of the original text rewritten into the initial rewritten text. Finally, the two categories are compared. If the categories are consistent, the cluster rewriting prompt word corresponding to the cluster category that is the same or similar to the category in the rewriting prompt word list is directly selected as the rewriting prompt word. If the categories are inconsistent, the global rewriting prompt word in the rewriting prompt word list can be selected as the rewriting prompt word. Then, the rewriting prompt word is merged with the initial prompt word to generate the target prompt word.
[0074] It should be understood that there may not be a cluster category in the rewrite prompt word list that is completely consistent with the cluster category corresponding to the initial prompt word. In this case, you can choose a cluster category in the rewrite prompt word list that is similar to the cluster category of the initial prompt word. The degree of similarity can be determined by a pre-set threshold. For example, a semantic similarity between the two greater than 0.5 is pre-set to be considered a similar cluster category.
[0075] 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.
[0076] 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.
[0077] 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:
[0078] An acquisition module 401 is configured to acquire an initial rewritten text corresponding to the original text;
[0079] A first clustering module 402 is configured to construct text pairs according to the original text and the initial rewritten text, and perform clustering processing on the text pairs to obtain text pair clustering categories corresponding to the text pairs;
[0080] The second clustering module 403 is configured to determine the initial prompt word according to the original text and the initial rewritten text, and perform clustering processing on the initial prompt word to obtain the prompt word cluster category corresponding to the initial prompt word;
[0081] The comparison module 404 is configured to compare the prompt word cluster category with the text pair cluster category to obtain a comparison result, and determine the rewriting prompt word according to the comparison result;
[0082] The fusion module 405 is configured to fuse the initial prompt word with the rewritten prompt word to obtain a target prompt word.
[0083] In some embodiments, the comparison module 404 is specifically used to determine the cluster rewrite prompt word corresponding to the prompt word cluster category as the rewrite prompt word if the comparison result indicates that the prompt word cluster category is the same as the text pair cluster category, the cluster rewrite prompt word represents the rewrite prompt that is common to the corresponding cluster category, and the cluster rewrite prompt word is obtained by clustering the sample prompt words; if the comparison result indicates that the prompt word cluster category is different from the text pair cluster category, then determine the global rewrite prompt word as the rewrite prompt word, the global rewrite prompt word represents the rewrite prompt that is common to each cluster category, and the global rewrite prompt word is obtained by a global search of the sample prompt words.
[0084] In some embodiments, the comparison module 404 is specifically used to obtain sample prompt words, the sample prompt words include at least two clustering categories, and each clustering category includes at least two sample prompt words; using the prompt word clustering model, the sample prompt words are clustered based on the similarity of the sample prompt words to obtain sample clustering results; a beam search is performed on the sample clustering results of each clustering category to obtain search results for each clustering category, and the commonalities of the sample prompt words in the search results of each clustering category are extracted to obtain cluster rewrite prompt words corresponding to each clustering category.
[0085] In some embodiments, the comparison module 404 is specifically configured to perform a beam search on the global sample prompt words to obtain a sample prompt word combination, extract the commonalities of the sample prompt words in the sample prompt word combination, and obtain a global rewriting prompt word.
[0086] 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 the sample prompt word, and construct a sample text pair based on the sample original text and the sample rewritten text; format the data set to obtain a string set in a target format, each string in the string set includes a corresponding sample text pair and the sample prompt word; use the string set to fine-tune the 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 based on the original text and the initial rewritten text.
[0087] In some embodiments, the first clustering module 402 is specifically used to extract features of each of the sample text pairs, and learn the sample difference features between the sample original text and the sample rewritten text in each sample text pair to obtain sample text pair features; cluster the sample text pair features based on the sample difference features to obtain sample text pair clustering results; perform unsupervised learning on the sample text pair clustering results through the initial text pair clustering model to obtain a text pair clustering model, and the text pair clustering model is used to perform clustering processing on the text pairs to obtain text pair clustering categories.
[0088] In some embodiments, the fusion module 405 is specifically used to provide rewriting guidance for the original text based on the target prompt word to obtain the target rewritten text; display the target rewritten text through a visual interface, and receive user feedback.
[0089] 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.
[0090] 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.
[0091] 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.
[0092] 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.
[0093] 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.
[0094] 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.
[0095] 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.
[0096] 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 performing clustering processing on the text pair to obtain a text pair clustering category corresponding to the text pair; Determining an initial prompt word according to the original text and the initial rewritten text, and performing clustering processing on the initial prompt word to obtain a prompt word cluster category corresponding to the initial prompt word; Compare the prompt word cluster category with the text pair cluster category to obtain a comparison result, and determine the rewrite prompt word according to the comparison result; The target prompt word is obtained by fusing the initial prompt word with the rewritten prompt word.
2. The method according to claim 1, characterized in that The step of determining the rewriting prompt word according to the comparison result includes: If the comparison result indicates that the prompt word cluster category is the same as the text pair cluster category, then determining the cluster rewriting prompt word corresponding to the prompt word cluster category as the rewriting prompt word, the cluster rewriting prompt word indicating a rewriting prompt common to the corresponding cluster category, and the cluster rewriting prompt word is obtained by clustering the sample prompt words; If the comparison result indicates that the prompt word cluster category is different from the text pair cluster category, a global rewrite prompt word is determined as the rewrite prompt word, wherein the global rewrite prompt word indicates a rewrite prompt common to each cluster category and is obtained by a global search of the sample prompt words.
3. The method according to claim 2, characterized in that The cluster rewriting prompt words are obtained by clustering the sample prompt words, including: Acquire the sample prompt words, wherein the sample prompt words include at least two cluster categories, and each cluster category includes at least two sample prompt words; Using a prompt word clustering model, clustering the sample prompt words based on the similarity of the sample prompt words to obtain a sample clustering result; A beam search is performed on the sample clustering results of each clustering category to obtain search results of each clustering category, and commonalities of the sample prompt words in the search results of each clustering category are extracted to obtain the cluster rewriting prompt words corresponding to each clustering category.
4. The method according to claim 3, characterized in that The global rewriting prompt word is obtained by a global search of the sample prompt word, including: Performing a beam search on the global sample prompt words to obtain a sample prompt word combination; The commonalities of the sample prompt words in the sample prompt word combination are extracted to obtain the global rewriting prompt word.
5. The method according to claim 2, characterized in that: Before determining the initial prompt word according to the original text and the initial rewritten text, the method further includes: Acquire a data set, the data set including a sample original text, a sample rewritten text, and the sample prompt word, and construct a sample text pair according to the sample original text and the sample rewritten text; Formatting the data set to obtain a set of character strings in a target format, each character string in the set of character strings including the corresponding sample text pair and the sample prompt word; The initial prompt word generation model is fine-tuned using the character string set to obtain a prompt word generation model, wherein the prompt word generation model is used to determine the initial prompt word according to the original text and the initial rewritten text.
6. The method according to claim 5, characterized in that Before clustering the text pairs to obtain the text pair cluster categories corresponding to the text pairs, the method further includes: Extracting features of each of the sample text pairs to obtain sample text pair features, and learning sample difference features between the sample original text and the sample rewritten text in each of the sample text pairs; Clustering the sample text pair features based on the sample difference features to obtain sample text pair clustering results; The sample text pair clustering results are subjected to unsupervised learning through the initial text pair clustering model to obtain a text pair clustering model, and the text pair clustering model is used to perform clustering processing on the text pairs to obtain the text pair clustering categories.
7. The method according to claim 1, characterized in that After the initial prompt word and the rewritten prompt word are merged to obtain the target prompt word, the method further includes: Based on the target prompt word, rewriting guidance is provided to the original text to obtain a target rewritten text; The target rewritten text is displayed through a visual interface, and user feedback is received.
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 clustering module is configured to construct a text pair according to the original text and the initial rewritten text, and perform clustering processing on the text pair to obtain a text pair clustering category corresponding to the text pair; A second clustering module is configured to determine an initial prompt word according to the original text and the initial rewritten text, and perform clustering processing on the initial prompt word to obtain a prompt word cluster category corresponding to the initial prompt word; A comparison module is configured to compare the prompt word cluster category with the text pair cluster category to obtain a comparison result, and determine the rewriting prompt word according to the comparison result; The fusion module is configured to fuse the initial prompt word with the rewritten prompt word to obtain a target 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
Large model data labeling method and device, equipment, medium and product
CN119848555A
Large Model Data Annotation Method, Device, Equipment, Medium and Product
CN119848555B