A method and device for real-time switching of writing styles
The method addresses the challenge of dynamic writing style adaptation in large language models by fusing writing styles through Lora parameter extraction and linear weighting, allowing real-time style switching in complex text creation tasks.
Patent Information
- Application Number
- CN202411497632.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2044-10-25
AI Technical Summary
The existing large language models have shortcomings in writing style expression, which is difficult to accurately match specific needs and lacks flexible mechanisms to support real-time switching of writing styles, especially in complex text creation, which is difficult to achieve dynamic adjustment.
By obtaining text materials of different writing styles, generating writing style data, and using Lora fine-tuning technology to train basic big models, extracting Lora parameters, performing linear weighted fusion, generating writing assistive models, and supporting real-time style switching.
It realizes dynamic adjustment of writing style, can flexibly switch multiple styles in complex text creation, generate text content that meets user needs, and improves the flexibility and consistency of text generation.
Smart Images

Figure CN119357385B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of writing style adjustment, and particularly to a method and device for real-time switching of writing styles. Background Art
[0002] With the maturity of artificial intelligence technology, large pre-trained language models (such as GPT, Llama, etc.) have demonstrated powerful capabilities in the field of text generation, being able to generate coherent and natural text content and complete the writing of complex articles. However, in practical applications, different text types, scenarios, and audiences often have strict and diverse requirements for writing styles. For example, news reports require an objective and rigorous style, while novel creation may involve various styles such as relaxed and humorous. In addition, even for the same type of text, in order to enhance expressiveness or adapt to the plot development, it may be necessary to mix multiple styles and be able to switch them in real time during the writing process.
[0003] However, although existing large language models can generate coherent text, they have obvious deficiencies in the performance of writing styles. On the one hand, since the model training often focuses on generality, the style characteristics of the generated text are not distinct enough to accurately match specific requirements. On the other hand, the model lacks a flexible mechanism to support the real-time switching of writing styles, making it difficult to achieve dynamic style adjustment during complex text creation. In addition, for some complex text creation tasks, such as novels and scripts, it is often necessary for the author to integrate multiple writing styles in a single work to enrich the plot and character shaping, which poses higher requirements for existing text generation technologies.
[0004] Therefore, developing an intelligent text creation system that can integrate multiple writing styles and switch them in real time during the creation process has important practical application value and theoretical exploration significance. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and device for real-time switching of writing styles to solve the problem that it is difficult to achieve dynamic adjustment of writing styles in the process of creating complex texts by existing large language models.
[0006] The technical solution adopted by the present invention is:
[0007] In a first aspect, the present invention provides a method for real-time switching of writing styles, including:
[0008] Obtaining text materials of different writing styles and storing them in an object database to generate writing style data;
[0009] Inputting the writing style data into a large model for text processing to generate requirement-text pairs of different writing styles;
[0010] Train a large base model based on requirement-text pairs of different writing styles, and use the LoRA fine-tuning technique to perform LoRA fine-tuning on the model parameters to extract LoRA parameters of different writing styles;
[0011] Fuse and calculate the LoRA parameters of different writing styles by linear weighting to obtain fused parameters;
[0012] Pre-load the large base model, LoRA parameters of different writing styles, and fused parameters into the memory, and based on the user's real-time writing needs, combine the parameters of the corresponding writing style with the large base model to generate a writing assistance model of the specified style.
[0013] Further, inputting the writing style data into the large model for text processing to generate requirement-text pairs of different writing styles includes:
[0014] According to a preset segmentation threshold, segment the texts of different writing styles into multiple text segments corresponding to the writing styles; the writing styles include formal style, relaxed style, humorous style, and concise style;
[0015] Input the text segments of different writing styles into the large model, summarize the main idea and overview corresponding to the text segments, and form requirement-text pairs with the text segments and the main idea and overview;
[0016] Input the requirement-text pairs into the large model again to check whether the requirement-text pairs can summarize the content of the text segments, and conduct manual inspection on the requirement-text pairs. After passing the inspection and having no problems in manual inspection, output the final requirement-text pairs of different writing styles.
[0017] Further, training the large base model based on the requirement-text pairs of different writing styles and using the LoRA fine-tuning technique to perform LoRA fine-tuning on the model parameters to extract LoRA parameters of different writing styles includes:
[0018] Input the requirement-text pairs of different writing styles into the large base model for training respectively, and during the training process, introduce low-rank matrices into each layer or selected partial layers of the large base model through the LoRA fine-tuning technique to perform LoRA fine-tuning on the original weight matrix, while freezing the parameters of other layers of the large base model;
[0019] After completing LoRA fine-tuning on the large base model according to different writing styles, obtain the LoRA parameters corresponding to the writing styles corresponding to , satisfying:
[0020] ;
[0021] Among them, and are two low-rank matrices.
[0022] Furthermore, the LoRA fine-tuning technique introduces low-rank matrices in each layer or selected partial layers of the base large model to perform LoRA fine-tuning on the original weight matrix, including:
[0023] In each layer or selected partial layers of the base large model, assume the dimension of the original weight matrix is ;
[0024] Introduce two low-rank matrices and , where , through matrix multiplication AB, simulate the fine-tuning of the original weight matrix to obtain the fine-tuned LoRA parameters θ of the base large model.
[0025] Furthermore, the method of fusing the LoRA parameters of different writing styles by linear weighting to obtain the fusion parameters includes:
[0026] Adopt the method of linear weighting to combine the LoRA parameters of different writing styles into a unified parameter according to the preset weights. The calculation method of the fusion parameters is:
[0027] ;
[0028] where, is the style parameter formed by fusion; is the total number of parameters to be fused; is the weight of the style parameter , indicating the proportion of the LoRA parameter corresponding to the style in the fusion parameter. The larger is, the more important the corresponding style parameter is, and the greater the impact of this parameter on document generation after parameter fusion;
[0029] Assign LoRA IDs to the LoRA parameters of different writing styles according to the preset naming specifications and formats.
[0030] Furthermore, the method of combining the parameters of the corresponding writing style with the base large model based on the user's real-time writing needs to generate a writing assistance model of the specified style includes:
[0031] Construct an auxiliary writing agent. The base large model itself understands the user input or context information and analyzes the writing style that the user hopes to obtain;
[0032] Match the LoRA parameters of the writing style according to the writing style to generate a parameter specification code, and the parameter specification code includes the LoRA ID;
[0033] Merge the Lora parameters of the corresponding writing style with the original parameters of the base large model to generate a writing assistance model of the specified style; wherein, the calculation method of parameter merging is:
[0034] ;
[0035] Wherein, the original parameters of the base large model are , and the parameters of the large model after parameter merging are , is the Lora parameter corresponding to the writing style.
[0036] Furthermore, if the Lora parameters corresponding to the writing style are not matched according to the writing style, generate parameter weights through the understanding of the style input by the user by the base large model, fine-tune the fusion parameters based on the parameter weights, and synthesize new style parameters; merge the new style parameters with the original parameters to generate a writing assistance model that meets the user's needs.
[0037] In a second aspect, the present invention provides a writing style real-time switching device, including:
[0038] A data collection module for obtaining text materials of different writing styles and storing them in an object database to generate writing style data;
[0039] A text processing module for inputting the writing style data into a large model for text processing to generate requirement-text pairs of different writing styles;
[0040] A model fine-tuning module for training the base large model based on the requirement-text pairs of different writing styles, and performing Lora fine-tuning on the model parameters using Lora fine-tuning technology to extract the Lora parameters of different writing styles;
[0041] A parameter fusion module for performing fusion calculation on the Lora parameters of different writing styles by linear weighting to obtain fusion parameters;
[0042] A style switching module for preloading the base large model, the Lora parameters of different writing styles, and the fusion parameters into the memory, and combining the parameters of the corresponding writing style with the base large model based on the user's real-time writing needs to generate a writing assistance model of the specified style.
[0043] In summary, the beneficial effects of the present invention are as follows:
[0044] A method for real-time switching of writing styles provided by the present invention collects materials of different writing styles through multiple channels, generates requirement-text data of different writing styles for the collected materials to support subsequent model parameter adjustment; for the requirement-text data generated for different styles, the Lora fine-tuning technology is respectively used to train the basic large model so that it learns different writing styles and obtains Lora parameters of different styles; in order to adapt to different style requirements and generate articles with mixed styles, different style parameters are fused to generate a large model for writing with mixed styles; the basic large model and Lora parameters of different styles are pre-loaded into the memory for the model to quickly call according to requirements, realizing real-time style switching. Brief Description of the Drawings
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required to be used in the embodiments of the present invention will be briefly introduced below. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings, and all of these are within the protection scope of the present invention.
[0046] Figure 1 It is a flowchart of a method for real-time switching of a writing style described in the present invention;
[0047] Figure 2 It is a functional module diagram of a device for real-time switching of a writing style in the present invention. Detailed Embodiments
[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention. It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. If there is no conflict, the various features in the present invention and its embodiments can be combined with each other, and all are within the protection scope of the present invention.
[0049] With the continuous progress of artificial intelligence and large model technologies, intelligent generation applications have penetrated into various fields. For example, in intelligent question answering, large model technologies provide strong support for intelligence and high efficiency, enabling question answering systems to be applied in many fields such as government affairs, cultural publicity, medical care, and teaching, greatly improving the convenience of information acquisition and communication. To achieve efficient material extraction and generation, the present invention provides a method for material extraction and generation based on multi-storage technology of large models, which is customized for the question answering needs of personalized fields. Based on an object database, a vector database, and a knowledge graph, the method realizes the extraction and generation of materials through a large model, and combines multi-objective optimization technology to optimize the generated materials. While ensuring the safety and controllability of the materials, misleading retrieval content is ignored, and materials with a unified style and more in line with the user's personalized preferences are generated, providing high-quality materials for applications such as intelligent question answering, assisted writing, and copywriting generation. The detailed implementation process of the present invention is shown in the following embodiments.
[0050] Embodiment 1:
[0051] Please refer to Figure 1 , Figure 1 , which is a schematic flowchart of a method for real-time switching of writing styles in Embodiment 1 of the present invention. As Figure 1 shown, the method provided by the present invention includes:
[0052] Obtain text materials of different writing styles and store them in an object database to generate writing style data;
[0053] Input the writing style data into a large model for text processing to generate requirement-text pairs of different writing styles;
[0054] Train a basic large model based on the requirement-text pairs of different writing styles, and use the Lora fine-tuning technology to perform Lora fine-tuning on the model parameters to extract Lora parameters of different writing styles;
[0055] Fuse and calculate the Lora parameters of different writing styles by linear weighting to obtain fusion parameters;
[0056] Pre-load the basic large model, the Lora parameters of different writing styles, and the fusion parameters into the memory, and based on the user's real-time writing requirements, combine the parameters of the corresponding writing style with the basic large model to generate a writing assistance model of the specified style.
[0057] Specifically, in an embodiment of the present invention, in order to realize large-model assisted writing of different styles, it is necessary to prepare training data of different styles. The present invention collects information of different styles through various channels such as the Internet and archives and stores it in an object database for generating writing style data. Among them, the writing style data text must contain various sentence patterns such as declarative sentences, interrogative sentences, and exclamatory sentences. Based on the collected information, a large model is used to automatically generate high-quality writing requirement-writing text pairs, that is, requirement text pairs, to enhance the style knowledge of the model. The writing styles in the present invention include: formal, relaxed, humorous, concise, etc.
[0058] Furthermore, in an embodiment of the present invention, the writing style data is input into a large model for text processing to generate requirement-text pairs of different writing styles, including:
[0059] According to the preset segmentation threshold, the text of the data of different writing styles is segmented into a plurality of text segments corresponding to the writing styles.
[0060] Among them, writing styles include formal style, relaxed style, humorous style and concise style. The formal style is rigorous in language, precise in wording, clear in structure, and logical. It avoids slang, abbreviations and colloquial expressions, and emphasizes objectivity, authority and professionalism. It is suitable for writing scenarios that require a high degree of professionalism and seriousness, such as academic papers, legal documents, government reports, business letters, formal invitations, policy statements, etc. The relaxed style is natural and fluent in language, friendly in wording, and often contains vivid metaphors and figurative descriptions. It can create a relaxed and pleasant reading atmosphere, focus on emotional resonance with readers, and is suitable for expressing personal insights, sharing life bits and pieces, and attracting readers' interest, such as essays, essays, travel logs, blog posts (non-professional), personal diaries, children's books, etc. The humorous style uses exaggeration, puns, irony and other techniques to create laughs, making the text interesting and entertaining, and can quickly narrow the distance between the author and the reader. It is suitable for humorous essays, satirical articles, comedy scripts, humorous blogs, cartoon comics scripts, talk show lines, etc. The concise style is concise in language, rich in information, and avoids lengthy and complex sentences. The concise style emphasizes directly conveying core information, allowing readers to quickly grasp the main points. It is suitable for fast-paced, high-efficiency reading scenarios, such as news reports, product descriptions, technical documents, social media articles, advertising copy, instant messaging, etc.
[0061] Text fragments with different writing styles are input into the big model, the main points and overviews corresponding to the text fragments are summarized and generated, and the text fragments, main points and overviews are combined into requirement-text pairs.
[0062] The requirement-text pairs are input into the big model again to check whether the requirement-text pairs can summarize the content of the text fragment, and the requirement-text pairs are manually checked. After the verification is correct and there are no problems in the manual check, the final requirement-text pairs with different writing styles are output.
[0063] Specifically, in some embodiments, when generating requirement-text pairs, the text is segmented into fragments of about 500 words, taking care to ensure the linguistic integrity of the segmentation. For text less than 500 words, no segmentation is performed. For each segmented text, the large model (such as qwen, llama, etc.) is used to summarize and generate 2-5 main ideas and overviews of the text, which are combined with the original text to form 2-5 requirement-text pairs. After generation, the generated requirement-text pairs are input into the large model for inspection to determine whether the requirements can well summarize the text content; the generated requirement-text pairs are manually inspected to improve data quality.
[0064] Furthermore, in the embodiments of the present invention, based on the requirement-text pairs of different writing styles, the basic large model is trained, and the Lora fine-tuning technology is used to perform Lora fine-tuning on the model parameters to extract the Lora parameters of different writing styles, specifically including:
[0065] The requirement-text pairs of different writing styles are respectively input into the basic large model for training, and during the training process, through the Lora fine-tuning technology, low-rank matrices are introduced into each layer or selected partial layers of the basic large model to perform Lora fine-tuning on the original weight matrix, while freezing the parameters of other layers of the basic large model.
[0066] After completing the Lora fine-tuning of the basic large model according to different writing styles, the Lora parameters corresponding to writing style i are obtained , satisfying:
[0067] ;
[0068] wherein, and are two low-rank matrices.
[0069] Specifically, the basic large model can use domestic and foreign open-source large models, including llama, qwen, ChatGLM, etc. When selecting the basic large model, factors such as the performance of the model, domain adaptability, community activity, maintainability, and whether it supports continuous updates need to be comprehensively considered. Specifically, domestic and foreign open-source large models such as llama, qwen, ChatGLM, etc. are ideal choices due to their excellent capabilities in text generation, understanding, or specific language processing, as well as extensive community support and active updates. Such selection criteria ensure that the selected model can not only meet the current business needs but also continuously evolve with the development of technology, bringing lasting competitiveness to the application.
[0070] Furthermore, in the embodiments of the present invention, the LoRA fine-tuning technology introduces low-rank matrices in each layer or selected partial layers of the base large model to perform LoRA fine-tuning on the original weight matrix, specifically including:
[0071] In each layer or selected partial layers of the base large model, assuming the dimension of the original weight matrix is .
[0072] Introduce two low-rank matrices and , where . Through matrix multiplication AB, simulate the fine-tuning of the original weight matrix to obtain the fine-tuned LoRA parameters θ .
[0073] The LoRA fine-tuning technology realizes the adaptive adjustment of the model by introducing low-rank matrices in each layer or partial layers of the base model. The ranks of these low-rank matrices are much lower than the rank of the original weight matrix, so the number of parameters is relatively small. Specifically, assume that in a certain layer, the dimension of the original weight matrix is . LoRA will introduce two smaller matrices and , where is much smaller than . Through matrix multiplication AB, the fine-tuning effect of the original weight matrix can be approximately simulated. During the LoRA fine-tuning process, most of the parameters of the pre-trained model remain frozen, that is, these parameters do not change during the fine-tuning process. This method not only reduces the consumption of computing resources but also reduces the risk of overfitting because only a small number of parameters are adjusted. LoRA realizes a low-rank approximation of the original weight matrix by introducing low-rank matrices. This approximation method keeps most of the model parameters unchanged while adjusting a small number of parameters to adapt to specific tasks, thus improving the flexibility and efficiency of model training.
[0074] Furthermore, in the embodiments of the present invention, the LoRA parameters of different writing styles are fused and calculated by linear weighting to obtain the fusion parameters, specifically including:
[0075] Adopt the method of linear weighting to combine the LoRA parameters of different writing styles into a unified parameter according to the preset weight. The calculation method of the fusion parameter is:
[0076] ;
[0077] where, is the style parameter formed by fusion; is the total number of parameters to be fused; is the style parameter The weight represents the Lora parameter corresponding to the style. The proportion in the fusion parameter The larger it is, the more important the corresponding style parameter is, and the greater the impact of this parameter on document generation after parameter fusion.
[0078] Specifically, in some embodiments, in addition to the above four single styles of formal, relaxed, humorous, and concise, it may be necessary to generate articles with mixed styles, such as formal and concise styles, which are suitable for relatively short formal reports; relaxed and humorous styles, which are suitable for essays, diaries, etc. Therefore, it is necessary to fuse different style parameters so that the large model can adapt to different style requirements, flexibly combine various style elements when generating text, create a unique and harmonious writing style, and fully reflect the advantages of the large model. The generated writing large model is not limited to the known several styles, but also has a certain generalization ability, can handle unseen or mixed-style data, and generate more diverse text content.
[0079] According to the preset naming specifications and formats, assign Lora IDs to the Lora parameters of different writing styles. In addition, in order to distinguish different style parameters, different IDs are assigned to the Lora parameters representing different styles for easy designation and invocation according to actual needs. The ID is unique and is unique throughout the system to avoid confusion and conflicts. When generating a new ID, ensure that it does not duplicate the existing ID. The ID is easy to understand and has a certain readability for developers and system administrators to understand and use, following certain naming specifications and formats, such as using specific prefixes or suffixes to identify different types of IDs. The ID has scalability, and its generation strategy can adapt to the expansion of the system scale and be flexibly adjusted according to system requirements.
[0080] Furthermore, in the embodiments of the present invention, the basic large model and Lora parameters of different styles are pre-loaded into the memory for the model to quickly call according to needs, realizing real-time style switching.
[0081] After the large model and parameters are loaded, based on the user's real-time writing needs, the parameters of the corresponding writing style are combined with the basic large model to generate a writing assistance model of the specified style. This process includes:
[0082] Construct an auxiliary writing agent. The basic large model itself understands the user input or context information and analyzes the writing style that the user hopes to obtain. Among them, the user input includes directly selecting a style, inputting specific instructions, etc. The context information includes the theme, emotion, etc. of the current text.
[0083] Match the Lora parameters of the writing style according to the writing style to generate a parameter specification code, and the parameter specification code includes the Lora ID;
[0084] Merge the Lora parameters of the corresponding writing style with the original parameters of the base large model to generate a writing assistance model with the specified style; among them, the calculation method of parameter merging is:
[0085] ;
[0086] Among them, the original parameters of the base large model are , and the parameters of the large model after parameter merging are , is the Lora parameter corresponding to the writing style.
[0087] Furthermore, in some other embodiments of the present invention, if no Lora parameters corresponding to the writing style are matched according to the writing style, that is, there are no appropriate pre-synthesized style parameters, then the parameter weights are generated by the base large model's understanding of the user input style, and the fusion parameters are fine-tuned based on the parameter weights to synthesize new style parameters; the new style parameters are merged with the original parameters to generate a writing assistance model that meets the user's needs.
[0088] The writing style fusion generation and real-time switching method of the embodiments of the present invention includes:
[0089] 1. Through parameter fine-tuning and multi-style parameter fusion based on data of different writing styles, learn the unique features of different writing styles, generate a writing large model that adapts to multiple writing styles, can flexibly combine multiple style elements when generating text, accurately capture and simulate various styles, and has a certain generalization ability to handle unseen or mixed-style requirements and generate more diverse text content.
[0090] 2. Through the parameter preloading technology, immediately call the corresponding parameters when the user needs them without loading the entire model, greatly shortening the switching time and realizing real-time switching of styles.
[0091] 3. Can automatically judge and select appropriate style parameters according to the user's input (such as directly selecting a style, inputting a specific instruction, etc.) or context information (such as the theme, emotion, etc. of the current text), accurately capture the user's needs, and maintain the coherence and consistency of the text.
[0092] Embodiment 2: Refer to Figure 2 As shown, the present invention provides a writing style real-time switching device, including:
[0093] A data collection module for obtaining text materials of different writing styles and storing them in an object database to generate writing style data;
[0094] A text processing module for inputting the writing style data into a large model for text processing to generate requirement-text pairs of different writing styles;
[0095] A model fine-tuning module, which is used to train a basic large model based on requirement-text pairs of different writing styles, and perform LoRA fine-tuning on the model parameters using the LoRA fine-tuning technology to extract LoRA parameters of different writing styles;
[0096] A parameter fusion module, which is used to perform fusion calculation on the LoRA parameters of different writing styles in a linear weighted manner to obtain fusion parameters;
[0097] A style switching module, which is used to pre-load the basic large model, LoRA parameters of different writing styles, and fusion parameters into the memory, and combine the parameters of the corresponding writing style with the basic large model based on the user's real-time writing requirements to generate a writing assistance model of the specified style.
[0098] In the embodiments of the present invention, materials of different writing styles are collected through multiple channels, requirement-text data of different writing styles are generated for the collected materials to support subsequent model parameter adjustment; for the requirement-text data generated for different styles, the basic large model is trained using the LoRA fine-tuning technology respectively to enable it to learn different writing styles and obtain LoRA parameters of different styles; in order to adapt to different style requirements and generate articles of mixed styles, different style parameters are fused to generate a large model for writing in mixed styles; the basic large model and LoRA parameters of different styles are pre-loaded into the memory for the model to quickly call according to requirements, realizing real-time style switching.
[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for real-time switching of writing styles, characterized in that, Including: Obtain text materials of different writing styles and store them in the object database to generate writing style data; Input the writing style data into the large model for text processing to generate requirement-text pairs of different writing styles; Train the basic large model based on the requirement-text pairs of different writing styles, and use the Lora fine-tuning technology to perform Lora fine-tuning on the model parameters to extract the Lora parameters of different writing styles; Perform fusion calculation on the Lora parameters of different writing styles by means of linear weighting to obtain fusion parameters, including: Adopt the method of linear weighting to merge the Lora parameters of different writing styles into a unified parameter according to the preset weight. The calculation method of the fusion parameter is: ; Among them, is the fused style parameter; is the total number of parameters to be fused; is the style parameter weight, indicating the Lora parameter corresponding to the style in the proportion of the fused parameters, The larger it is, the more important the corresponding style parameter is, and the greater the impact of this parameter on document generation after parameter fusion; Assign Lora IDs to the Lora parameters of different writing styles according to the preset naming specifications and formats; Load the basic large model, the Lora parameters of different writing styles, and the fusion parameters into the memory in advance, and based on the user's real-time writing needs, combine the parameters of the corresponding writing style with the basic large model to generate a writing assistance model of the specified style, including: Construct an auxiliary writing agent. The basic large model itself understands the user input or context information and analyzes the writing style that the user hopes to obtain; Match the Lora parameters of the writing style according to the writing style to generate a parameter specification code, and the parameter specification code contains the Lora ID; Merge the Lora parameters of the corresponding writing style with the original parameters of the basic large model to generate a writing assistance model of the specified style; among them, the calculation method of parameter merging is: ; Among them, the original parameters of the base large model are , and the parameters of the large model after parameter merging are , are the Lora parameters corresponding to the writing style; If the Lora parameters of the corresponding writing style are not matched according to the writing style, generate parameter weights through the understanding of the style of the user input by the basic large model, fine-tune the fusion parameters based on the parameter weights, and synthesize new style parameters; merge the new style parameters with the original parameters to generate a writing assistance model that meets the user's needs.
2. The real-time writing style switching method according to claim 1, characterized in that The inputting the writing style data into the large model for text processing to generate requirement-text pairs of different writing styles includes: According to the preset segmentation threshold, respectively segment the texts of different writing styles into multiple text segments corresponding to the writing styles; the writing styles include formal style, relaxed style, humorous style, and concise style; Input the text segments of different writing styles into the large model, summarize the main idea and overview corresponding to the text segments, and form requirement-text pairs with the text segments and the main idea and overview; Input the requirement-text pairs into the large model again to check whether the requirement-text pairs can summarize the content of the text segments, and perform manual inspection on the requirement-text pairs. After the inspection is correct and there are no problems in the manual inspection, output the final requirement-text pairs of different writing styles.
3. The real-time writing style switching method according to claim 1, characterized in that The training of the basic large model based on the requirement-text pairs of different writing styles and the use of the Lora fine-tuning technology to perform Lora fine-tuning on the model parameters to extract the Lora parameters of different writing styles includes: Input the requirement-text pairs of different writing styles into the base large model for training respectively. During the training process, introduce low-rank matrices in each layer or selected partial layers of the base large model through the LoRA fine-tuning technique to perform LoRA fine-tuning on the original weight matrix, and freeze the parameters of other layers of the base large model at the same time; After fine-tuning the base large model according to different writing styles, the writing style corresponding LoRA parameters is obtained, satisfying: ; Among them, and are two low-rank matrices.
4. The real-time writing style switching method according to claim 3, characterized in that The introducing of low-rank matrices in each layer or selected partial layers of the base large model through the LoRA fine-tuning technique to perform LoRA fine-tuning on the original weight matrix includes: In each layer or selected partial layers of the base large model, assume that the dimension of the original weight matrix is ; Introduce two low-rank matrices and , where , through matrix multiplication AB, simulate the fine-tuning of the original weight matrix to obtain the fine-tuned Lora parameters of the basic large model θ .
5. A real-time writing style switching device, characterized in that, including: A data collection module, which is used to obtain text materials of different writing styles, store them in an object database, and generate writing style data; A text processing module, which is used to input the writing style data into the large model for text processing to generate requirement-text pairs of different writing styles; A model fine-tuning module, which is used to train the base large model based on the requirement-text pairs of different writing styles, and perform LoRA fine-tuning on the model parameters using the LoRA fine-tuning technique to extract LoRA parameters of different writing styles; A parameter fusion module, which is used to perform fusion calculation on the LoRA parameters of different writing styles by means of linear weighting to obtain fusion parameters, including: Using the method of linear weighting, merge the LoRA parameters of different writing styles into a unified parameter according to the preset weight. The calculation method of the fusion parameter is: ; Among them, is the fused style parameter; is the total number of parameters to be fused; is the style parameter weight, indicating the proportion of the Lora parameter corresponding to the style in the fused parameters, The larger it is, the more important the corresponding style parameter is, and the greater the impact of this parameter on document generation after parameter fusion; Assign LoRA IDs to the LoRA parameters of different writing styles according to the preset naming specification and format; A style switching module, which is used to pre-load the base large model, the LoRA parameters of different writing styles, and the fusion parameters into the memory, and combine the parameters of the corresponding writing style with the base large model based on the user's real-time writing requirements to generate a writing assistance model of the specified style, including: Construct an auxiliary writing agent. Let the base large model itself understand the user input or context information and analyze the writing style that the user hopes to obtain; Match the LoRA parameters of the writing style according to the writing style to generate a parameter specification code, and the parameter specification code contains the LoRA ID; Merge the LoRA parameters of the corresponding writing style with the original parameters of the base large model to generate a writing assistance model of the specified style; among them, the calculation method of parameter merging is: ; Among them, the original parameters of the base large model are , and the parameters of the large model after parameter merging are , is the Lora parameter corresponding to the writing style; If the LoRA parameters of the corresponding writing style are not matched according to the writing style, generate parameter weights through the understanding of the style of the user input by the base large model, fine-tune the fusion parameters based on the parameter weights, and synthesize new style parameters; merge the new style parameters with the original parameters to generate a writing assistance model that meets the user's requirements.
Citation Information
Patent Citations
Large language model training method for document writing, computer device and storage medium
CN118410776A
Adaptive multimodal event detection
US20230245452A1