Text generation method and device, electronic equipment, storage medium and product
By performing task intent recognition and rewriting the model input format template for the problem text, the problem of low text quality when generating domain-specific texts using large language models is solved, and high-quality professional text generation is achieved.
Patent Information
- Application Number
- CN202510695233.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2026-11-27
AI Technical Summary
When existing large language models generate text for specific domains, users often struggle to accurately express their generation intent, resulting in low text quality that fails to meet professional requirements.
By performing task intent recognition on the question text, a model input format template for a preset domain is obtained, the initial query instruction is rewritten, and a response text that meets the requirements of a specific domain is generated.
It improves the professionalism and accuracy of the generated text, meeting the actual needs of users.
Smart Images

Figure CN123180103A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the fields of artificial intelligence technology and text generation technology. Specifically, this disclosure relates to a text generation method, apparatus, electronic device, computer-readable storage medium, and computer program product. Background Technology
[0002] In recent years, with the rapid development of natural language processing technology, large language models (LLMs) have been widely used in various text generation tasks. Existing large language models typically automatically generate corresponding text content based on user-input prompts to meet users' text generation needs.
[0003] However, in practical applications, ordinary users often lack understanding of how large language models are invoked and do not possess the ability to construct professional prompts, making it difficult for them to accurately express their generation intentions. This affects the accuracy and professionalism of the generated content, resulting in low-quality generated text that fails to meet the actual needs of users. Summary of the Invention
[0004] This disclosure provides a text generation method, apparatus, electronic device, computer-readable storage medium, and computer program product to address the problem of low text quality in the prior art when large language models generate text for specific domains.
[0005] According to one aspect of the present disclosure, a text generation method is provided, the method comprising: Obtain the question text to be processed, wherein the question text includes an initial query instruction; The task intent is identified by performing task intent recognition on the question text, and the task category corresponding to the question text is determined from multiple candidate task categories. The multiple candidate task categories include target tasks or non-target tasks, and the target task is a text generation task in a preset domain. If it is determined that the task category belongs to the target task, obtain the model input format template of the large language model corresponding to the task category, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction; Obtain a response prompt message, which is used to instruct the large language model to respond to the query command of the input model; The response prompt and the new query instruction are input into the large language model, and the response text corresponding to the new query instruction is generated by the large language model. The response text is then used as the response text to the question text.
[0006] According to another aspect of the present disclosure, a text generation apparatus is provided, the apparatus comprising: The question text acquisition module is used to acquire the question text to be processed, wherein the question text includes an initial query instruction; The intent recognition module is used to perform task intent recognition on the question text, and determine the task category corresponding to the question text from multiple candidate task categories. The multiple candidate task categories include target tasks or non-target tasks, and the target task is a text generation task in a preset domain. The instruction rewriting module is used to obtain a preset model input format template of a large language model corresponding to the task category when it is determined that the task category belongs to the target task, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction. Obtain a response prompt message, which is used to instruct the large language model to respond to the query command of the input model; The module for generating response text is used to input the response prompt information and the new query instruction into the large language model, generate the response text corresponding to the new query instruction through the large language model, and use the response text as the response text to the question text.
[0007] As an optional embodiment, when the intent recognition module performs task intent recognition on the question text and determines the task category corresponding to the question text from multiple candidate task categories, it is specifically used for: Obtain discrimination prompt information, which is used to indicate the task intent of the schematic diagram recognition model to the query instruction of the input model, so as to determine the task category corresponding to the question text from multiple candidate task categories; The discrimination prompt information and the question text are input into the intent recognition model, and the task category corresponding to the question text is obtained through the intent recognition model.
[0008] As an optional embodiment, the question text also includes historical text, which includes the historical interaction content between the target object and the large language model, wherein the target object is the object that initiated the initial query instruction; The discrimination prompt information also indicates the intent recognition logic chain for the intent recognition big model to perform intent recognition, and the intent recognition logic chain includes: Determine whether the query command input to the model is related to the preset domain; If it is irrelevant, output the first result, which indicates that the task category is a non-target task; If relevant, determine whether the task category is a text creation task or a text editing task based on whether the historical text and the query instructions are relevant; The target tasks include text creation tasks and text editing tasks within the preset domain.
[0009] As an optional embodiment, the target task includes at least one of the text creation task or the text editing task in the preset domain; Where the task category is determined to be a text creation task, the device further includes a candidate response text acquisition module, the candidate response text acquisition module being used for: Obtain a standard text library, which stores multiple standard response texts for the preset domain; Determine the semantic similarity between the new query instruction and each standard response text in the standard text library; If there exists a standard response text with a semantic similarity greater than or equal to a preset threshold, then the standard response text with a semantic similarity greater than or equal to the preset threshold will be used as a candidate response text for the new query instruction. The module for generating response text is specifically used to input the response prompt information and the new query instruction into the large language model, and to generate the response text corresponding to the new query instruction through the large language model: The response prompt information, the new inquiry instruction, and the candidate response text corresponding to the new inquiry instruction are input into the large language model, and the response text corresponding to the new inquiry instruction is generated by the large language model.
[0010] As an optional embodiment, the standard text library also includes a feature vector of a text summary for each of the standard response texts; The candidate response text module, when determining the semantic similarity between the new query instruction and each standard response text in the standard text library, is specifically used for: The new query instruction is subjected to feature extraction to obtain the feature vector of the new query instruction; Determine the similarity between the feature vector of the new query instruction and the feature vector of the text summary of each of the standard response texts. The semantic similarity corresponding to each of the text summaries is used as the semantic similarity between the standard response text corresponding to the text summary and the new query instruction text.
[0011] As an optional embodiment, for each of the standard response texts, the text summary of the standard response text is obtained in the following manner: According to the preset summary generation requirements, the standard response text is summarized to obtain a text summary of the standard response text; wherein, the summary generation requirements indicate at least one content item to be included in the summary to be generated; Specifically, for the text creation task, the model input format template indicates that the rewritten query instruction includes the content items from at least one content item.
[0012] As an optional embodiment, when the instruction rewriting module obtains a model input format template of a large language model corresponding to the preset task category, and rewrites the initial query instruction based on the model input format template to obtain a new query instruction, it is specifically used for: Obtain the rewriting prompt information corresponding to the task category. The rewriting prompt information includes the model input format template corresponding to the task category. The rewriting prompt information is used to prompt the large model to rewrite the input query command according to the model input format template corresponding to the task category, provided that the semantics of the command before and after rewriting remain unchanged. The rewrite prompt information and the initial query instruction are input into the rewrite model, and a new query instruction is obtained through the rewrite model.
[0013] As an optional embodiment, the device further includes a preset threshold determination module, used for: Obtain multiple sample query instructions corresponding to the text creation task; Based on the model input format template corresponding to the text creation task, the multiple sample query instructions are rewritten to obtain a new sample instruction corresponding to each sample query instruction. For each new sample instruction, determine the semantic similarity between the new sample instruction and each standard response text in the standard text library, and take the standard response text with the highest semantic similarity as the reference response text for the new sample instruction; The preset threshold is determined based on the semantic similarity between each new sample instruction and its corresponding reference response text.
[0014] As an optional embodiment, when determining the preset threshold based on the semantic similarity between each new sample instruction and its respective reference response text, the preset threshold determination module is specifically used for: Each new sample instruction and its corresponding reference response text are displayed to the reviewer, and feedback information from the reviewer is obtained for each new sample instruction and its corresponding reference response text. The feedback information indicates whether the reference response text is the answer to the corresponding new sample instruction. Based on the semantic similarity of each reference response text that is indicated as "yes" according to the feedback information, the preset threshold is determined.
[0015] As an optional embodiment, the response prompt information is used to instruct the large language model to determine whether there is a response text to the input model's query instruction in the input candidate response text. If yes, the corresponding candidate response text is output as the response text to the query instruction. If no, the response text to the query instruction is generated by referring to the candidate response text.
[0016] As an optional embodiment, the target task includes at least one of the text creation task or the text editing task in the preset domain; In the case where the task category is determined to be a text editing task, the question text also includes historical text. When the instruction rewriting module rewrites the initial query instruction based on the model input format template, it is specifically used for: Based on the model input format template corresponding to the text editing task, the initial query instruction is rewritten, wherein the model input format template indicates that the rewritten query instruction includes the position to be edited in the historical text and the corresponding editing method.
[0017] As an optional embodiment, the response prompt information also indicates the model output format corresponding to the task category, and the text format of the response text corresponding to the new query instruction is the model output format corresponding to the task category.
[0018] According to another aspect of the embodiments of this application, an electronic device is provided, the electronic device including a memory, a processor and a computer program stored in the memory, the processor executing the computer program to implement the above-described text generation method.
[0019] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the above-described text generation method.
[0020] According to another aspect of the embodiments of this application, a computer program product is provided, including a computer program that, when executed by a processor, implements the above-described text generation method.
[0021] The beneficial effects of the technical solutions provided in this disclosure are: By performing task intent recognition on the acquired question text, the task category to which the question text belongs is determined. A model input format template for text generation tasks in a preset domain is pre-set. When the task category of the question text to be processed is a text generation task in the preset domain, the model input format template is obtained. The initial query instruction is rewritten based on the model input format template, so that the rewritten query instruction can more effectively guide the large language model to generate high-quality response text that meets the requirements of a specific domain. This effectively improves the professionalism and accuracy of the generated response content and solves the problem of low text quality when generating text in a specific domain in existing technologies. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments of this disclosure will be briefly introduced below.
[0023] Figure 1 A schematic diagram of a system architecture provided for an embodiment of this disclosure; Figure 2 A flowchart illustrating a text generation method provided in an embodiment of this disclosure; Figure 3 A schematic diagram illustrating intent recognition provided for an embodiment of this disclosure; Figure 4 A schematic diagram illustrating the determination of candidate response text provided in an embodiment of this disclosure; Figure 5 A schematic diagram of a generative vector database provided in an embodiment of this disclosure; Figure 6 A schematic diagram illustrating another method for determining candidate response text provided in an embodiment of this application; Figure 7 A schematic diagram illustrating the determination of a preset threshold provided in an embodiment of this application; Figure 8 This is a schematic diagram illustrating another method for determining a preset threshold according to an embodiment of this disclosure; Figure 9 A flowchart illustrating a text generation method provided in an embodiment of this disclosure; Figure 10 A system architecture diagram for implementing a text generation method is provided in an embodiment of this application; Figure 11 Another system architecture diagram provided for embodiments of this disclosure; Figure 12 This is a schematic diagram of the structure of a text generation device provided in an embodiment of the present disclosure; Figure 13 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0024] The embodiments of this disclosure are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this disclosure, and do not constitute a limitation on the technical solutions of the embodiments of this disclosure.
[0025] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the terms “comprising” and “including” as used in embodiments of this disclosure mean that the corresponding feature can be implemented as the presented feature, information, data, step, operation, element, and / or component, but do not exclude implementation as other features, information, data, step, operation, element, component, and / or combinations thereof supported by the art. It should be understood that when we say that an element is “connected” or “coupled” to another element, the one element can be directly connected or coupled to the other element, or it can mean that the one element and the other element are connected through an intermediate element. Furthermore, “connected” or “coupled” as used herein can include wireless connection or wireless coupling. The term “and / or” as used herein indicates at least one of the items defined by the term, for example, “A and / or B” or “A, B” indicates implementation as “A,” or implementation as “B,” or implementation as “A and B.”
[0026] In the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0027] To make the objectives, technical solutions, and advantages of this disclosure clearer, the embodiments of this disclosure will be described in further detail below with reference to the accompanying drawings.
[0028] First, the technical terms used in this disclosure will be introduced and explained: Artificial intelligence (AI) refers to the technology of simulating human intelligent behavior through computer systems, aiming to enable machines to possess abilities such as perception, understanding, reasoning, learning, and decision-making. AI systems typically rely on algorithmic models, big data, and computing power, and can be used in various application scenarios such as image recognition, speech recognition, natural language processing, autonomous driving, and intelligent control. In recent years, with the development of deep learning technology, AI has achieved significant breakthroughs in semantic understanding and text generation, becoming one of the important foundational technologies driving intelligent services and automated processing.
[0029] Deep learning is a machine learning method based on artificial neural networks. It features a multi-layered network structure and can automatically learn high-level feature representations from massive amounts of data. Compared to traditional machine learning methods, deep learning demonstrates stronger feature extraction and modeling capabilities in fields such as image recognition, speech recognition, and natural language processing. The training of large language models typically relies on deep learning methods based on deep neural networks (such as the Transformer architecture) to achieve effective modeling and generation of complex language rules.
[0030] Natural Language Processing (NLP) is an important branch of artificial intelligence that aims to enable computers to understand, analyze, generate, and respond to human natural language. NLP involves multiple disciplines such as linguistics, computer science, and statistics, and typical tasks include text classification, sentiment analysis, named entity recognition, question-answering systems, and text generation. With the development of big data and deep learning technologies, NLP has been widely applied in dialogue systems, intelligent customer service, and automated writing, and is one of the core technologies supporting large language models to achieve intelligent interaction and text generation.
[0031] Large Language Models (LLMs) are a class of natural language processing models trained on massive corpora using deep learning techniques. They typically have billions or even hundreds of billions of parameters and are capable of understanding and generating natural language text. These models learn linguistic patterns and contextual dependencies within the corpus, possessing strong language understanding and generation capabilities, and are widely used in tasks such as dialogue generation, machine translation, text summarization, and question answering systems. Representative large language models include the GPT series, BERT, and T5.
[0032] The pretraining finetuning paradigm is a widely used method for training large language models. Its core idea is to perform unsupervised pre-training on a large-scale general corpus, enabling the model to learn general language representation capabilities; then, supervised fine-tuning is performed on specific downstream tasks or domain-specific data, allowing the model to adapt to specific task requirements. This paradigm effectively improves the model's generalization and transfer capabilities and is currently the mainstream technical approach in natural language processing model development.
[0033] Prompt engineering refers to the technique of designing and optimizing prompts for user input to guide large language models in generating more predictable text content. Because language models are highly sensitive to input prompts, well-designed prompts can significantly improve the relevance, accuracy, and stylistic consistency of the generated text. Prompt engineering typically involves adjusting elements such as prompt structure, semantic guide words, and example inputs, and it plays a particularly important role in "zero-shot" or "few-shot" tasks where fine-tuning model parameters is not required.
[0034] Retrieval-Augmented Generation (RAG) is a text generation technique that combines information retrieval with generative language models. Before generating an answer or content, this method first retrieves information relevant to the input question from an external knowledge base or document collection. The retrieved information, along with the original input, is then fed into a language model for text generation. By introducing external knowledge relevant to the input, RAG can significantly improve the accuracy, timeliness, and knowledge coverage of the generated content, making it particularly suitable for tasks such as open-domain question answering and specialized content generation.
[0035] Vertical text generation refers to text generation for specific vertical fields (such as healthcare, law, finance, e-commerce, etc.). It utilizes natural language processing technology, through domain identification, task modeling, prompt optimization, or knowledge enhancement, to guide language models to generate professional text that conforms to the semantic norms and expression habits of that field. This method effectively improves the accuracy, professionalism, and practical usability of the generated content, and is suitable for scenarios such as professional copywriting, industry report generation, and intelligent question answering.
[0036] Existing methods for vertical text generation mainly fall into two technical paths: one is to fine-tune a domain-specific model by using small sample data on a general-purpose language model; the other is to combine a general-purpose model with a domain-specific database and use retrieval-enhanced generation (RAG) to assist text generation. While the former improves domain adaptability, it suffers from high computational resource consumption, high training costs, and poor model transferability. The latter, while reducing training costs and improving versatility, requires highly specialized user input, and the retrieved content may not adequately match the actual problem, easily introducing noise and affecting the quality and accuracy of the generated text.
[0037] The text generation methods, apparatuses, electronic devices, computer-readable storage media, and computer program products disclosed herein are intended to solve at least one of the above-mentioned technical problems of the prior art.
[0038] The following description of several exemplary embodiments illustrates the technical solutions of this disclosure and the technical effects produced by these solutions. It should be noted that the following embodiments can be referenced, learned from, or combined with each other. Identical terms, similar features, and similar implementation steps in different embodiments will not be repeated.
[0039] Figure 1 This is a schematic diagram of a system architecture provided in an embodiment of the present disclosure. The system architecture includes a terminal 10, a server 20, and a template database 30. The terminal 10 can be a user terminal, which may have a client application for question-and-answer installed. The user can access the server 20 through this client, or through a browser application on the terminal. The terminal 10 can be used to obtain question text with initial query instructions input by the user. The user can input questions in various ways, such as natural language text input, voice input, structured option selection, or submit questions in a multimodal form by uploading relevant documents, images, etc., and send the questions to the server 20. The server 20 can be a server deployed with a large language model. After obtaining the question text, the server 20 will perform task intent recognition on the question text to determine whether the task category of the question text is a text generation task in a preset domain. The number of preset domains can be multiple, such as contract domains, advertising copywriting domains, and medical and health records domains. The system architecture diagram provided in this disclosure can be applied to vertical text generation, also known as vertical domain text generation. In this disclosure, at least one vertical domain can be preset as a preset domain to automatically generate text content that conforms to the characteristics of that domain.
[0040] The task category of the user-input question text may be a text generation task in a preset domain, a text generation task in another domain, or a non-text generation task in the preset domain. Therefore, server 20 needs to perform task intent recognition on the question text. If the task category of the question text is determined to be a text generation task in a preset domain, the question text is processed according to the corresponding processing method. Specifically, after server 20 determines that the task category of the question text is the target task, it can obtain the model input format template of the large language model corresponding to the preset task category from template database 30. The model input format templates corresponding to different preset domains can be different. Template database 30 can store the model input format templates for each preset domain that are set manually. After server 20 determines that the task category of the question text is a text generation task in the contract drafting domain, it can obtain the model input format template corresponding to the contract drafting text generation task from template database 30. After server 20 determines that the task category of the question text is a text generation task in the advertising copywriting domain, it can obtain the model input format template for the advertising copywriting domain from template database 30.
[0041] After obtaining the model input format template, server 20 rewrites the initial query instruction in the question text according to the template to obtain a new query instruction. This rewriting reduces linguistic ambiguity and helps the model more accurately identify user intent. Upon receiving the new query instruction, server 20 obtains response hints, which are the prompts of the large language model, instructing it to respond to the input query instruction. Server 20 inputs the response hints and the new query instruction into the large language model. Based on its natural language understanding capabilities, the large language model determines that it needs to respond to the input query instruction, further performs semantic analysis on the input query instruction, and generates the corresponding text to obtain the response text for the new query instruction. After obtaining the response text input by the large language model, server 20 uses this response text as the response to the user's input question text and sends it to terminal 10. Terminal 10 displays the response text to the user in the client or browser's visual interface.
[0042] In some embodiments, terminal 10 may be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smartwatch, smart voice interaction device, smart home appliance, vehicle terminal, etc., but is not limited thereto. Those skilled in the art will understand that the number of the aforementioned terminals may be more or less. For example, there may be only one terminal, or there may be dozens or hundreds of terminals, or even more. This disclosure does not limit the number or type of terminals.
[0043] In some embodiments, server 20 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. Server 20 is used to provide background services for query and answering applications. In some embodiments, server 20 undertakes the main computing work, and terminal 10 undertakes the secondary computing work; or, server 20 undertakes the secondary computing work, and terminal 10 undertakes the main computing work; or, server 20 and terminal 10 collaborate on computing using a distributed computing architecture.
[0044] For example, the text generation method in this embodiment can be performed by a server. The following description uses a server as the execution entity to illustrate the solution in this embodiment.
[0045] This disclosure provides a text generation method, such as... Figure 2 As shown, the method includes: S201. Obtain the question text to be processed, which includes the initial query instruction.
[0046] In this embodiment, the server can be a backend server for a question-and-answer application. The server may deploy a large language model, and the server implements the question-and-answer function based on the large language model. The server can obtain question text including an initial query instruction. This initial query instruction can be a statement used to express a request or question.
[0047] Optionally, the server can obtain the question text by receiving input from an interactive object. This interactive object can be a user using the question-and-answer application. When using the application, the user inputs a query to describe their needs, such as "What is the contract text?". Therefore, the server can obtain the question text based on the user's input. Alternatively, the interactive object can be other devices, such as business servers. During business processing, business servers may generate problems that need to be addressed. These business servers can interact with the question-and-answer application's server, inputting the problems generated during business processing into the application's server. The server then obtains the question text based on the input from other business servers.
[0048] Optionally, the server can also obtain the historical interaction content with the interactive object, and obtain the question text based on the current input of the interactive object and the historical interaction content with the interactive object, so as to provide users with more accurate response text based on the contextual understanding capability of the large language model.
[0049] It should be noted that the "problem" in the "problem text" of this disclosure embodiment is a broad concept. It can be a question in the usual sense, such as "What is a contract?", in which case the corresponding response text is the answer to the question. It can also be a business processing request, such as "Please generate a contract text about renting a house" and "Please correct the typos in the contract", in which case the corresponding response text is the business processing result corresponding to the business processing request.
[0050] S202. Perform task intent recognition on the question text and determine the task category corresponding to the question text from multiple candidate task categories.
[0051] Among them, multiple candidate task categories include target tasks or non-target tasks, with target tasks being text generation tasks in a preset domain.
[0052] In this embodiment of the disclosure, multiple candidate task categories are provided in advance. By performing task intent recognition on the question text, the task category of the question text is determined from the multiple candidate task categories. Optionally, semantic analysis can be performed on the question text in general to obtain a reference task category for the question text. The semantic similarity between the reference task category and each candidate task category is determined, and the candidate task category with the highest similarity is taken as the task category corresponding to the question text.
[0053] Specifically, the candidate task categories include target tasks or non-target tasks. Target tasks are text generation tasks in preset domains. There can be multiple preset domains, such as contract domains, advertising copy domains, and medical and health records domains. A domain can be understood as the text format type of a vertical text. Different format types of vertical texts belong to different domains. For example, contracts, advertising copy, and medical and health records have different text formats and belong to different domains. Non-target tasks are tasks other than text generation tasks within the preset domain. These can include non-text generation tasks within the preset domain, text generation tasks outside the preset domain, and non-text generation tasks outside the preset domain. If the preset domain is the contract domain, then non-text generation tasks within the preset domain can be tasks related to contracts but not used to generate contracts. For example, the task category for the question text "What is a contract?" is a non-text generation task within the preset domain. Non-text generation tasks outside the preset domain can be text generation tasks in other domains. For example, if the preset domain is contracts, the task category for the question text "Please write a promotional article about environmental protection" is a non-text generation task outside the preset domain. Non-text generation tasks outside the preset domain are tasks that are neither related to the preset domain nor to text generation tasks. For example, if the preset domain is contracts, the task category for the question text "Please generate an image based on the promotional article" is a non-text generation task outside the preset domain.
[0054] In this embodiment of the disclosure, task intent recognition is performed on the question text to determine whether the question text is a text generation task in a preset domain, so as to process the question text accordingly based on the task category corresponding to the question text.
[0055] As an optional embodiment, task intent recognition can be achieved by using a large model to perform task intent recognition on the question text. Specifically, task intent recognition of the question text involves determining the task category corresponding to the question text from multiple candidate task categories, including: Obtain discrimination prompt information. The discrimination prompt information is used to identify the task intent of the large diagram recognition model in response to the query instruction of the input model, so as to determine the task category corresponding to the question text from multiple candidate task categories. The discrimination prompt information and question text are input into the intent recognition model, and the task category corresponding to the question text is obtained through the intent recognition model.
[0056] In this embodiment of the disclosure, the intent recognition big model can be an existing big language model. Prompt words can be pre-set for this intent recognition big model as judgment prompts. These prompts are used to identify the task intent of the initial query instruction in the question text of the intent recognition big model. For example, the judgment prompt could be: "Please determine whether the input query instruction is related to the contract generation task. If it is, output the target task; if it is not, output the non-target task."
[0057] The discrimination prompt information and question text are input into the intent recognition big data model. Based on the semantic analysis capability of the intent recognition big data model, the task category corresponding to the question text is obtained, and it is determined whether the task category corresponding to the question text is the target task or a non-target task.
[0058] Optionally, after obtaining the output of the large intent recognition model, each output can be labeled according to the task type of the output, and the corresponding initial query instruction can be processed accordingly based on the label.
[0059] In this embodiment of the disclosure, the task intent of the query instruction in the question text is identified by a large model that determines the prompt information. Based on the powerful semantic analysis capability of the large language model, the task intent identification result of the question text is highly accurate.
[0060] As an optional embodiment, when the server obtains the question text based on the input of the interactive object and the historical interaction content with the interactive object, it can obtain not only the initial query instruction but also the historical text. When the input of the interactive object and the historical interaction content with the interactive object include historical text, the question text includes both the initial query instruction and the historical text. The historical text can be a reference sample input by the interactive object or a response text from the historical interaction content.
[0061] As an optional embodiment, if the question text also includes historical text, the task category of the question text can be determined by performing semantic analysis based on the query instructions and historical text using an intent recognition big data model.
[0062] Specifically, the discrimination prompt also instructs the intent recognition logic chain of the intent recognition big model, which includes: Determine whether the query command input to the model is related to the text generation of the preset domain; If it is irrelevant, output the first result, which indicates that the task category is a non-target task; If relevant, determine whether the task category is a text creation task or a text editing task based on whether the historical text and the query instructions are relevant; The target tasks include text creation tasks and text editing tasks within a preset domain.
[0063] In this embodiment of the disclosure, the discrimination prompt information includes an intent recognition logic chain that guides the intent recognition big model to perform intent recognition. This intent recognition logic chain can be understood as a thought chain, which is used to guide the intent recognition big model to gradually determine the task category of the question text.
[0064] like Figure 3 As shown, Figure 3 This is a schematic diagram of intent recognition provided in an embodiment of this disclosure. The intent recognition big data model executes the intent recognition process shown in the diagram based on the judgment prompt information. For the input question text, the intent recognition big data model obtains the query instruction (Query) in the question text and determines whether the query instruction is related to text generation in a preset domain, i.e., whether the query is related to generating vertical text. If it is determined that the query instruction is unrelated to generating vertical text, the task category of the question text is determined to be a non-target task. The unrelated input in the diagram indicates that the input question text is unrelated to the text generation task in the preset domain, i.e., the first result in this embodiment of the disclosure. If it is determined that the query instruction is related to text generation in the preset domain, it further determines whether there is historical text in the question text. If there is no historical text, the task category of the question text is determined to be a text creation task, i.e., a creation task in the diagram. If historical text exists, it further determines whether the query instruction is related to historical text. If not, the task category of the question text is determined to be a text creation task; if so, the task category of the question text is determined to be a text editing task, i.e., an editing task in the diagram.
[0065] In this embodiment of the disclosure, the text generation task in the preset domain includes a text creation task and a text editing task in the preset domain. The text creation task generates new text based on a query instruction, while the text editing task edits existing text according to the query instruction to obtain the edited text. For example, if the preset domain is a contract, then the task category for the query text "Please write a contract text about purchasing a mobile phone" is the text creation task in the preset domain, and the task category for the query text "Please help me modify the second clause in the contract text for purchasing a mobile phone, the contract text for purchasing a mobile phone is xxx" is the text editing task in the preset domain, where "xxx" represents the specific content of the contract text for purchasing a mobile phone.
[0066] It should be noted that the historical text in the question text can be either what the user inputs when entering the query command, or it can be the user's historical interaction content with the large language model. This large language model is used to generate the question text response text. For example, the user first enters the query command "Please write a contract text for purchasing a mobile phone", and then obtains a contract text for purchasing a mobile phone output by the large language model. Further, the user can enter the query command "Please help me modify the second clause in the contract text for purchasing a mobile phone". At this time, the server can use the user's query command and the contract text for purchasing a mobile phone in the interaction content as the question text. The contract text for purchasing a mobile phone in the interaction content is recorded as the historical text in the question text.
[0067] This disclosure provides a structured intent recognition logic chain, which guides a large model to more accurately complete task intent recognition and classification through a series of conditional branch judgments. The intent recognition logic chain provides a clear reasoning path for the task intent recognition process, making the task category determination process interpretable and enabling more accurate determination of the task category of the question text.
[0068] S203. If it is determined that the task category belongs to the target task, obtain the model input format template of the large language model corresponding to the preset task category, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction.
[0069] In this embodiment of the disclosure, a model input format template corresponding to a text generation task in a preset domain can be preset. If the preset domain includes multiple domains, the text generation task in each preset domain can have a corresponding model input format template. In addition, when the text generation task in the preset domain may also include a text creation task and a text editing task in the preset domain, the text creation task and the text editing task in the preset domain can each have their own corresponding model input format template.
[0070] The model input format template corresponding to the text generation task in the preset domain can be a format template for rewriting the query instruction pre-generated by a technician. It is important to understand that the initial query instruction input by the user may contain inaccuracies or ambiguities. If the initial query instruction is directly input into the large language model, the resulting response text may not satisfy the user. Therefore, in this embodiment, by obtaining the model input format template corresponding to the text generation task in the preset domain, the initial query instruction is rewritten according to the model input format template to obtain a new query instruction. This new query instruction makes it easier for the large language model to understand the user's actual needs, enabling the large language model to better understand the intent of the question text, thereby improving the relevance and accuracy of the answer and obtaining a response text that satisfies the user.
[0071] In this embodiment of the disclosure, the initial query instruction is rewritten according to the model input format template, which allows users to express themselves freely when inputting content without requiring users to master complex syntax or format, thereby improving the interactivity and intelligence.
[0072] Optionally, when rewriting the initial query command, techniques such as regular expressions, template matching, and keyword replacement can be used to rewrite the initial query command into a query command that conforms to the model input format template. Alternatively, the initial query command can also be rewritten by modifying a large model (i.e., a large language model with text rewriting capabilities).
[0073] As an optional embodiment, a model input format template of a large language model corresponding to a preset task category is obtained. Based on the model input format template, the initial query instruction is rewritten to obtain a new query instruction, including: Obtain the rewriting prompt information corresponding to the task category. The rewriting prompt information includes the model input format template corresponding to the task category. The rewriting prompt information is used to prompt the large model to rewrite the input query command according to the model input format template corresponding to the task category, while keeping the semantics of the command before and after rewriting unchanged. The rewrite prompt and the initial query command are input into the rewrite model, and a new query command is obtained through the rewrite model.
[0074] In this embodiment of the disclosure, after determining the target task category, the initial instruction can be labeled with the corresponding category. This allows the acquisition of an input format template for the large language model corresponding to the target task category, whereby the template represents the input structure required for that type of task. Based on this input format template, rewriting prompts are generated. These prompts include the input format template and are used to remind the large language model that the semantics of the instructions before and after rewriting should remain consistent, and that the initial instruction should be rewritten according to the specified format.
[0075] The initial query instruction and the rewritten prompt information are input into the rewritten large language model, which then generates a new query instruction. This new query instruction is semantically consistent with the initial instruction and conforms to the input format requirements of the large language model for this task category.
[0076] This embodiment of the disclosure can automatically complete the standardized rewriting of instruction formats, so that instructions under different task categories can better adapt to the processing needs of large language models, thereby improving the accuracy and consistency of task execution.
[0077] Optionally, the rewriting model and the intent recognition model can be different large language models. To reduce the resource consumption of deploying large language models, the rewriting model and the intent recognition model can be the same model, which can perform corresponding tasks based on corresponding prompts. Specifically, the prompts from the rewriting model can be used as rewriting prompts, and the prompts from the intent recognition model can be used as judgment prompts.
[0078] S204. Received a reply prompt message.
[0079] The response prompt information is used to instruct the large language model to respond to the query instructions from the input model.
[0080] S205. Input the response prompt information and the new query instruction into the large language model, generate the response text corresponding to the new query instruction through the large language model, and use the response text as the response text to the question text.
[0081] In this embodiment of the disclosure, the response text corresponding to a new initial query instruction can be obtained through a large language model as the response text to the question text. When obtaining the response text corresponding to a new initial query instruction through the large language model, response prompt information can be obtained. This response prompt information is used to instruct the large language model to respond to the query instruction of the input model. The response prompt information and the new query instruction are input into the large language model, so that the large language model responds to the query instruction of the output model under the prompt of the response prompt information, and outputs the response text corresponding to the query instruction.
[0082] The large language model used to generate response text, the large rewriting model used to rewrite query instructions, and the large intent recognition model used to perform task intent recognition can all be the same model. By obtaining the corresponding prompt words during the corresponding processing, the model can be instructed to perform the corresponding processing. By using the same large language model, the deployment of models can be reduced, and computing resources and hardware overhead can be saved.
[0083] Optionally, when the question text also includes historical text, the response prompt, new query instructions, and historical text can be input into the large language model so that the large language model can use the historical text as a reference to generate the response text or use the historical text as the text to be modified to obtain the modified historical text as the response text.
[0084] As an optional embodiment, the response prompt information also indicates the model output format corresponding to the task category, and the text format of the response text corresponding to the new query instruction is the model output format corresponding to the task category.
[0085] In this embodiment of the disclosure, a text format for a preset domain can be pre-generated. The response prompt message instructs the large language model to output the response text according to this text format. For example, if the preset domain is a contract, a contract text format can be pre-generated. The response prompt message not only instructs the large language model to respond to the input model's query, but also instructs the output response text to conform to the contract text format.
[0086] By indicating the model input format corresponding to the task category in the response prompt information, the response text output by the large language model is made into standardized text of the preset domain, which has higher standardization and improves the user experience. Optionally, the model output format includes the file format and text structure of the output text. Taking the preset domain and the contract domain as an example, the model output format can include the output file format OUTPUT_FORMAT, which can be HTML, Markdown, or other custom formats, and can also include the contract text structure COMPLEX_OUTPUT_PROMPT, which is the text structure of the contract text.
[0087] Optionally, if the task type of the question text to be processed is a non-target task, the response prompt information and the question text can be input into the large language model, and the response text of the question text can be obtained based on the large language model. This large language model can be the same as or different from the large language model used to process text generation tasks in the preset domain mentioned above.
[0088] In this embodiment, task intent recognition is performed on the acquired question text to be processed to determine the task category to which the question text belongs. A model input format template for a text generation task in a preset domain is pre-set. When the task category of the question text to be processed is a text generation task in the preset domain, the model input format template is obtained, and the initial query instruction is rewritten based on the model input format template. This allows the rewritten query instruction to more effectively guide the large language model to generate high-quality response text that meets the requirements of a specific domain, thereby effectively improving the professionalism and accuracy of the generated response content and solving the problem of low text quality when generating text in a specific domain in the prior art.
[0089] In this embodiment of the disclosure, the text generation task in the preset domain may include at least a text creation task and a text editing task in the preset domain. For different tasks, this embodiment of the disclosure may employ different processing methods to obtain the corresponding response text. First, the specific processing method for the text creation task in the preset domain will be introduced.
[0090] As an optional embodiment, the target task includes at least one of a text creation task or a text editing task in a preset domain; In the case where the task category is determined to be a text creation task, the method further includes: Obtain a standard text library, which stores multiple standard response texts for the preset domain; Determine the semantic similarity between the new query instruction and the standard response texts in the standard text library; If there exists a standard response text with a semantic similarity greater than or equal to a preset threshold, then the standard response text with a semantic similarity greater than or equal to the preset threshold will be used as a candidate response text for the new query instruction. The response prompt and the new query instruction are input into the large language model, which then generates the response text corresponding to the new query instruction, including: The response prompt, the new query instruction, and the candidate response text corresponding to the new query instruction are input into the large language model, and the response text corresponding to the new query instruction is generated by the large language model.
[0091] In this embodiment, when the task category of the question text is a text creation task within a preset domain, Retrieval Enhancement (RAG) technology can be used to search a standard text library containing multiple standard response texts within the preset domain. This search retrieves the complete text most closely related to the needs of the interactive object from existing vertical text data. If a standard response text with high relevance to the question text exists in the standard text library, it is selected as a candidate response text. The candidate response text, response hints, and the new query instruction are then input into the large language model to obtain the response text corresponding to the new query instruction generated by the large language model. This allows the large language model to refer to the candidate response text to obtain the response text for the question text, thereby improving the accuracy of the response text.
[0092] In this embodiment of the disclosure, the semantic similarity between the initial query instruction and the standard texts in the standard text library can be used to search for whether there are candidate response texts in the standard text library. Furthermore, since the semantic information of the rewritten initial query instruction, i.e. the new query instruction, is more explicit, in this embodiment of the disclosure, the semantic similarity between the new query instruction and the standard response texts in the standard text library can be used to determine whether there are candidate response texts corresponding to the question text in the standard text library.
[0093] Specifically, it determines whether there is a standard response text with a semantic similarity greater than or equal to a preset threshold. If so, the standard response text with a semantic similarity greater than or equal to the preset threshold is taken as a candidate response text.
[0094] Optionally, the semantic similarity between the new query instruction and each standard response text can be determined, and then each semantic similarity can be compared with a preset threshold to determine the standard response text corresponding to a semantic similarity greater than or equal to the preset threshold. For example... Figure 4 As shown, Figure 4 This diagram illustrates a method for determining candidate response texts according to an embodiment of this disclosure. For a new query instruction, a standard text library is retrieved, and the semantic similarity between the new query instruction and each standard response text is calculated to obtain a semantic similarity set. Within this set, semantic similarities greater than or equal to a preset threshold are determined. Figure 4 The semantic similarity score of 5 is used to determine the standard response text 5 corresponding to the semantic similarity score of 5, which is then used as the candidate response text.
[0095] Optionally, the standard response texts in the standard text library can be pre-classified. First, categories similar to the new query instruction are identified. From these categories, standard response texts with semantic similarity greater than or equal to a preset threshold are selected as candidate response texts. For example, if the preset domain is contracts, the standard text library stores multiple standard contract texts. These texts can be categorized according to their purpose to determine the intended use of the contract text for the new query instruction. For instance, if the purpose is purchasing electronic products, candidate response texts are retrieved from the standard response texts in the "purchasing electronic products" category. This eliminates the need to determine the semantic similarity between the new query instruction and every standard text in the standard text library, improving the efficiency of candidate response text retrieval. Optionally, nearest neighbor search can also be used to retrieve candidate response texts from the standard text library.
[0096] In this embodiment, when no candidate response text exists, it indicates that no standard response text highly relevant to the question text exists in the standard text library. In this case, the new query instruction and response hint information are input into the large language model, which generates the response text corresponding to the new query instruction. When a candidate response text exists, the candidate response text, response hint information, and the new query instruction are input into the large language model to obtain the response text corresponding to the new query instruction generated by the large language model. The optional response hint information is used to prompt the large language model to determine whether the input includes a candidate response text. If no candidate response text is included, the query instruction input to the model is responded to; if a candidate response text is included, the query instruction input to the model is responded to based on the candidate response text.
[0097] As an optional embodiment, the response prompt information is used to instruct the large language model to determine whether there is a response text to the input model's query instruction in the input candidate response text. If there is, the corresponding candidate response text is output as the response text to the query instruction. If there is no response text, the response text corresponding to the query instruction is generated by referring to the candidate response text.
[0098] In this embodiment of the disclosure, when candidate response texts exist, the large language model can be guided to respond to the input query command based on the candidate response texts, using response prompt information. Specifically, the response prompt information can instruct the large language model to determine whether the input candidate response text can be used as the response text to the input query command. The output query command here is the new query command. If the large language model believes that the candidate response text can be used as the response text to the input query command, it will output the candidate response text as the response text to the query command. If the candidate response text cannot be used as the response text to the input query command, the large language model will refer to the text content of the candidate response text to generate the response text.
[0099] Optionally, if no candidate response text is found, an empty response text can be set as the input for the large language model. The large language model will then find that the candidate response text cannot be used as the corresponding answer text.
[0100] As an optional embodiment, two different response prompts can be preset, corresponding to the retrieval of candidate response text and the retrieval of no candidate response text, respectively. When no candidate response text is retrieved, the corresponding first response prompt and the new query instruction are input into the large language model, instructing the large language model to respond to the query instruction input into the model. When a candidate response text is retrieved, the corresponding second response prompt, the new query instruction, and the candidate response text are input into the large language model, instructing the large language model to determine whether the candidate response text can be used as the response text to the input query instruction. If the candidate response text is deemed acceptable, it is output as the response text to the query instruction. If it is deemed unacceptable, the large language model is instructed to refer to the text content of the candidate response text to generate the response text.
[0101] For example, if the preset domain is contracts, the response message could be: "Your setup: You are a contract drafting assistant." The following is a sample contract: {RetrieveText} Your task: Determine if the sample contract is suitable for the user's needs. If it is, modify the format to the specified format and use the content directly. If it is not suitable, use it as a reference and draft a contract that meets the user's needs yourself.
[0102] {OUTPUT_FORMAT} You need to analyze the sample contract first to determine if it meets the user's needs, and then output the HTML contract.
[0103] If you drafted the contract yourself without using the reference contract, please note `{COMPLEX_OUTPUT_PROMPT}`. Here, `OUTPUT_FORMAT` and `COMPLEX_OUTPUT_PROMPT` are pre-set format templates for the contract text. `OUTPUT_FORMAT` indicates the format requirements of the contract text, and `COMPLEX_OUTPUT_PROMPT` indicates the text structure of the contract text. The reference contract is a candidate response text.
[0104] For responses where no candidate response text exists, the prompt message could be: "Your setup: You are a professional contract drafting assistant, Your task: Draft a contract that meets the user's needs. { OUTPUT_FORMAT} {COMPLEX_OUTPUT_PROMPT}.
[0105] By pre-setting the above two types of response prompts, the large language model does not need to judge whether the input includes candidate response text, thus it can focus more on generating response text and reduce the difficulty for the large language model to understand the content of the input text.
[0106] In this embodiment of the disclosure, if multiple candidate response texts are obtained, all of the multiple candidate response texts can be input into the large language model, instructing the large language model to determine whether there are candidate response texts among the multiple candidate response texts that can be used as response texts for new inquiry instructions. The candidate response texts that can be used as response texts for new inquiry instructions are output, or the optimal candidate response text that can be used as response texts for new inquiry instructions is selected and output.
[0107] Optionally, the number of candidate response texts can be limited to one. When retrieving candidate response texts, the standard response text with the highest semantic similarity to the new query instruction can be determined from the standard text library. This text is then compared to a preset threshold. If the semantic similarity is greater than or equal to the preset threshold, the standard response text is selected as a candidate response text. If the semantic similarity is less than the preset threshold, it indicates that no candidate response text exists for the new initial query instruction. By selecting only one candidate response text, the problem of too many candidate response texts interfering with the large language model's response text generation and leading to low accuracy in the generated response text is prevented.
[0108] As an optional embodiment, the standard text library also includes a feature vector of a text summary for each standard response text; Determining the semantic similarity between the new query instruction and the standard response texts in the standard text library includes: Feature extraction is performed on the new query instruction to obtain its feature vector; Determine the similarity between the feature vector of the new query instruction and the feature vector of the text summary of each standard response text. The semantic similarity of each text summary is used as the semantic similarity between the standard response text corresponding to the text summary and the new query instruction text.
[0109] In this embodiment, the feature vectors of standard response texts in the standard text library may be very long, containing a large amount of non-critical information. Direct semantic comparison would lead to a high computational burden and slow response. Text summarization is a compressed representation of the standard response text, with shorter feature vectors and more focused semantics, making it more suitable for fast similarity calculation. Therefore, in this embodiment, the semantic similarity between a new query instruction and the corresponding text summary can be determined as the semantic similarity between the new query instruction and the corresponding standard response text.
[0110] In this embodiment of the disclosure, the text summary can be a summary of the core content of the standard response text, which can represent the purpose of the standard response text. The text summary of each standard response text in each standard text library can be obtained in advance, and a feature vector for each text summary can be obtained by extracting features from the text summaries. For example... Figure 5 As shown, Figure 5 This is a schematic diagram of a generative vector database provided in an embodiment of the present disclosure. First, the text summaries of each standard response text in the standard text library are performed to obtain a text summary corresponding to each standard response text. Then, feature extraction is performed on each text summary to obtain a feature vector of each text summary, which is the summary vector in the figure.
[0111] Optionally, a pre-trained language model (such as the BERT model) can be used to perform semantic embedding encoding on each text summary to obtain the feature vector of each text summary, or a large language model that can perform embedding encoding can be used for encoding.
[0112] In this embodiment of the disclosure, the feature vectors of standard response texts and corresponding text summaries can be stored in a standard text library according to a correspondence. Alternatively, the standard text library can store the correspondence between the standard response text, the text summary, and the feature vector of the text summary. Optionally, the standard response text library can be used to store standard response texts and corresponding text summaries. It can be constructed using a key-value pair storage system for text summaries and standard response texts, with the feature vectors of the text summaries additionally stored in a vector database to store different forms of data separately.
[0113] In this embodiment of the disclosure, the semantic similarity between the new query instruction and each standard response text can be determined by determining the similarity between the new query instruction and the text summaries of each standard text. Specifically, the feature vector of the new query instruction can be obtained by extracting features from the new query instruction in the same way as obtaining the feature vector of the text summaries. The semantic similarity between the feature vectors of the new query instruction and the text summaries of each standard response text can be determined by calculating pre-similarity and Euclidean distance similarity. Figure 6 As shown, Figure 6 This is a schematic diagram illustrating another method for determining candidate response text provided in an embodiment of this application. The semantic similarity between the instruction vector of the new query instruction and the summary vector of the text summary corresponding to the standard response text is calculated. The maximum semantic similarity, i.e., semantic similarity 5 in the diagram, is then determined. If semantic similarity 5 is greater than or equal to a preset threshold, then the standard response text 5 is selected as the candidate response text.
[0114] Optionally, the preset threshold can be set by technicians based on experience, and the preset threshold can be different for different preset domains. Furthermore, considering that the semantic similarity of two feature vectors obtained by different encoding methods is different, using a fixed value set by human experience as the preset threshold may result in poor performance of the candidate response texts.
[0115] Therefore, as an optional embodiment, the preset threshold can be determined in the following way: Retrieve multiple sample query instructions corresponding to the text creation task; Based on the text, create the model input format template corresponding to the task, rewrite the multiple sample query instructions respectively, and obtain the new sample instructions corresponding to each sample query instruction; For each new sample instruction, determine the semantic similarity between the new sample instruction and each standard response text in the standard text library, and take the standard response text with the highest semantic similarity as the reference response text for the new sample instruction; The preset threshold is determined based on the semantic similarity between each new sample instruction and its corresponding reference response text.
[0116] In this embodiment of the disclosure, a large instruction generation model can be used to generate sample query instructions for text creation tasks in multiple preset domains. The method of sampling and rewriting the initial query instructions can be used to rewrite each sample query instruction according to the model input format model, so as to obtain a new sample query instruction for each sample query instruction, which is then used as a new sample instruction.
[0117] The semantic similarity between each new sample instruction and each standard response text in the standard text library is determined. The standard response text with the highest semantic similarity is used as the reference response text for that sample instruction. Based on the semantic similarity between the new sample instruction and its respective reference response text, a preset threshold is determined. The method for determining semantic similarity can be the same as the method described earlier for determining the semantic similarity between the new query instruction and each standard response text. The method for obtaining the rewritten sample instruction corresponding to each sample query instruction can also be the method described earlier for rewriting the initial query instruction to obtain a new query instruction. For example, the sample query instruction and rewriting prompts can be input into a large-scale rewriting model, which then rewrites the sample query instruction according to the rewriting requirements (model input format template) in the rewriting prompt information to obtain a new sample instruction.
[0118] Specifically, multiple sample query commands (Query) are treated as a single command set. Each sample query instruction in the instruction set is rewritten one by one to generate a new instruction set. Use the new instruction set Each query is searched individually, and a similarity score set is constructed based on the maximum semantic similarity corresponding to each new query command. Based on the set of similarity scores, a preset threshold is determined.
[0119] like Figure 7 As shown, Figure 7This is a schematic diagram illustrating the determination of a preset threshold provided in an embodiment of this application. First, sample instructions related to text creation tasks in multiple preset domains are generated to construct an initial instruction set. For each sample instruction in the initial instruction set, each sample instruction is rewritten to obtain a new instruction set. For each new instruction, the semantic similarity between the new instruction and each standard response text in the standard text library is determined to obtain a semantic similarity set. The semantic similarity between the new instruction 'a' and standard response text 1 is denoted as semantic similarity a1. The semantic similarity between other new instructions and standard response texts is represented in the same way; for example, semantic similarity c2 is denoted as the semantic similarity between the new instruction 'c' and standard response text 2. For each new instruction, the maximum semantic similarity corresponding to that new instruction is selected, such as... Figure 7 As shown, the maximum semantic similarity corresponding to the new instruction a is the semantic similarity a2, that is, the semantic similarity between the new instruction a and the standard response text 2 is the maximum semantic similarity corresponding to the new instruction a. Based on the maximum semantic similarity corresponding to each new instruction, a preset threshold is determined.
[0120] Optionally, the semantic similarity corresponding to the maximum or minimum value in the similarity score set can be used as the preset threshold, or the average of the two can be used as the preset threshold, or the average of all semantic similarities in the similarity score set can be used as the preset threshold. In this embodiment of the disclosure, multiple sample query instructions are generated for the text creation task, and semantic matching is performed with the standard response text. Based on the matching results, a preset threshold is obtained statistically, without the need for manual specification of specific threshold values or manual debugging.
[0121] As an optional embodiment, the preset threshold is determined based on the semantic similarity between each new sample instruction and its respective reference response text, including: Each new sample instruction and its corresponding reference response text are shown to the reviewer, and feedback information is obtained from the reviewer regarding the reference response text for each new sample instruction. This feedback information indicates whether the reference response text is the answer to the corresponding new sample instruction. Based on the semantic similarity of each reference response text indicated by the feedback information, the preset threshold is determined.
[0122] In this embodiment, a preset threshold can be determined based on whether the reference response text corresponding to a new sample instruction can serve as the answer text for that new sample instruction. Specifically, the standard response text with the highest semantic similarity to the new sample instruction can be obtained as the reference response text. The new sample instruction and the reference response text are provided to the reviewer. The reviewer verifies whether the reference response text is the answer to the new sample instruction, and feedback information is obtained from the reviewer. Based on the feedback information, the semantic similarity of the reference response text corresponding to the new sample instruction is determined, and a preset threshold is determined based on the determined semantic similarity. The reviewer can be a technical personnel or a large language model with review capabilities.
[0123] Optionally, the minimum semantic similarity among the reference response texts that respond to "yes" can be determined as a preset threshold. For example... Figure 8 As shown, Figure 8 This is a schematic diagram illustrating another method for determining a preset threshold according to an embodiment of this disclosure. Figure 7 After obtaining the maximum semantic similarity for each new instruction using the method described in the previous section, for each new instruction, the standard response text corresponding to the maximum semantic similarity for that instruction is used as the reference response text for that new instruction, thus obtaining a set of reference response texts. It is then determined whether each reference response text can serve as the answer to the corresponding new instruction, and the reference texts that can serve as answers are selected, resulting in a set of filtered reference response texts. The corresponding semantic similarity is then further determined, and the minimum semantic similarity corresponding to the set of filtered reference response texts is used as a preset threshold.
[0124] Specifically, obtain the set of reference response texts corresponding to the new sample instructions. For each new sample instruction and corresponding reference response text Perform a relevance assessment to determine whether the reference response text can serve as an answer to a new sample instruction, with the answer being either yes or no. This assessment can be performed manually or using a large model. Further, the assessment result is denoted as... If the reference response text can serve as the answer to a new sample instruction, then ,otherwise .
[0125] Take all results that are judged as "relevant" ( ) corresponding The set of similarity scores that successfully matched the search results If a higher similarity score indicates a stronger correlation, then the minimum value of that set should be used. The threshold is used as the filtering threshold (i.e., the preset threshold); otherwise, the maximum value is taken. Used as a filtering threshold.
[0126] In this embodiment, a preset threshold is determined based on the semantic similarity of the reference response text that can serve as the answer to a new sample instruction. This makes the determined candidate response text more likely to be the answer to a new query instruction, thus improving the quality of the determined candidate response text. When the large language model determines that the candidate response text is the answer to a new query instruction, the candidate response text is output, thereby improving the efficiency and accuracy of determining the answer text to the question text.
[0127] As an optional embodiment, for each standard response text, the text summary of the standard response text is obtained in the following manner: According to the preset summary generation requirements, the text of the standard response is summarized to obtain a text summary of the standard response; wherein, the summary generation requirements indicate at least one content item to be included in the summary to be generated; For the text creation task, the model input format template indicates that the rewritten query instruction includes the content item corresponding to at least one content item.
[0128] In this embodiment of the disclosure, a summary generation requirement can be preset. Based on the summary generation requirement, the standard response text is summarized to obtain a text summary. Optionally, the summary generation requirement is used to require that the text summary to be generated includes at least estimated content items. The content items can be set according to a preset domain. Different preset domains may include different content items in the text summary.
[0129] Optionally, a large model (such as a summary generation model, which may or may not be the same as the large language model and intent recognition model used to generate the response text corresponding to the query instruction) can be used to summarize the standard response text to obtain a text summary of the standard response text. Specifically, prompt words can be preset, which are used to prompt the large model to generate a summary of the text input to the large model based on the summary generation requirements. Optionally, for each standard response text, the above prompt words, the standard response text, and the summary generation requirements can be input into the large model, and the large model will generate a text summary of the standard response text according to the summary generation requirements.
[0130] In this embodiment of the disclosure, when the task category corresponding to the question text to be processed is a text creation task in a preset domain, the model input template corresponding to that task category indicates that the rewritten query instruction includes the aforementioned content items. By rewriting the initial query instruction into a new query instruction corresponding to the format of the text summary, it is beneficial to more accurately determine the candidate response text corresponding to the question text from each text summary.
[0131] Optionally, as an example, when summarizing text, the summary generation requirements are: generate a text summary using the format "[Text Topic], [Text Content]" or generate a text summary including both the text topic and key text content. The model input format template corresponding to the text creation task is "Please help me generate / draft / write a [Text Topic], [Content Requirements]". The first part of this input format template uses the fixed sentence "Please help me generate / draft / write a" as the instruction trigger word, where the verb selection is determined according to the initial query instruction; the second part contains two parts, namely the text topic used to create the text and the content requirements for creating the text. These can be determined according to the initial query instruction. For example, if the initial query instruction is "My car was hit, can you help me draft a compensation contract?", the modified query instruction would be "Please help me draft a traffic accident compensation agreement for discussing compensation matters after my car was hit."
[0132] In this embodiment of the disclosure, the text format of the rewritten query instruction is similar to the text format of the text summary, which makes the text summary and the query instruction have a strong structural and semantic correspondence, which is beneficial to improving the matching quality.
[0133] As an optional embodiment, the target task includes at least one of the text creation task or the text editing task in the preset domain; In the case where the task category is determined to be a text editing task, the question text also includes historical text. Based on the model input format template, the initial query instruction is rewritten, including: Based on the model input format template corresponding to the text editing task, the initial query instruction is rewritten. The model input format template indicates that the rewritten query instruction includes the position to be edited in the historical text and the corresponding editing method.
[0134] In this embodiment of the disclosure, the query instruction corresponding to the text creation task in the preset domain is to request the large language model to generate text in the preset domain, and the query instruction corresponding to the text editing task in the preset domain is to request the large language model to modify the historical text and output the modified text. Both are text generation tasks. Since the expression of the initial query instruction in the question text obtained by the server may be unclear, it is necessary to modify the initial query instruction into a new query instruction with clear semantics.
[0135] In this embodiment of the disclosure, the model input format template corresponding to the text creation task in the preset domain has been described above. For the text editing task in the preset domain, the model input format template corresponding to the text editing task indicates that the rewritten query instruction includes the editable position in the historical text. For example, in the application scenario of the contract domain, the model input format template is "Please help me modify [edit position]". When rewriting, the position in the contract text that needs to be modified can be determined according to the initial query instruction, such as "the second clause in the contract", as the edit position, to obtain the modified query instruction. Optionally, the model input format template also indicates that the rewritten query instruction includes the editing method. In this case, the model input format template is "Please [specific operation], [edit position]". The operation can be the editing method, including deletion, addition, or modification. The specific editing method can also be determined according to the initial query instruction. For example, the initial query instruction is "Please modify the clause in the second clause that the cost of repairing the mobile phone shall be borne by Party A", and the modified query instruction is "Please modify the clause in the second clause that Party A shall bear the cost of repairing the mobile phone".
[0136] Optionally, when the task category is a text editing task in a preset domain, the initial query instruction can be modified based on historical text and model input format template, so as to modify the initial query instruction with reference to the specific content in the historical text.
[0137] In this embodiment of the disclosure, when the task category is a text editing task in a preset domain, the historical text, new query instructions, and response prompts in the question text are input into the large language model. The response prompts can be the same as those for text editing tasks in the preset domain, instructing the large language model to respond to the instructions input into the model. Optionally, different response prompts can be set according to the task category. The specific content of the response prompts for text creation tasks has been described above. The response prompts for text editing tasks in the preset domain can prompt the large language model to edit the input historical text according to the input query instructions. For example, it could be: "Your settings: You are a contract modification assistant; Contract to be modified: {BaseContract}; Your task: Add, delete, and modify contracts according to the user's modification opinions. Output the full text of the modified contract. For parts that do not need modification, please keep them unchanged. Please ensure that the format and sequence number of the modified contract are accurate. Note {OUTPUT_FORMAT}."
[0138] In this embodiment, different model input format templates are set for text creation tasks and text editing tasks, so that the large rewriting model can rewrite the initial query instruction according to the model input format template to obtain a new query instruction with clearer semantics. This is beneficial for the large language model to generate higher quality response text based on the new query instruction.
[0139] Optionally, a tag corresponding to the task category of the initial inquiry instruction can be added to the new inquiry instruction. Based on the pre-established correspondence between tags and prompt words, and between tags and templates, the prompt words or templates corresponding to the initial inquiry instruction can be obtained.
[0140] As an optional embodiment, different rewriting prompts can be preset for text creation tasks and text editing tasks respectively. The rewriting prompts are used to prompt the large model to rewrite the input query instructions according to the corresponding model input format template.
[0141] For example, the rewrite query instruction for a text creation task could be: "Assuming you are an extremely professional English and Chinese language expert, your task is: given a user's needs or questions, please rewrite the user's needs or questions into a fixed-format question, making the revised question more complete and clear."
[0142] Note: Always remember that your task is to generate independent questions, not to directly answer existing ones! Fixed-format questions: Please draft a [Generate Contract Name], [Generate Other Requirements]; if the input question includes limits on content length or word count, please do not include specific numbers when generating the new question; ensure the language of the questions remains consistent before and after reconstruction; ensure the meaning of the questions remains consistent before and after reconstruction. Below are some examples. Example input: Please help me rewrite my question: My car was hit, can you help me draft a contract? | Rewritten question: Example output: Please draft a traffic accident compensation agreement for me to discuss compensation matters after my car was hit. #Identify requirements and change to a fixed format. [Generate Contract Name] is [Traffic Accident Compensation Agreement]. [Generate Other Requirements] is [For discussing compensation matters after my car was hit]. Example input: Please help me rewrite my question: I want to buy a mobile phone, can you help me draft a contract? | Rewritten question: Example output: Please help me draft a mobile phone purchase contract for my mobile phone purchase. #Identify requirements and change to a fixed format [Generate Contract Name] to [Mobile Phone Purchase Contract] [Generate Other Requirements] to [For My Mobile Phone Purchase]".
[0143] The rewrite query instruction for the text creation task could be: "Assuming you are an extremely professional English and Chinese language expert, your task is: given a contract and a user's question, please rewrite the user's question into a specific format, making the revised question more complete and clear."
[0144] The rewritten problem needs to encompass two aspects: 1. Operations: such as drafting, expanding, deleting, modifying, adding, polishing, etc.
[0145] 2. Scope: For example, the first article, the first and second articles, the entire text, etc.
[0146] The rewritten question needs to have a fixed format: [{EDIT_FLAG}]<operation><scope><other content remains unchanged (optional)> Notice: Always remember that your task is to generate independent problems, not to directly modify the contract! Your task is to make the problem more independent and clear, and to explain the operations and scope more clearly (expanding, deleting a clause, modifying certain clauses, etc.).
[0147] Ensure that the language remains consistent before and after the reconstruction.
[0148] Ensure that the meaning of the problem remains consistent before and after reconstruction.
[0149] Here are a few examples: Example input: `Contract: ... IX. Supplementary Clauses ... | Issues to be polished: Please add more to the supplementary clauses | Issues after polishing:` Example output: `[{EDIT_FLAG}]. Add the content of Supplementary Clause 9 to the contract, keeping everything else unchanged. #Contract and issue related (identifying Supplementary Clause as Article 9), the issue is incomplete (no scope specified), so it has been supplemented to be more complete.
[0150] Example input: `Contract: (Related Contract) | Issues to be polished: Please help me revise the wording of the contract to be more precise | Issues after polishing:` Example output: `[{EDIT_FLAG}]. Polish the entire contract to make it more rigorous, while keeping the specific content of the contract unchanged. #The contract and the questions are related (the questions are broad and suitable for all contracts), and the questions are not complete (no scope is specified), so we supplement them to make them more complete."
[0151] To more clearly illustrate the text generation method provided in this disclosure, a complete embodiment of this disclosure is provided below. For example... Figure 9 As shown, Figure 9 A flowchart illustrating a text generation method provided in this disclosure includes: S301. Obtain the question text to be processed, including the initial query instruction; S302. Obtain the discrimination prompt information, input the discrimination prompt information and the question text into the intent recognition big model, and obtain the task category corresponding to the question text based on the intent recognition big model; The discrimination prompt information is used to identify the large model of the schematic diagram: it determines whether the initial query instruction is related to the preset domain and whether it is related to the text generation task. If neither is related, the task of the question text is classified as a non-target task. Otherwise, it determines whether there is historical text in the question text. If not, the task category of the question text is text creation task in the preset domain. Otherwise, it determines whether the initial query instruction is related to historical text. If not, the task category of the question text is text creation task in the preset domain. Otherwise, it is classified as a text creation task. If the task category is determined to be a text creation task, proceed with steps S303-S307; If the task category is determined to be a text creation task, proceed with steps S308-S309; S303. Obtain the rewriting prompt information corresponding to the text creation task, and rewrite the initial query instruction based on the rewriting prompt information to obtain the new query instruction; S304. Extract features from the new query command to obtain the feature vector of the new query command; S305. Obtain the standard text library and determine the semantic similarity between the feature vectors of the text summaries of the new query instruction and each standard response text in the standard text library; S306. Determine whether the maximum semantic similarity is greater than a preset threshold. If it is, then use the standard response text corresponding to the maximum semantic similarity as the candidate response text. S307. Obtain the response prompt information. Input the response prompt information, the new query instruction, and the candidate response text (if candidate response text exists) into the large language model to obtain the response text of the question text. S308. Obtain the rewriting prompt information corresponding to the text editing task, and rewrite the initial query instruction based on the rewriting prompt information to obtain the new query instruction; S309. Obtain the response prompt information. Input the response prompt information, new query instructions, and historical text into the large language model to obtain the response text to the question text.
[0152] like Figure 10 As shown, Figure 10This application provides a system architecture diagram for implementing a text generation method. The system architecture can be divided into two main modules: an intent recognition and refinement module and a retrieval and generation module. The system's input is a question text including an initial query instruction (Query). This question text may also include historical text; whether historical text is included depends on actual needs. The question text is input to the intent recognition and refinement module to obtain a more detailed new query (i.e., a new query instruction). Finally, the new query and historical text (optional) are input to the retrieval and generation module to obtain the generated text. Figure 10 The document provides sample texts for four questions, Sample 1 to Sample 4.
[0153] Specifically, the intent recognition refinement module consists of an intent classification module and two refinement query modules. The intent classification module categorizes queries into three types: create text, modify text, and irrelevant input. The refinement query modules are primarily used to systematically identify user intents and generate more precise queries. The input to the intent classification module is the user query and historical text. The process of the intent classification module is as follows: S1. Determine whether the user query is relevant to the vertical domain and the generated task. If irrelevant, classify it as "Category: Irrelevant Input"; otherwise, proceed to S2. S2. Determine if the historical text exists. If it does not exist, classify it as "Category: Create Text"; otherwise, proceed to S3. S3. Determine whether the user query and historical text are related. If they are not related, classify them as [Category: Create Text]; otherwise, classify them as [Category: Edit Text].
[0154] For input categorized as "Category: Create Text," the user query will be fed into the Create Detailed Query module for further analysis; its historical text (if any) will not participate in subsequent processes. For input categorized as "Category: Edit Text," both the user query and historical text will be fed into the Edit Detailed Query module for further analysis. For input categorized as "Category: Irrelevant Input," it will not proceed to subsequent processes.
[0155] The purpose of the refined query module is to transform diverse, colloquial queries provided by users into new queries that are more closely aligned with the specific text generation requirements. This is achieved by regenerating the user-input queries using a larger model. The core of this module lies in its systematic definition of the format and content of the generated new queries, ensuring the stability of the subsequent generated text.
[0156] Taking contract drafting as an example, user input may be more everyday and not specify the theme or content of the contract. Instead, they may focus on the subject matter and the problems they encounter. By refining the Query module, this can be transformed into a more systematic expression. Regardless of the quality of the user's input query, the quality of the generated text can be guaranteed to be at a good level.
[0157] The purpose of creating a refinement module (i.e., the Create-Refine Query module in the diagram) is to help the large model identify the requirements for the text topic and text content. The format of the refined new query is "Please help me generate / draft / write a [text topic], [content requirements]". [Text topic] is the title of the text, and [content requirements] are the personalized customization needs identified by the user.
[0158] The purpose of the editing refinement module (i.e., the Edit-Refine Query module in the diagram) is to identify the operation, scope (location) of the edited text, and whether other content has been changed. The format of the refined new Query is "[Operation][Scope][Other content remains unchanged (optional)]". [Operation] is the main operation of this edit, including expanding, deleting, modifying, adding, polishing, etc. [Scope] is the scope of the user's Query within the historical text. For example, the first item, the first and second items, the entire text, etc. [Other content remains unchanged (optional)] is the text that needs to be included when [Scope] is not the entire text. This prevents other parts from being rewritten by the larger model and ensures the stability of the editing function.
[0159] The retrieval generation module consists of a filtered retrieval module and two generation modules. The filtered retrieval module retrieves relevant vertical text, while the generation modules generate new vertical text from the new query and historical text.
[0160] The filter-enabled search module is used when a user's query is categorized as "Category: Create Text". This module receives a new query from the creation refinement module as input and outputs the retrieved vertical text (i.e., candidate response text, which may be empty).
[0161] This module consists of two steps: retrieval and filtering. The retrieval step searches for complete texts that most closely match the user's needs from existing vertical text data (i.e., a standard text library). The filtering step determines whether to discard retrieved text (set to empty).
[0162] The retrieval process involves a preparation process and an implementation process. The preparation process is as follows: For the referenced vertical text, a summarization model is used to generate multiple summaries. The summary format is "[Text Topic], [Text Content]". A storage system is constructed using summary-original vertical text as key-value pairs. A vector database is constructed using embedding encoding of the summaries.
[0163] The implementation process is as follows: a user query categorized as "Category: Created Text" is searched in a vector database to obtain the most similar summary and similarity score. This summary is then searched in a key-value database to obtain the corresponding original vertical category text, and the similarity score and the original vertical category text are returned.
[0164] The filtering process involves a preparation process and an implementation process. The preparation process is as follows: Use a large model to generate a collection of N intents to create a vertical text query set. The refinement module is used to rewrite each query in the query collection, generating a refined query collection. Use the search module to refine the query collection. Search each item individually to generate a set of similarity scores. Original vertical text collection For each refined query, and corresponding vertical text Perform a relevance assessment to determine whether the text within this vertical category can serve as an answer to the query, with a yes or no answer. This assessment can be done manually or using a large model. The assessment result is denoted as... If the vertical category text can be used as the answer to the query, then ,otherwise .
[0165] Take all results that are judged as "relevant" ( ) corresponding The set of similarity scores that successfully matched the search results If a higher similarity score indicates a stronger correlation, then the minimum value of that set should be used. Use the threshold as a filter threshold; otherwise, take the maximum value. Used as a filtering threshold.
[0166] The implementation process is as follows: The similarity score returned by the retrieval module is compared with the threshold. If a higher similarity score indicates stronger relevance, then the vertical text is discarded when the similarity score is below the threshold; if a lower similarity score indicates stronger relevance, then the vertical text is discarded when the similarity score is above the threshold.
[0167] If it is determined that the vertical text needs to be discarded, then return null; otherwise, return the retrieved vertical text.
[0168] For both the creation and editing generation modules, the purpose of the generation module is to generate vertically oriented text in a specified format. The system prompts for both generation modules must include: 1. The text generation requirements for the corresponding vertical field. 2. Fixed formatting requirements (e.g., HTML, Markdown, or other custom formats). Furthermore, the creation and editing modules receive different inputs. This module receives auxiliary data generated upstream as input, specifically: For the creation and generation module, it receives the new query output from the creation and refinement module as input. If the output of the filtered retrieval module is not empty, it will also be input into this module as reference text. The large language model is instructed to determine whether the reference text is suitable for the user's needs. If suitable, the format is modified to the specified format (e.g., HTML, Markdown, or other custom formats) and the content is used directly. If not suitable, the new text is generated based on the existing text.
[0169] For the editing and generation module, it receives the new Query output by the editing and refinement module as input, and the historical text is also input into this module as the text to be modified.
[0170] This retrieval generation module is used to combine prompts with upstream data and input them into a large model to generate vertical text in a specified format, which serves as the output of this module and also as the final output of the system.
[0171] The advantages of the text generation task provided in this disclosure are: it can generate text for various vertical domains without training a model, resulting in lower costs. The intent classification module categorizes user queries and controls the queries to enter different downstream processes, making the generation of vertical text more accurate; the query refinement module systematically sets the format and content of the generated new queries, making the generation of vertical text more stable. In this invention, for the retrieval module with filtering, its vector database construction uses summaries in the form of "[text topic], [text content]" to construct retrieval vectors, which are consistent with the target query format of the creation-refinement module ("Please help me generate / draft / write a [text topic], [content requirements]"), making the search for vertical text more accurate; its filtering threshold is not a fixed value, but is calculated based on the existing creation-refinement query module and vector database, ensuring that the method can adapt to different vertical databases and query scenarios.
[0172] The text generation method provided in this disclosure was tested in the scenario of drafting electronic signature product contracts. The comparative experimental results are shown in the table below:
[0173] Experiment Implementation Method: When the algorithm is invoked, either Experiment 1 or Experiment 2 will be randomly selected. Each time the algorithm is invoked, a random number between 0 and 1 will be generated. If 0 < random number <= 0.5, Method 1 will be used for text generation; if 0.5 <= random number < 1, Method 2 will be used. Users can provide feedback of "satisfied" or "unsatisfied" for each generated result. The selection of experiments and user feedback will be recorded.
[0174] The satisfaction formula in the experiment is: , in, This is the experiment number. Total number of calls To provide feedback on the number of "satisfactory" ratings, The number of calls that did not receive feedback. The weight for the neutral attitude (no feedback) is set to 0.5 here.
[0175] As can be seen from the table, the satisfaction level of the text generation method provided in this embodiment is higher than that of simply applying a large model with a suitable number of prompt words.
[0176] like Figure 11 As shown, Figure 11 Another system architecture diagram provided for embodiments of this disclosure.
[0177] This system architecture includes a user side and backend services. The backend services provide an interactive interface for users to interact with. Users can submit question text through the interface. After the request is verified by the authentication service, it is forwarded by the API gateway to the backend business cluster and algorithm cluster for processing, generating a response text, and returning it to the user through the interactive interface.
[0178] Specifically, the authentication service is responsible for authenticating user requests to ensure their legitimacy. The API gateway, as the system's entry point, processes and forwards user requests to the corresponding backend services. The backend business cluster includes multiple service instances responsible for handling business logic; this server cluster can centrally deploy large language models to implement intent recognition, instruction rewriting, and response text generation functions. The backend algorithm cluster contains multiple algorithm service instances responsible for executing complex algorithm tasks, such as intent recognition and semantic similarity calculation. Basic components provide the system's essential services. The configuration center manages the system's configuration information. The vector database stores feature vectors of text summaries of standard response texts for semantic similarity calculation. The KV database provides key-value pair storage services for standard response texts and text summaries. The log service records system operation logs. The message queue handles asynchronous message passing. MySQL is a relational database used for data storage. The search engine provides text search functionality. Object storage stores large files or object data.
[0179] This disclosure provides a text generation apparatus, such as... Figure 12 As shown, the text generation device 40 may include: a question text acquisition module 401, an intent recognition module 402, an instruction rewriting module 403, and a response text generation module 404, wherein, The problem text acquisition module 401 is used to acquire the problem text to be processed, wherein the problem text includes an initial query instruction; The intent recognition module 402 is used to perform task intent recognition on the question text and determine the task category corresponding to the question text from multiple candidate task categories. The multiple candidate task categories include target tasks or non-target tasks. The target task is a text generation task in a preset domain. The instruction rewriting module 403 is used to obtain the preset model input format template of the large language model corresponding to the task category when it is determined that the task category belongs to the target task, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction. Obtain a response prompt message, which instructs the large language model to respond to the query instructions from the input model; The response text generation module 404 is used to input the response prompt information and the new query instruction into the large language model, generate the response text corresponding to the new query instruction through the large language model, and use the response text as the response text to the question text.
[0180] The apparatus of this disclosure embodiment can execute the method provided in this disclosure embodiment, and its implementation principle is similar, and it has corresponding technical effects. The actions performed by each module in the apparatus of each embodiment of this disclosure correspond to the steps in the method of each embodiment of this disclosure. For a detailed functional description of each module of the apparatus, please refer to the description in the corresponding method shown above, and it will not be repeated here.
[0181] This disclosure provides an electronic device including a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to implement the steps of the method provided in any optional embodiment of this disclosure. Compared with the prior art, it can achieve the following: by performing task intent recognition on the acquired question text to be processed, the task category to which the question text belongs is determined; a model input format template for a text generation task in a preset domain is pre-set; when the task category of the question text to be processed is a text generation task in the preset domain, the model input format template is obtained, and the initial query instruction is rewritten based on the model input format template, so that the rewritten query instruction can more effectively guide the large language model to generate high-quality response text that meets the requirements of a specific domain, thereby effectively improving the professionalism and accuracy of the generated response content, and solving the problem of low text quality when generating text in a specific domain in the prior art.
[0182] In one alternative embodiment, an electronic device is provided, such as Figure 13 As shown, Figure 13 The illustrated electronic device 4000 includes a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, for example, via a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 4004 is not limited to one type, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of this disclosure.
[0183] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with this disclosure. Processor 4001 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0184] Bus 4002 may include a pathway for transmitting information between the aforementioned components. Bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 4002 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 13 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0185] The memory 4003 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.
[0186] The memory 4003 is used to store computer programs that execute embodiments of the present disclosure, and is controlled by the processor 4001 to execute them. The processor 4001 is used to execute the computer programs stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.
[0187] Among them, electronic devices include but are not limited to Figure 1 The terminal and server are described in the following embodiments. In some embodiments, the terminal is a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, smart voice interaction device, smart home appliance, vehicle terminal, etc., but is not limited thereto. Those skilled in the art will understand that the number of the above-mentioned terminals can be more or less. For example, there may be only one terminal, or there may be dozens or hundreds of terminals, or more. The embodiments of this disclosure do not limit the number and device type of the terminals. In some embodiments, the server is an independent physical server, or it may be a server cluster or distributed system composed of multiple physical servers, or it may be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. Server 20 is used to provide backend services for query and answering applications.
[0188] This disclosure provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.
[0189] This disclosure also provides a computer program product, including a computer program that, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.
[0190] It should be understood that although arrows indicate various operation steps in the flowcharts of the embodiments of this disclosure, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of the embodiments of this disclosure, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured as required, and the embodiments of this disclosure do not limit this.
[0191] The above description is only an optional implementation method for some implementation scenarios of this disclosure. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this disclosure without departing from the technical concept of this disclosure also fall within the protection scope of the embodiments of this disclosure.
Claims
1. A text generation method, characterized in that, The method includes: Obtain the question text to be processed, wherein the question text includes an initial query instruction; The task intent is identified by performing task intent recognition on the question text, and the task category corresponding to the question text is determined from multiple candidate task categories. The multiple candidate task categories include target tasks or non-target tasks, and the target task is a text generation task in a preset domain. If it is determined that the task category belongs to the target task, obtain the model input format template of the large language model corresponding to the task category, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction; Obtain a response prompt message, which is used to instruct the large language model to respond to the query command of the input model; The response prompt and the new query instruction are input into the large language model, and the response text corresponding to the new query instruction is generated by the large language model. The response text is then used as the response text to the question text.
2. The method according to claim 1, characterized in that, The step of performing task intent recognition on the question text and determining the task category corresponding to the question text from multiple candidate task categories includes: Obtain discrimination prompt information, which is used to indicate that the large schematic diagram recognition model recognizes the task intent of the query instruction of the input model, so as to determine the task category corresponding to the question text from the multiple candidate task categories; The discrimination prompt information and the question text are input into the intent recognition model, and the task category corresponding to the question text is obtained through the intent recognition model.
3. The method according to claim 2, characterized in that, The question text also includes historical text, which includes the historical interaction content between the target object and the large language model. The target object is the object that initiated the initial query instruction. The discrimination prompt information also indicates the intent recognition logic chain for the intent recognition big model to perform intent recognition, and the intent recognition logic chain includes: Determine whether the query command input to the model is related to the text generation of the preset domain; If it is irrelevant, output the first result, which indicates that the task category is a non-target task; If relevant, determine whether the task category is a text creation task or a text editing task based on whether the historical text and the query instructions are relevant; The target tasks include text creation tasks and text editing tasks within the preset domain.
4. The method according to any one of claims 1 to 3, characterized in that, The target task includes at least one of the text creation task or the text editing task in the preset domain; Where the task category is determined to be a text creation task, the method further includes: Obtain a standard text library, which stores multiple standard response texts for the preset domain; Determine the semantic similarity between the new query instruction and each standard response text in the standard text library; If there exists a standard response text with a semantic similarity greater than or equal to a preset threshold, then the standard response text with a semantic similarity greater than or equal to the preset threshold will be used as a candidate response text for the new query instruction. The step of inputting the response prompt information and the new query instruction into the large language model, and generating the response text corresponding to the new query instruction through the large language model, includes: The response prompt information, the new inquiry instruction, and the candidate response text corresponding to the new inquiry instruction are input into the large language model, and the response text corresponding to the new inquiry instruction is generated by the large language model.
5. The method according to claim 4, characterized in that, The standard text library also includes feature vectors of text summaries for each of the standard response texts; Determining the semantic similarity between the new query instruction and each standard response text in the standard text library includes: The new query instruction is subjected to feature extraction to obtain the feature vector of the new query instruction; Determine the semantic similarity between the feature vector of the new query instruction and the feature vector of the text summary of each standard response text, and use the semantic similarity corresponding to each text summary as the semantic similarity between the standard response text corresponding to the text summary and the new query instruction text.
6. The method according to claim 5, characterized in that, For each of the aforementioned standard response texts, the textual summary of the standard response text is obtained in the following manner: According to the preset summary generation requirements, the standard response text is summarized to obtain a text summary of the standard response text; wherein, the summary generation requirements indicate at least one content item to be included in the summary to be generated; Specifically, for the text creation task, the model input format template indicates that the rewritten query instruction includes the content items from at least one content item.
7. The method according to any one of claims 1-3, characterized in that, The step involves obtaining a preset model input format template for a large language model corresponding to the task category, and rewriting the initial query instruction based on the model input format template to obtain a new query instruction, including: Obtain the rewriting prompt information corresponding to the task category. The rewriting prompt information includes the model input format template corresponding to the task category. The rewriting prompt information is used to prompt the large model to rewrite the input query command according to the model input format template corresponding to the task category, provided that the semantics of the command before and after rewriting remain unchanged. The rewrite prompt information and the initial query instruction are input into the rewrite model, and a new query instruction is obtained through the rewrite model.
8. The method according to claim 4, characterized in that, The preset threshold is determined in the following way: Obtain multiple sample query instructions corresponding to the text creation task; Based on the model input format template corresponding to the text creation task, the multiple sample query instructions are rewritten to obtain a new sample instruction corresponding to each sample query instruction. For each new sample instruction, determine the semantic similarity between the new sample instruction and each standard response text in the standard text library, and take the standard response text with the highest semantic similarity as the reference response text for the new sample instruction; The preset threshold is determined based on the semantic similarity between each new sample instruction and its corresponding reference response text.
9. The method according to claim 8, characterized in that, The determination of the preset threshold based on the semantic similarity between each new sample instruction and its respective reference response text includes: Each new sample instruction and its corresponding reference response text are displayed to the reviewer, and feedback information from the reviewer is obtained for each new sample instruction and its corresponding reference response text. The feedback information indicates whether the reference response text is the answer to the corresponding new sample instruction. Based on the semantic similarity of each reference response text that is indicated as "yes" according to the feedback information, the preset threshold is determined.
10. The method according to claim 4, characterized in that, The response prompt information is used to instruct the large language model to determine whether there is a response text to the input model's query instruction in the input candidate response text. If there is, the corresponding candidate response text is output as the response text to the query instruction. If there is no response text, the response text corresponding to the query instruction is generated by referring to the candidate response text.
11. The method according to any one of claims 1 to 3, characterized in that, The target task includes at least one of the text creation task or the text editing task in the preset domain; In the case where the task category is determined to be a text editing task, the question text also includes historical text. The rewriting of the initial query instruction based on the model input format template includes: Based on the model input format template corresponding to the text editing task, the initial query instruction is rewritten, wherein the model input format template indicates that the rewritten query instruction includes the position to be edited in the historical text and the corresponding editing method.
12. A text generation device, characterized in that, The device includes: The question text acquisition module is used to acquire the question text to be processed, wherein the question text includes an initial query instruction; The intent recognition module is used to perform task intent recognition on the question text, and determine the task category corresponding to the question text from multiple candidate task categories. The multiple candidate task categories include target tasks or non-target tasks, and the target task is a text generation task in a preset domain. The instruction rewriting module is used to obtain a preset model input format template of a large language model corresponding to the task category when it is determined that the task category belongs to the target task, and rewrite the initial query instruction based on the model input format template to obtain a new query instruction. Obtain a response prompt message, which is used to instruct the large language model to respond to the query command of the input model; The module for generating response text is used to input the response prompt information and the new query instruction into the large language model, generate the response text corresponding to the new query instruction through the large language model, and use the response text as the response text to the question text.
13. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the method according to any one of claims 1-11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-11.
