A text generation method based on a large language model

By compiling deterministic finite state automata and multi-level contexts into a large language model, the problems of logical drift and memory forgetting in long text generation of large language models are solved, the consistency and standardization of long text generation are achieved, and the manual maintenance cost is reduced.

CN122735940BActive Publication Date: 2026-11-27SHANGHAI YUNGONG EMERGENCE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611209032.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-11
Publication Date
2026-11-27
Estimated Expiration
2046-08-11

AI Technical Summary

Technical Problem

Existing large language models tend to forget key information defined in the preceding text when processing long texts of tens of thousands of words, leading to problems such as logical drift and inconsistent terminology. Furthermore, existing solutions struggle to balance consistency and standardization in the generation of long texts.

Method used

By inputting source documents into a large model to extract feature pairs, compiling them into a deterministic finite state automaton, and combining documents and text blocks to build a multi-level context, hard constraint rules are constructed to ensure the consistency of long text generation.

Benefits of technology

It effectively solves the problems of logical drift and memory forgetting in long text generation, greatly improves content consistency, eliminates the need for manual maintenance of the thesaurus, and reduces the cost of domain adaptation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122735940B_ABST
    Figure CN122735940B_ABST
Patent Text Reader

Abstract

The application discloses a text generation method based on a large language model, comprising: acquiring a source document and a current text block; the current text block is a semantic block in the source document; the source document is input into a preset large language model in a streaming manner to extract a plurality of initial feature pairs; a deterministic finite state automaton is compiled based on the plurality of initial feature pairs; a multi-level context is built based on the source document, the current text block and the deterministic finite state automaton; and the current text block and the multi-level context are input into the preset large language model to obtain an output text. In the application, the source document is input into the large model to extract feature pairs, which are compiled into a deterministic finite state automaton, and a multi-level context is built in combination with the document and the text block, and the model is input to complete long text generation, effectively solving the problems of long text generation logic drift and memory forgetting, greatly improving content consistency, without the need for manual maintenance of a vocabulary, and reducing the cost of domain adaptation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing technology, and in particular to a text generation method based on a large language model. Background Technology

[0002] With the rapid development of generative artificial intelligence technology, large language models, with their powerful semantic understanding and content creation capabilities, have been widely applied in long text generation scenarios such as engineering document translation, code refactoring, and long manuscript writing, becoming a core tool in the field of natural language processing. Based on an end-to-end generation model, large models can efficiently complete various text creation tasks, greatly improving content production efficiency and gaining widespread application in industries such as government and enterprise offices, software development, and text creation.

[0003] However, existing large-scale model generation solutions reveal significant shortcomings when processing long texts of tens of thousands of words. On the one hand, limited by attention mechanisms and context windows, as the text sequence lengthens, the model easily forgets key information such as previously defined proper nouns, variable names, and character settings, leading to problems such as logical drift and inconsistencies in expression. On the other hand, the probabilistic, word-by-word generation nature of large-scale models makes it impossible to strictly adhere to fixed expression rules, often resulting in inconsistent terminology translations and misclassified variable names, severely impacting text quality.

[0004] Currently, the mainstream solution in the industry combines retrieval-enhanced generation technology with static knowledge bases. Retrieval-enhanced generation can only push reference content in the form of soft constraints, and the model is prone to ignoring reference information, making it impossible to achieve mandatory standardization control. On the other hand, manually built and maintained static terminology and rule bases require a lot of manpower to adapt to new fields and new documents, making it difficult to achieve rapid cold start and lacking application flexibility. However, the above methods still cannot guarantee the consistency and standardization of long text generation. Summary of the Invention

[0005] To address the existing technical problems, this invention provides a text generation method based on a large language model. By inputting the source document into the large model to extract feature pairs, compiling them into a deterministic finite state automaton, and combining the document with text blocks to build a multi-level context, the method inputs the text into the model to complete the generation of long texts. This effectively solves the problems of logical drift and memory forgetting in long text generation, significantly improves content consistency, eliminates the need for manual maintenance of the thesaurus, and reduces the cost of domain adaptation.

[0006] In a first aspect, embodiments of this application provide a text generation method based on a large language model, the method comprising: Obtain the source document and the current text block; the current text block is a semantic block in the source document; The source document is streamed into a preset large language model for feature pair extraction to obtain multiple initial feature pairs. Based on the aforementioned initial features, a deterministic finite state automaton is compiled. A multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton. The current text block and the multi-level context are input into the preset large language model to obtain the output text.

[0007] In an alternative embodiment, the compilation of a deterministic finite state automaton based on the plurality of initial features includes: Cluster analysis is performed on the multiple initial feature pairs to remove conflicting feature pairs and retain multiple core feature pairs. The multiple core feature pairs are compiled into the deterministic finite state automaton.

[0008] In one alternative embodiment, a multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton, including: A macro-context is constructed based on the source document; Based on the sliding window memory mechanism, the semantic residual of the semantic block preceding the current text block in the source document is extracted to construct the meso-context; A micro-context is constructed based on the deterministic finite state automaton and the current text block; The multi-level context is determined based on the macro context, the meso context, and the micro context.

[0009] In one alternative embodiment, the macro-context includes a global summary of the source document, a domain definition, and / or a language style guide.

[0010] In an optional embodiment, constructing a micro-context based on the deterministic finite state automaton and the current text block includes: The deterministic finite state automaton is used to scan the current text block to be processed to obtain the target feature pairs that have been hit; Transform the target feature pairs into mandatory system commands; The micro-context is constructed based on the forced system instructions.

[0011] In one optional embodiment, the current text block and the multi-level context are input into the preset large language model to obtain output text, including: The current text block and the multi-level context are input into the preset large language model to obtain the draft text; The draft text is scanned by reverse matching using the deterministic finite state automaton to obtain the output text.

[0012] In one optional embodiment, the draft text is subjected to a reverse matching scan using the deterministic finite state automaton to obtain the output text, including: If the draft text contains conflicting words that conflict with the deterministic finite state automaton, the conflicting words are replaced based on the deterministic finite state automaton, and the replaced draft text is determined as the output text. Alternatively, if the draft text does not contain any conflicting terms that conflict with the deterministic finite state automaton, the draft text is determined as the output text.

[0013] Secondly, embodiments of this application provide a text generation apparatus based on a large language model, the apparatus comprising: The acquisition module is used to acquire the source document and the current text block; the current text block is a semantic block in the source document. The feature pair extraction module is used to extract feature pairs from the source document stream input into a preset large language model to obtain multiple initial feature pairs; A compilation module is used to compile a deterministic finite state automaton based on the plurality of initial features; The context building module is used to build a multi-level context based on the source document, the current text block, and the deterministic finite state automaton; The text output module is used to input the current text block and the multi-level context into the preset large language model to obtain the output text.

[0014] Thirdly, embodiments of this application provide an electronic device, which includes a processor and a memory. The memory stores at least one instruction, at least one program, code set, or instruction set. The processor loads and executes the at least one instruction, at least one program, code set, or instruction set to implement the text generation method based on a large language model of the first aspect.

[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing at least one instruction or at least one program, wherein the at least one instruction or at least one program is loaded and executed by a processor to implement the text generation method based on a large language model of the first aspect.

[0016] Fifthly, embodiments of this application provide a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the text generation method based on a large language model according to the first aspect.

[0017] The text generation method based on a large language model provided in this application has the following technical effects: The process involves obtaining a source document and a current text block, where the current text block is a semantic block within the source document. The source document is streamed into a pre-defined large language model for feature pair extraction, yielding multiple initial feature pairs. A deterministic finite-state automaton is compiled based on these initial feature pairs. A multi-level context is constructed based on the source document, the current text block, and the deterministic finite-state automaton. The current text block and the multi-level context are then input into the pre-defined large language model to obtain the output text. In this application, by inputting the source document into a large model to extract feature pairs, compiling them into a deterministic finite-state automaton, and combining the document and text block to build a multi-level context, the model is input to generate long text. This effectively solves the problems of logical drift and memory forgetting in long text generation, significantly improves content consistency, eliminates the need for manual lexicon maintenance, and reduces domain adaptation costs. Attached Figure Description

[0018] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 This is a schematic diagram of an application environment provided in an embodiment of this application; Figure 2 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 1 ; Figure 3 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 2 ; Figure 4 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 3 ; Figure 5 This is a schematic diagram of the structure of a text generation device based on a large language model provided in an embodiment of this application; Figure 6 This is a hardware structure block diagram of a server for a text generation method based on a large language model provided in an embodiment of this application. Detailed Implementation

[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0021] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0022] Please see Figure 1 , Figure 1 This is a schematic diagram of an application environment provided in an embodiment of this application, including an object terminal 110, the Internet 120, a gateway 130, and a text generation server 140.

[0023] The target terminal 110 is a device used by the target to input query information or input documents. It includes various forms such as desktop computers, laptops, PDAs (Personal Digital Assistants), mobile phones, in-vehicle terminals, home theater terminals, and dedicated terminals. Furthermore, it can be a single device or a collection of multiple devices. For example, multiple devices can be connected via a local area network, sharing a single display device to work collaboratively, forming a single terminal. The target terminal 110 can also communicate with the Internet 120 via wired or wireless means to exchange data.

[0024] Gateway 130, also known as an internetwork connector or protocol converter, is a computer system or device that enables network interconnection at the transport layer and acts as a translator. It bridges the gap between two systems using different communication protocols, data formats, languages, or even completely different architectures. Gateway 130 also provides filtering and security functions. Messages sent from target terminal 110 to text generation server 140 are forwarded to the corresponding text generation server 140 via gateway 130. Similarly, messages sent from text generation server 140 to target terminal 110 are also forwarded to the corresponding target terminal 110 via gateway 130.

[0025] Text generation server 140 refers to a computer system capable of providing services to target terminal 110. Compared to target terminal 110, text generation server 140 has higher requirements in terms of stability, security, and performance. Text generation server 140 can be a single high-performance computer in a network platform, a cluster of multiple high-performance computers, a portion of a single high-performance computer (e.g., a virtual machine), or a combination of portions of multiple high-performance computers (e.g., virtual machines). Text generation server 140 can also communicate with the Internet 120 via wired or wireless means to exchange data.

[0026] In this embodiment, the text generation server 140 acquires a source document and a current text block; the current text block is a semantic block in the source document; the source document is streamed into a preset large language model for feature pair extraction to obtain multiple initial feature pairs; a deterministic finite state automaton is compiled based on the multiple initial feature pairs; a multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton; the current text block and the multi-level context are input into the preset large language model to obtain output text.

[0027] In this application, feature pairs are extracted from the source document and compiled into a deterministic finite state automaton. A multi-level context is built by combining the document and text blocks, and the input is used to complete the generation of long text. This effectively solves the problems of logical drift and memory forgetting in the generation of long text, greatly improves content consistency, eliminates the need for manual maintenance of the thesaurus, and reduces the cost of domain adaptation.

[0028] The following describes a specific embodiment of a text generation method based on a large language model according to this application. Figure 2 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 1 This specification provides method operation steps as shown in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operation steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual system or server products, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown in the embodiments or drawings... Figure 2 As shown, it may include: S201: Obtain the source document and the current text block; the current text block is a semantic block in the source document.

[0029] S202: The source document is streamed into a preset large language model to extract feature pairs, resulting in multiple initial feature pairs.

[0030] S203: Compile a deterministic finite state automaton based on the aforementioned multiple initial features.

[0031] S204: Construct a multi-level context based on the source document, the current text block, and the deterministic finite state automaton.

[0032] S205: Input the current text block and the multi-level context into the preset large language model to obtain the output text.

[0033] Figure 3 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 2 The method may include: S301: Get the source document and the current text block.

[0034] In one possible embodiment, the processing object of this method is the complete source document to be generated, translated or rewritten. In this application, before generating long text, the entire source document needs to be divided into blocks according to the semantic integrity rules to obtain multiple independent semantic blocks.

[0035] In this embodiment of the application, the current text block is a semantic block in the source document, and the semantic block to be processed is the current text block.

[0036] By breaking down long texts into semantic blocks, we can effectively adapt to the text capacity limitations of large models in a single processing run, while ensuring the semantic integrity of each block, thus laying the foundation for subsequent accurate block-by-block generation and contextual connection.

[0037] S302: Input the source document into the preset large language model in a streaming manner to extract feature pairs and obtain multiple initial feature pairs.

[0038] In one possible embodiment, before the text generation task starts, a panoramic pre-scan operation is performed on the complete source document, and the source document is input into a preset large language model segment by segment using a streaming input method to avoid the problem of model attention dilution caused by inputting a long text at once.

[0039] The large language model automatically identifies and extracts core relevance features from the source document that need to maintain global consistency, based on the specific task type, forming pairs of initial features. These task types include document translation, code refactoring, and text continuation.

[0040] In this application, the task type can be a task identifier that the user actively inputs, or it can be obtained by a large language model through intelligent recognition and automatic reasoning of the source document content, without requiring manual configuration by the user, thus further improving the automation and adaptability of the method.

[0041] For example, in engineering translation scenarios, feature pairs corresponding to the terms (Monitor) and (Controller) are extracted; in code refactoring scenarios, variable mapping feature pairs (user_old - original user account) and (log_id - unique log identifier) ​​are extracted; and in novel creation scenarios, feature pairs of the protagonist (Wang Ming - calm and meticulous character) are extracted, comprehensively covering the consistency constraint elements required for long text generation.

[0042] S303: Compile a deterministic finite state automaton based on the aforementioned multiple initial features.

[0043] In one possible embodiment, a deterministic finite state automaton with mandatory constraints is constructed by denoising, normalizing, and structuring the initial feature pairs, serving as the hard constraint base for full-text generation. Specifically, compiling the deterministic finite state automaton based on the multiple initial feature pairs includes: S3031: Perform cluster analysis on the multiple initial feature pairs, remove conflicting feature pairs from the multiple initial feature pairs and retain multiple core feature pairs.

[0044] In one possible embodiment, clustering and conflict disambiguation are performed on all extracted initial feature pairs to screen out conflicting feature pairs that are ambiguous, have multiple translations, or are contradictory.

[0045] For feature pairs with multiple mapping relationships within the same cluster, the validity of a feature pair is determined by comprehensively considering its usage frequency in the source document context, domain-wide standards, and textual semantic logic. Specifically, feature pairs that appear most frequently in the source document, conform to the corresponding industry-wide standards, and perfectly match the contextual semantics are prioritized as valid items; other feature pairs that are inconsistent with the subject's mapping, have low usage frequency, or violate domain standards are uniformly judged as conflicting items and removed.

[0046] For example, if the source document contains two feature pairs, (Monitor) and (Monitor), and considering the domain specifications of the engineering document and the frequency of use throughout the document, (Monitor) is determined to be a valid feature pair. If the variable (user_id) corresponds to both "user ID" and "user password", then based on the context logic of the code document, the mapping relationship with the highest semantic matching degree is retained.

[0047] The system retains only feature pairs with unique mapping relationships and standardized expressions as core feature pairs to ensure the uniqueness and accuracy of subsequent constraint rules and avoid text generation chaos caused by constraint conflicts.

[0048] S3032: Compile the multiple core feature pairs into the deterministic finite state automaton.

[0049] In one possible implementation, the Aho-Corasick (AC) algorithm is employed to uniformly compile the normalized core feature pairs into a memory-recognizable deterministic finite state automaton. This automaton can achieve millisecond-level text matching scanning and can transform discrete core features into standardized, enforceable constraint rules, eliminating the need for manual construction and maintenance of terminology and rule bases, thus achieving zero-cost cold-start construction of constraint rules.

[0050] S304: Construct a multi-level context based on the source document, the current text block, and the deterministic finite state automaton.

[0051] In one possible embodiment, to address the issues of long-distance memory forgetting and fragmented paragraph connections in long text generation, this application constructs a multi-level context system integrating macro, meso, and micro perspectives to comprehensively ensure the consistency of logic and expression throughout the text. Specifically, the multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton, including: S3041: Construct a macro-context based on the source document.

[0052] In this embodiment, the macro-context includes a global summary of the source document, domain definition, and / or language style guidelines. As a top-level constraint, the macro-context guides the overall text creation direction, domain attributes, and writing style, ensuring that the generated content aligns with the core theme and domain specifications of the source document throughout the entire process.

[0053] In one possible implementation, global semantic parsing and extraction are performed on the complete source document to generate a macro-context that includes a global summary of the source document, domain-specific definitions, a unified language style guide, and an overall authoring framework.

[0054] For example, when translating architectural engineering documents, the macro context will label the document as "Translation of Technical Specifications for Prefabricated Building Construction," uniformly adopting a rigorous and formal engineering writing style, and clearly stating that all architectural professional terms must follow national standard translation standards; when translating Python code refactoring documents, global requirements such as code comment style and variable naming conventions will be clearly stated.

[0055] S3042: Extract the semantic residual of the semantic block preceding the current text block in the source document based on the sliding window memory mechanism, and construct the meso-context.

[0056] In one possible embodiment, a sliding window memory mechanism is introduced to locate the previous adjacent semantic block of the current text block and extract the core semantic residual of that semantic block, including the core viewpoint of the paragraph, the key sentences at the end, the connection logic, etc., in order to construct the meso-level context.

[0057] For example, if the current text block is "Construction Safety Protection Rules", then the core requirements and closing statements of the previous semantic block "Construction Site Basic Specifications" are extracted; if the current processing code function is an iterative semantic block, then the functional logic and variable definition residuals of the previous code module are retrieved.

[0058] By leveraging the meso-level context, logical linkage between adjacent text blocks is achieved, eliminating paragraph fragmentation and logical discontinuity issues caused by traditional block generation, and ensuring the overall coherence of the text.

[0059] S3043: Construct a micro-context based on the deterministic finite state automaton and the current text block.

[0060] In one optional embodiment, constructing a micro-context based on the deterministic finite state automaton and the current text block includes: using the deterministic finite state automaton to scan the current text block to be processed to obtain the hit target feature pairs; converting the target feature pairs into forced system instructions; and constructing the micro-context based on the forced system instructions.

[0061] In one possible embodiment, a pre-built deterministic finite state automaton is used to perform real-time scanning and matching of the current text block to be processed, accurately hitting all target core feature pairs contained in the text block; then the matched target feature pairs are converted into standardized mandatory system instructions, clarifying the hard constraint rules such as terms, variables, and settings that the current text generation must follow.

[0062] For example, if the word "Monitor" is detected in the text, a mandatory instruction is generated: "All 'Monitor' translations are uniformly translated as 'monitor,' and other translations such as 'display' or 'monitor' are prohibited." If the code variable "user_id" is detected, a mandatory instruction is generated: "The variable must retain the 'user_id' format throughout and must not be changed to 'userId' or 'userID'." Finally, a micro-context is generated based on this mandatory system instruction, enabling precise constraint control over the details of single text block generation.

[0063] S3044: Determine the multi-level context based on the macro context, the meso context, and the micro context.

[0064] In one possible embodiment, the macro-context of top-level global constraints, the meso-context of middle-level connecting constraints, and the micro-context of bottom-level detailed constraints are fused and assembled to form a complete multi-level context.

[0065] This contextual system achieves comprehensive coverage of the overall, local, and detailed aspects, forming a closed-loop constraint from three dimensions: overall writing style, paragraph logic, and detailed terminology.

[0066] S305: Input the current text block and the multi-level context into the preset large language model to obtain the output text.

[0067] Figure 4 This is a flowchart illustrating a text generation method based on a large language model provided in an embodiment of this application. Figure 3 The current text block and the multi-level context are input into the preset large language model to obtain the output text, including: S401: Input the current text block and the multi-level context into the preset large language model to obtain the draft text.

[0068] In one possible implementation, the large language model receives constraint instructions from multi-level contexts and the original content of the current text block. While retaining its own language generalization and content creation capabilities, it strictly follows global style, paragraph logic, and detailed constraint rules to autonomously generate initial draft text, taking into account both text fluency and constraint standardization.

[0069] For example, when continuing to write engineering text, the model ensures that the sentences are fluent and coherent, and initially avoids the problem of terminology confusion; when generating code comments, it generates the initial content in line with the previous variable definitions and code logic.

[0070] S402: The draft text is scanned by reverse matching using the deterministic finite state automaton to obtain the output text.

[0071] In one possible embodiment, to completely eliminate the representational bias and illusion problems caused by model probability generation, it is also necessary to perform reverse verification and correction on the generated draft text. Specifically, the deterministic finite state automaton is used to perform a reverse matching scan on the draft text to obtain the output text, including: S4021: Determine if there are conflicting words in the draft text. If yes, execute S4022; otherwise, execute S4024.

[0072] In one possible embodiment, a deterministic finite state automaton is invoked to perform a full scan and comparison of the draft text, checking whether there are conflicting words in the text that do not conform to the core feature pairs and constraint rules. For example, it checks whether there are deviations in terms, variables, or settings such as "Monitor" is translated as "display", "user_id" is written as "userId", and "contradictions in the character settings".

[0073] S4022: Replace the conflicting terms based on the deterministic finite state automaton.

[0074] In one possible embodiment, if the draft text contains conflicting words that conflict with the deterministic finite state automaton, the conflicting words are replaced based on the deterministic finite state automaton, and the replaced draft text is determined as the output text.

[0075] For example, the incorrect translation "display" was forcibly replaced with the standard term "monitor," the non-standard variable "userId" was forcibly corrected to "user_id," all non-standard expressions were corrected, and key information throughout the text was strictly unified.

[0076] S4023: The replaced draft text is determined as the output text.

[0077] In one possible implementation, after all conflicting terms have been corrected, a text that fully conforms to the constraint rules and has a unified expression standard is obtained, which is then used as the final output text.

[0078] S4024: The draft text is determined as the output text.

[0079] In another possible embodiment, if there are no conflicting words in the draft text that conflict with the deterministic finite state automaton, it means that the content generated by the model fully conforms to the constraint rules and no correction is needed. The draft text is then determined as the output text, that is, the draft text is directly used as the final output text.

[0080] The method in this embodiment does not require parameter fine-tuning of large models. It controls the model generation behavior in a non-intrusive hard constraint manner, which can adapt to long text generation scenarios in various fields and effectively solve the industry pain points of traditional technology soft constraint failure, high manual maintenance cost, and poor consistency of long texts.

[0081] This application also provides a text generation device based on a large language model. Figure 5 This is a schematic diagram of the structure of a text generation device based on a large language model provided in an embodiment of this application, as shown below. Figure 5 As shown, the device includes: The acquisition module 501 is used to acquire the source document and the current text block; the current text block is a semantic block in the source document. Feature pair extraction module 502 is used to extract feature pairs from the source document stream input into a preset large language model to obtain multiple initial feature pairs; Compilation module 503 is used to compile a deterministic finite state automaton based on the plurality of initial features; Context building module 504 is used to build a multi-level context based on the source document, the current text block and the deterministic finite state automaton; The text output module 505 is used to input the current text block and the multi-level context into the preset large language model to obtain the output text.

[0082] In an optional embodiment, it further includes: The clustering analysis module is used to perform clustering analysis on the multiple initial feature pairs, remove conflicting feature pairs from the multiple initial feature pairs and retain multiple core feature pairs; The first compilation module is used to compile the multiple core feature pairs into the deterministic finite state automaton.

[0083] In an optional embodiment, it further includes: The first construction module is used to construct a macro-context based on the source document; The second construction module is used to extract the semantic residual of the semantic block preceding the current text block in the source document based on the sliding window memory mechanism, and construct the meso-context. The third construction module is used to construct a micro-context based on the deterministic finite state automaton and the current text block; The fourth construction module is used to determine the multi-level context based on the macro context, the meso context, and the micro context.

[0084] In one alternative embodiment, the macro-context includes a global summary of the source document, a domain definition, and / or a language style guide.

[0085] In an optional embodiment, it further includes: The scanning module is used to scan the current text block to be processed using the deterministic finite state automaton to obtain the hit target feature pairs; The conversion module is used to convert the target feature pairs into mandatory system commands; The fifth construction module is used to construct the micro-context based on the forced system instructions.

[0086] In an optional embodiment, it further includes: The input module is used to input the current text block and the multi-level context into the preset large language model to obtain the draft text; The reverse scanning module is used to perform a reverse matching scan on the draft text using the deterministic finite state automaton to obtain the output text.

[0087] In an optional embodiment, it further includes: The first determining module is used to replace the conflicting words in the draft text that conflict with the deterministic finite state automaton based on the deterministic finite state automaton, and determine the replaced draft text as the output text if there are conflicting words in the draft text that conflict with the deterministic finite state automaton. The second determining module is used to determine the draft text as the output text, either if there are no conflicting words in the draft text that conflict with the deterministic finite state automaton.

[0088] The apparatus and method embodiments in this application are based on the same application concept.

[0089] The methods and embodiments provided in this application can be executed on a computer terminal, server, or similar computing device. Taking running on a server as an example, Figure 6 This is a hardware structure block diagram of a server for a text generation method based on a large language model provided in an embodiment of this application. For example... Figure 6 As shown, the server 600 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 610 (CPUs 610 may include, but are not limited to, microprocessors (MCUs) or programmable logic devices (FPGAs), a memory 630 for storing data, and one or more storage media 620 (e.g., one or more mass storage devices) for storing application programs 623 or data 622. The memory 630 and storage media 620 may be temporary or persistent storage. The program stored in the storage media 620 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 610 may be configured to communicate with the storage media 620 and execute the series of instruction operations stored in the storage media 620 on the server 600. Server 600 may also include one or more power supplies 660, one or more wired or wireless network interfaces 650, one or more input / output interfaces 640, and / or one or more operating systems 621, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0090] The input / output interface 640 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 600. In one example, input / output interface 640 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, input / output interface 640 may be a radio frequency (RF) module used for wireless communication with the Internet.

[0091] Those skilled in the art will understand that Figure 6 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 600 may also include... Figure 6 The more or fewer components shown, or having the same Figure 6 The different configurations shown.

[0092] This application provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction, at least one program, code set, or instruction set. The processor loads and executes the at least one instruction, at least one program, code set, or instruction set to implement the above-described data processing method.

[0093] Embodiments of this application also provide a computer-readable storage medium, which can be disposed in a server to store at least one instruction, at least one program, code set, or instruction set related to implementing a text generation method based on a large language model in the method embodiments. The at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the above-described text generation method based on a large language model.

[0094] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0095] As can be seen from the embodiments of the text generation method, apparatus, electronic device, or storage medium based on a large language model provided in this application, the present application obtains a source document and a current text block; the current text block is a semantic block in the source document; the source document is streamed into a preset large language model for feature pair extraction to obtain multiple initial feature pairs; a deterministic finite state automaton is compiled based on the multiple initial feature pairs; a multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton; the current text block and the multi-level context are input into the preset large language model to obtain the output text. In this application, by inputting the source document into a large model to extract feature pairs, compiling them into a deterministic finite state automaton, and combining the document and text block to build a multi-level context, the input model completes the generation of long text, effectively solving the problems of logical drift and memory forgetting in long text generation, significantly improving content consistency, eliminating the need for manual maintenance of the lexicon, and reducing domain adaptation costs.

[0096] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0097] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0098] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0099] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A text generation method based on a large language model, characterized in that, include: Obtain the source document and the current text block; the current text block is a semantic block in the source document; A panoramic pre-scan operation is performed on the complete source document. The source document is then streamed into a preset large language model for feature pair extraction to obtain multiple initial feature pairs. These multiple initial feature pairs are core related features in the source document that need to be kept globally consistent, which are automatically identified and extracted by the preset large language model according to the current specific task type. Based on the aforementioned initial features, a deterministic finite state automaton is compiled. A multi-level context is constructed based on the source document, the current text block, and the deterministic finite state automaton. The current text block and the multi-level context are input into the preset large language model to obtain the output text; The compilation of a deterministic finite state automaton based on the plurality of initial features includes: Cluster analysis is performed on the multiple initial feature pairs. For feature pairs with multiple mapping relationships within the same cluster group, the effective feature pairs are determined by combining the frequency of use in the source document context, general domain norms, and text semantic logic. Conflicting feature pairs with inconsistent mappings under the same subject are removed, and core feature pairs are retained. The Aho-Kolasik algorithm is used to compile the regularized core feature pairs into a memory-recognizable deterministic finite state automaton. The construction of a multi-level context based on the source document, the current text block, and the deterministic finite state automaton includes: A macro-context is constructed based on the source document; Based on the sliding window memory mechanism, the semantic residual of the semantic block preceding the current text block in the source document is extracted to construct the meso-context; The deterministic finite state automaton is used to perform real-time scanning and matching of the current text block to be processed, so as to obtain the target feature pairs that are hit. The target feature pairs are converted into mandatory system instructions to specify the terms, variables, and constraint rules that must be followed in the generation of the current text block; Construct a micro-context based on the aforementioned forced system instructions; The multi-level context is determined based on the macro context, the meso context, and the micro context.

2. The text generation method based on a large language model according to claim 1, characterized in that, The macro-context includes a global summary of the source document, domain definitions, and / or language style guidelines.

3. The text generation method based on a large language model according to claim 1, characterized in that, The step of inputting the current text block and the multi-level context into the preset large language model to obtain the output text includes: The current text block and the multi-level context are input into the preset large language model to obtain the draft text; The draft text is scanned by reverse matching using the deterministic finite state automaton to obtain the output text.

4. The text generation method based on a large language model according to claim 3, characterized in that, The step of using the deterministic finite state automaton to perform a reverse matching scan on the draft text to obtain the output text includes: If the draft text contains conflicting words that conflict with the deterministic finite state automaton, the conflicting words are replaced based on the deterministic finite state automaton, and the replaced draft text is determined as the output text. Alternatively, if the draft text does not contain any conflicting terms that conflict with the deterministic finite state automaton, the draft text is determined as the output text.

5. A text generation device based on a large language model, characterized in that, The device includes: The acquisition module is used to acquire the source document and the current text block; the current text block is a semantic block in the source document. The feature pair extraction module is used to perform a panoramic pre-scan operation on the complete source document, and input the source document into a preset large language model for feature pair extraction to obtain multiple initial feature pairs; the multiple initial feature pairs are the core related features in the source document that need to be kept globally consistent, which are automatically identified and extracted by the preset large language model according to the current specific task type; A compilation module is used to compile a deterministic finite state automaton based on the plurality of initial features; The context building module is used to build a multi-level context based on the source document, the current text block, and the deterministic finite state automaton; The text output module is used to input the current text block and the multi-level context into the preset large language model to obtain the output text; The compilation of a deterministic finite state automaton based on the plurality of initial features includes: Cluster analysis is performed on the multiple initial feature pairs. For feature pairs with multiple mapping relationships within the same cluster group, the effective feature pairs are determined by combining the frequency of use in the source document context, general domain norms, and text semantic logic. Conflicting feature pairs with inconsistent mappings under the same subject are removed, and core feature pairs are retained. The Aho-Kolasik algorithm is used to compile the regularized core feature pairs into a memory-recognizable deterministic finite state automaton. The construction of a multi-level context based on the source document, the current text block, and the deterministic finite state automaton includes: A macro-context is constructed based on the source document; Based on the sliding window memory mechanism, the semantic residual of the semantic block preceding the current text block in the source document is extracted to construct the meso-context; The deterministic finite state automaton is used to perform real-time scanning and matching of the current text block to be processed, so as to obtain the target feature pairs that are hit. The target feature pairs are converted into mandatory system instructions to specify the terms, variables, and constraint rules that must be followed in the generation of the current text block; Construct a micro-context based on the aforementioned forced system instructions; The multi-level context is determined based on the macro context, the meso context, and the micro context.

6. An electronic device, characterized in that, The electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the text generation method based on a large language model as described in any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the text generation method based on a large language model as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Large model decoding constraint method, device and medium

    CN119830959A

  • Long text generation method based on large language model

    CN120493917A