Text generation method and device, electronic equipment and computer readable storage medium
By receiving text generation requests, matching prompt templates, inputting large language models to generate text, and performing format processing and sensitive word detection, it solves the problems of indiversity and lack of security detection in the existing technology, and achieves efficient and diverse and secure text generation.
Patent Information
- Application Number
- CN202411443775.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-02-07
AI Technical Summary
The prior art is difficult to generate diverse texts and lacks a security detection mechanism, resulting in low text generation efficiency and non-compliant content.
By receiving text generation requests, matching with pre-compiled prompt templates, inputting large language models to generate text, and performing formatting and sensitive word detection, ensuring that the generated text is diverse and safe.
It realizes diversified text generation, improves text generation efficiency, and ensures the compliance and professionalism of text content through sensitive word detection.
Smart Images

Figure CN119398167A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a text generation method, device, electronic device and computer-readable storage medium. Background Art
[0002] In the context of the rapid development of information technology, the demand for document processing is increasing. The document writing process is usually cumbersome and time-consuming, and requires professionals to manually complete the writing, proofreading and format adjustment according to different types of document requirements, which greatly restricts work efficiency.
[0003] At present, there are some document-assisted creation systems on the market. These systems usually combine big data technology and natural language processing (NLP) technology, and use pre-trained models such as BERT and large-scale corpora to realize intelligent error correction and review functions of text. By training the Bi-LSTM model based on word embedding, these systems can perform semantic analysis and language modeling to assist in text generation.
[0004] However, most existing technical solutions can only assist in generating a single type of text, lack the ability to generate diversified text, and are generally not equipped with security detection mechanisms. Summary of the invention
[0005] In view of this, the purpose of the present application is to provide a text generation method, device, electronic device and computer-readable storage medium to achieve diversified text generation and provide a security detection mechanism.
[0006] In a first aspect, the present invention provides a text generation method, comprising: receiving a text generation request, the text generation request including document type information; matching and / or integrating the information in the text generation request with a pre-compiled prompt template to obtain a prompt sentence corresponding to the document type information; inputting the prompt sentence into a large language model, and obtaining a first text corresponding to the document type information returned by the large language model, and formatting the first text to obtain a second text; traversing the second text through a pre-established sensitive word set, matching the characters of the second text with a pre-defined sensitive word set during the traversal process, and detecting sensitive words in the second text; and if no sensitive words are detected in the second text, sending the second text to a client.
[0007] In combination with the first aspect, an embodiment of the present application provides a first possible implementation of the first aspect, wherein the first text is in a formatted lightweight markup language format, and formatting the first text to obtain a second text includes: formatting the first text into a target format to obtain a second text.
[0008] In combination with the first possible implementation of the first aspect, the embodiment of the present application provides a second possible implementation of the first aspect, wherein the format conversion of the first text into a target format to obtain a second text includes: converting the first text into a text in HTML format; converting the text in HTML format into a second text in a target format.
[0009] In combination with the first possible implementation of the first aspect, an embodiment of the present application provides a third possible implementation of the first aspect, wherein the text generation request also includes typesetting information, and the format conversion of the first text into a target format to obtain a second text includes: generating a typesetting configuration file based on the typesetting information; format conversion of the first text into a target format text, and typeset the target format text through the typesetting configuration file to obtain a second text.
[0010] In combination with the first aspect, an embodiment of the present application provides a fourth possible implementation of the first aspect, wherein the method further includes: traversing the prompt sentence with the consciousness through a pre-established set of sensitive words, matching the characters of the prompt sentence with the pre-defined set of sensitive words during the traversal process, and detecting the sensitive words in the prompt sentence.
[0011] In combination with the first aspect, an embodiment of the present application provides a fifth possible implementation of the first aspect, wherein the text generation request also includes at least one of the following information: subject, summary, reference content, language style, and identity.
[0012] In combination with the first aspect or the first to fifth possible implementations of the first aspect, an embodiment of the present application provides a sixth possible implementation of the first aspect, wherein the sensitive word set is a dictionary tree, and the detection includes: performing sensitive word detection using a dictionary tree.
[0013] In combination with the first aspect or the first to fifth possible implementations of the first aspect, an embodiment of the present application provides a seventh possible implementation of the first aspect, wherein the method further includes: receiving user feedback information; and inputting the prompt sentence into a large language model, and obtaining a first text corresponding to the script type information returned by the large language model, including: inputting the prompt sentence and the historical feedback information into a large language model, and obtaining a first text corresponding to the script type information returned by the large language model.
[0014] In a second aspect, the present invention provides a text generation device, comprising: a request receiving unit, used to receive a text generation request, the text generation request including document type information; a prompt sentence generating unit, used to match and / or integrate the information in the text generation request with a pre-compiled prompt template to obtain a prompt sentence corresponding to the document type information; a text generation unit, used to input the prompt sentence into a large language model, and obtain a first text corresponding to the document type information returned by the large language model, and format the first text to obtain a second text; a detection and sending unit, used to traverse the second text through a pre-established sensitive word set, match the characters of the second text with a pre-defined sensitive word set during the traversal process, and detect sensitive words in the second text; and if no sensitive words are detected in the second text, send the second text to a client.
[0015] In combination with the second aspect, an embodiment of the present application provides a first possible implementation of the second aspect, wherein the first text is in a formatted lightweight markup language format, and the text generation unit includes a format conversion module for converting the first text into a target format to obtain a second text.
[0016] In combination with the first possible implementation of the second aspect, an embodiment of the present application provides a second possible implementation of the second aspect, wherein the format conversion module includes: a first conversion module, used to convert the first text into a text in HTML format; a second conversion module, used to convert the text in HTML format into a second text in a target format.
[0017] In combination with the first possible implementation of the second aspect, an embodiment of the present application provides a third possible implementation of the second aspect, wherein the text generation request also includes typesetting information, and the format conversion of the first text into a target format to obtain a second text includes: generating a typesetting configuration file based on the typesetting information; format conversion of the first text into a target format text, and typeset the target format text through the typesetting configuration file to obtain a second text.
[0018] In combination with the second aspect, an embodiment of the present application provides a fourth possible implementation of the second aspect, wherein the device also includes: a detection unit, used to traverse the prompt statement with the consciousness through a pre-established set of sensitive words, match the characters of the prompt statement with the pre-defined set of sensitive words during the traversal process, and detect sensitive words in the prompt statement.
[0019] In combination with the second aspect, an embodiment of the present application provides a fifth possible implementation of the second aspect, wherein the text generation request also includes at least one of the following information: subject, summary, reference content, language style, and identity.
[0020] In combination with the first aspect or the first to fifth possible implementations of the first aspect, an embodiment of the present application provides a sixth possible implementation of the first aspect, wherein the sensitive word set is a dictionary tree, and the detection and sending unit is also used to perform sensitive word detection using a dictionary tree.
[0021] In combination with the first aspect or the first to fifth possible implementations of the first aspect, an embodiment of the present application provides a seventh possible implementation of the first aspect, wherein the device also includes: a feedback receiving unit, used to receive user feedback information; and the text generation unit is also used to: input the prompt statement and the historical feedback information into a large language model, and obtain a first text returned by the large language model that corresponds to the script type information.
[0022] In a third aspect, the present invention provides an electronic device comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the text generation method described in any of the aforementioned embodiments are performed.
[0023] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the text generation method as described in any of the aforementioned embodiments are executed.
[0024] The text generation method, device, electronic device and computer-readable storage medium provided in the embodiment of the present application receive a text generation request including document type information, match and / or integrate the information in the text generation request with a pre-compiled prompt template, obtain a prompt sentence corresponding to the document type information, and input the prompt sentence into a large language model to obtain a first text corresponding to the document type information returned by the large language model. Compared with the prior art that can only generate text of a single document type, it can generate text of multiple documents, thus realizing the generation of diversified texts. In addition, through a pre-established sensitive word library, the second text is traversed, and during the traversal process, the characters of the second text are matched with a pre-defined set of sensitive words to detect sensitive words in the second text; and if no sensitive words are detected in the second text, the second text is sent to the client. Compared with the prior art solution without a security detection mechanism, it ensures the compliance and professionalism of the text content.
[0025] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 A flowchart of a text generation method provided in an embodiment of the present application is shown;
[0028] Figure 2 A flowchart of another text generation method provided in an embodiment of the present application is shown;
[0029] Figure 3 A schematic diagram of the structure of a text generation device provided in an embodiment of the present application is shown;
[0030] Figure 4 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0031] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0032] Taking into account the singleness and security risks of existing technical solutions, the embodiments of the present application provide a text generation method, device, electronic device and computer-readable storage medium, which are described below through embodiments.
[0033] To facilitate understanding of this embodiment, a text generation method disclosed in the embodiment of this application is first described in detail. Figure 1 The flowchart of the text generation method shown includes the following steps:
[0034] S101: receiving a text generation request, wherein the text generation request includes document type information.
[0035] In this embodiment, the text generation request may be received through a network connection (wired network or wireless network). The text generation request may be a requirement for text generation input by a user on a client device, including the type of document requested to be generated. The document types may include: notices, requests for instructions, reports, etc., and the embodiment of the present application does not limit the specific document types.
[0036] In some optional implementations of this embodiment, the text generation request may also include at least one of the following information: subject, summary, reference content, language style, and identity. Among them, the subject and summary can be used to clarify the subject and core content of the text, ensuring that the generated text is closely related to the central topic. The reference content can be a string content entered by the user, or a document attachment uploaded by the user, which can be used as a reference sample for subsequent text generation. Identity is used to define the identity of a virtual document writer, including his or her professional background, language style, and writing habits. By adding this information to the text generation request, the subsequently generated text can be more in line with the diversified requirements of users and can improve the quality of the generated text.
[0037] S102: Matching and / or integrating the information in the text generation request with a pre-compiled prompt template to construct a prompt sentence corresponding to the document type information.
[0038] In this embodiment, the corresponding prompt statement template can be prepared in advance for each language, and the prompt template corresponding to the language can be matched according to the language information in the received text generation request as a prompt statement. It is also possible to first match the corresponding prompt template according to the above-mentioned language information, and then bring the values of other information items in the text generation request into the predetermined position in the matched template to obtain the prompt statement. It is also possible to directly store each information item in the text generation request in the form of a variable in the prompt statement template, and then bring the values of each information item in the received text generation request into the corresponding variable to form the prompt statement. Among them, in addition to the information in the text generation request, the prompt statement can also include general requirements for the generated text, such as "the principles of seeking truth from facts, accuracy and standardization, simplicity and efficiency, and security and confidentiality should be adhered to", "the content is expressed in markdown format", etc., so as to improve the quality of the generated text.
[0039] In some optional implementations of this embodiment, after constructing the prompt statement, the consciousness can be traversed through the pre-established sensitive word library, and the characters of the prompt statement can be matched with a pre-defined sensitive word set during the traversal process to detect the sensitive words in the prompt statement. Among them, sensitive words can be collected in advance and a sensitive word set can be established. When performing the detection, the prompt statement can be pre-processed with text, such as word segmentation, etc. Then, a sensitive word matching algorithm (such as KMP algorithm, Boyer-Moore algorithm, etc.) is used to search for sensitive words in the prompt statement to obtain sensitive words and their position information. If there are sensitive words, the prompt statement can be reconstructed, or the sensitive words can be replaced. Thereby ensuring that no sensitive words are generated by the user in the subsequent generation process, and ensuring the quality of the generated text content.
[0040] S103: Input the prompt sentence into the large language model, obtain a first text corresponding to the script type information returned by the large language model, and perform format processing on the first text to obtain a second text.
[0041] In this embodiment, large language models are an important part of the field of natural language processing. They are based on deep learning algorithms, especially recurrent neural networks (RNNs), Transformers and other architectures, and can generate and understand human language. Large language models have a large number of parameters (usually in the millions or tens of millions, sometimes even billions), and can capture the complexity of language structure during training, thereby generating high-quality text.
[0042] In this embodiment, the prompt statement can be input into the large language model by calling the interface provided by the large language model, and the first text can be obtained by obtaining the return value of the interface. Since the prompt statement is generated according to the text type information in the text generation request, the prompt statement can include the text type requirements for the generated text, and the instruction information such as how the text type is written, so the large language model can output the first text that meets the user's requirements according to the prompt statement. When the above interaction with the large language model is performed, it can be one round of interaction or multiple rounds of interaction. For example, when generating the prompt statement, various requirements for the generated text can be included in the prompt statement, and then a high-quality first text can be obtained by interacting once. After the large language model generates the initial text, the large language model can be checked by two or more interactions to see whether the logic of the initial text is coherent and complete, and whether the style meets the requirements (such as formal, objective, etc.), and the initial text can be further adjusted according to the results of the volume check to obtain the first text. After obtaining the first text, the formatting of the first text can be to check whether its format and structure meet the requirements, or to perform typesetting processing on the first text. For example, check whether the first text is in Markdown format, or adjust it to Markdown format. Markdown is very concise, and almost all text editors and programming tools support Markdown format. Therefore, generating text in Markdown format can ensure that the text content can be seamlessly transferred and edited on various platforms, whether it is used for the final Word document, or directly viewed and modified in a Markdown-supported environment.
[0043] In some optional implementations of this embodiment, the first text can be a formatted lightweight markup language format, such as Markdown. Markdown provides basic structural elements, such as titles, lists, links, references, etc., which help maintain the logical structure and organization of the text. This makes it possible to more accurately apply the style and layout rules of the Word document according to the structure of Markdown during the subsequent format conversion process. Text in Markdown format is an efficient, flexible and practical method that provides good structure and convertibility while retaining the text content, helping to simplify subsequent formatting work. In addition to Markdown, it can also be ReStructuredText, AsciiDoc, Textile and other formats, which are not limited in this embodiment.
[0044] And, formatting the first text to obtain the second text may include: formatting the first text into a target format to obtain the second text. The target format may be a Word document format or other formats such as PDF. Taking the Markdown formatted text as an example, after generating the Markdown text, it can be converted into a Word or other format document through rules. Markdown provides clear text hierarchy and element identification, and the conversion process is controllable and accurate. The font, size, paragraph format and other layout settings of the second text can be predefined. During the conversion, the first text is converted according to the predefined layout settings to obtain a second text that matches the layout settings, thereby ensuring that the generated second text meets the actual requirements.
[0045] S104: Traversing the second text through a pre-established set of sensitive words, matching characters of the second text with a pre-defined set of sensitive words during the traversal process, and detecting sensitive words in the second text; and if no sensitive words are detected in the second text, sending the second text to the client.
[0046] In this embodiment, in order to ensure the compliance and professionalism of the final generated text, it is necessary to perform sensitive word detection on the second text. Sensitive words can be collected in advance and a sensitive word set can be established. When performing the detection, the second text can be preprocessed, such as word segmentation, etc. Then, a sensitive word matching algorithm (such as KMP algorithm, Boyer-Moore algorithm, etc.) is used to traverse it, and sensitive words are searched according to the sensitive word set to obtain sensitive words and their location information.
[0047] In an optional implementation of this embodiment, the above-mentioned sensitive word set can be a dictionary tree. The dictionary tree is an efficient string search data structure that can quickly find sensitive words. For longer texts or a large number of sensitive words, the use of a dictionary tree can speed up the matching process. The pre-collected sensitive words can be inserted into the dictionary tree. And, the sensitive word detection of the prompt statement and / or the second text may include: sensitive word detection using a dictionary tree (Trie tree). Among them, the characters in the prompt statement or the second text can be traversed, and the dictionary tree can be used for matching, so as to quickly find out the sensitive words and obtain their positions. The sensitive word detection of the prompt statement and / or the generated text through the dictionary tree reduces the string comparison, improves the query efficiency and accuracy, significantly reduces the query time, and improves the detection efficiency.
[0048] After the above detection, if no sensitive words are detected in the second text, the second text can be sent to the client device through a network connection so that the client device displays the second text content. If sensitive words are found, steps S103-S104 are re-executed until there are no sensitive words.
[0049] In an optional implementation of the present embodiment, the text generation method of the present embodiment may further include: receiving user feedback information. And in step 103, the prompt statement and the historical feedback information may be input into a large language model, and the first text corresponding to the text type information returned by the large language model may be obtained. Among them, the user's feedback information may be received in a text dialogue interaction manner. For example, after sending the second text content, the user enters a modification opinion on the second text on the client. After receiving the modification opinion, the second text may be regenerated according to the modification opinion, and the feedback information input by the user may be obtained again. Such interaction may be one round or multiple rounds. By receiving user feedback information, the large language model may be enabled to learn to improve the quality of the generated text. In step 103, the session information used when the user gives feedback may be input into the large language model, so that the large model may generate a higher quality first text according to the historical feedback information. Through this implementation, the generated text may be optimized according to the user's feedback and suggestions to meet the ever-changing usage requirements.
[0050] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings.
[0051] The text generation method provided in the embodiment of the present application receives a text generation request including document type information, matches and / or integrates the information in the text generation request with a pre-compiled prompt template, obtains a prompt sentence corresponding to the document type information, and inputs the prompt sentence into a large language model to obtain a first text corresponding to the document type information returned by the large language model. Compared with the prior art that can only generate text of a single document type, it can generate texts of multiple documents, thus realizing the generation of diversified texts. In addition, the second text is traversed through a pre-established sensitive word library, and the characters of the second text are matched with a pre-defined set of sensitive words during the traversal process to detect sensitive words in the second text; and if no sensitive words are detected in the second text, the second text is sent to the client. Compared with the prior art solution without a security detection mechanism, it ensures the compliance and professionalism of the text content.
[0052] Reference below Figure 2 , Figure 2 FIG. 2 shows a flowchart of another text generation method provided by an embodiment of the present application. Figure 2As shown, another text generation method provided by this embodiment includes:
[0053] S201: receiving a text generation request, wherein the text generation request includes document type information.
[0054] In this embodiment, the detailed description of step S201 may refer to the relevant part of step S101, which will not be repeated again.
[0055] S202: Match and / or integrate the information in the text generation request with a pre-compiled prompt template to obtain a prompt sentence corresponding to the document type information.
[0056] In this embodiment, the detailed description of step S202 may refer to the relevant part of step S102, which will not be repeated again.
[0057] S203: Input the prompt sentence into a large language model, and obtain a first text returned by the large language model and corresponding to the script type information.
[0058] In this embodiment, the detailed description of step S203 may refer to the relevant part of the first text generation in step S103, which will not be described again.
[0059] S204: Convert the first text into a text in HTML format.
[0060] In this embodiment, the first text is in a formatted lightweight markup language, such as Markdown, etc. A parsing library corresponding to the lightweight markup language (such as marked.js or showdown.js) can be used to convert the text in the lightweight markup language format into HTML format.
[0061] S205: Convert the text in HTML format into a second text in a target format.
[0062] In this embodiment, the target format can be Word format or other formats such as PDF. Among them, the docx library can be used to convert HTML format text into a Word document. The docx library is a powerful tool that allows customization of the content and format of a Word document.
[0063] In an optional implementation of this embodiment, the text generation request may also include typesetting information, and step S205 may include: generating a typesetting configuration file according to the typesetting information; converting the first text into a target format text, and typeset the target format text through the typesetting configuration file to obtain a second text. Among them, the typesetting information may include: font, size, paragraph format, title level, etc. The user can specify the typesetting information of the generated text on the client, and in step S205, the corresponding format template can be generated according to the typesetting information. When converting a Word document, the HTML format text is converted accordingly according to the format template through the docx library and converted into a Word format text corresponding to the typesetting information. This implementation method enables users to customize the typesetting information of the document and can flexibly generate text content in various formats on demand.
[0064] S206: Traversing the second text through a pre-established sensitive word library, matching characters of the second text with a pre-defined set of sensitive words during the traversal process, and detecting sensitive words in the second text; and if no sensitive words are detected in the second text, sending the second text to the client.
[0065] In this embodiment, the detailed description of step S206 may refer to the relevant part of step S104 and will not be repeated here.
[0066] The text generation method provided in this embodiment converts the first text into a text in HTML format and then converts the text in HTML format into a second text in a target format, thereby ensuring the consistency and accuracy of the document, improving the quality of the generated text in Word format, and enabling the generated second text to be better displayed in the browser of the client.
[0067] Based on the same technical concept, the embodiments of the present application also provide a text generation device, an electronic device, and a computer-readable storage medium, etc. For details, please refer to the following embodiments.
[0068] Figure 3 The structural diagram of a text generation device provided by an embodiment of the present application is shown. The functions implemented by the text generation device correspond to the steps of executing the above-mentioned text generation method. The device can be understood as a component of a server including a processor, and the component can implement the above-mentioned text generation method. As shown in the figure, the text generation device may include: a request receiving unit 301, a prompt sentence generating unit 302, a text generating unit 303, and a detection sending unit 304.
[0069] The request receiving unit 301 is used to receive a text generation request, wherein the text generation request includes document type information.
[0070] The prompt generation unit 302 is used to match and / or integrate the information in the text generation request with the pre-compiled prompt template to obtain a prompt sentence corresponding to the text type information.
[0071] The text generation unit 303 is used to input the prompt sentence into the large language model, obtain the first text corresponding to the script information returned by the large language model, and perform format processing on the first text to obtain a second text.
[0072] The detection and sending unit 304 is used to traverse the second text through a pre-established sensitive word library, match the characters of the second text with a pre-defined set of sensitive words during the traversal process, and detect sensitive words in the second text; and if no sensitive words are detected in the second text, send the second text to the client.
[0073] In this embodiment, the execution logic of the request receiving unit 301, the prompt sentence generating unit 302, the text generating unit 303, and the detection sending unit 304 can respectively refer to the above-mentioned detailed description of steps S101 to S104, which will not be repeated here.
[0074] In some optional implementations of this embodiment, the first text is in a formatted lightweight markup language format, and the text generation unit 303 includes a format conversion module for converting the first text into a target format to obtain a second text.
[0075] In some optional implementations of this embodiment, the format conversion module may include: a first conversion module, used to convert the first text into a text in HTML format; a second conversion module, used to convert the text in HTML format into a second text in a target format. The execution logic and technical effects of the first conversion module and the second conversion module can be referred to Figure 2 The relevant contents of step S204 and step S205 in the corresponding method are not repeated here.
[0076] In some optional implementations of this embodiment, the text generation device of this embodiment may further include: a detection unit, which is used to traverse the prompt sentence with the consciousness through a pre-established sensitive word library, match the characters of the prompt sentence with a pre-defined sensitive word set during the traversal process, and detect the sensitive words in the prompt sentence. The detailed description and technical effects of this implementation method can be referred to Figure 1 The relevant description of the corresponding implementation method of step S102 in the corresponding method will not be repeated here.
[0077] In some optional implementations of this embodiment, the text generation request may also include at least one of the following information: subject, summary, reference content, language style, and identity. Among them, the subject and summary can be used to clarify the subject and core content of the text to ensure that the generated text is closely related to the central topic. The reference content can be a string content entered by the user or a document attachment uploaded by the user, which can be used as a reference sample for subsequent text generation. Identity is used to define the identity of a virtual document writer, including his or her professional background, language style, and writing habits. By adding this information to the text generation request, the subsequently generated text can be more in line with the diversified requirements of users and can improve the quality of the generated text.
[0078] In some optional implementations of this embodiment, the sensitive word set is a dictionary tree, and the detection sending unit 304 and the detection unit can also be used to detect sensitive words in a dictionary tree manner. Among them, the dictionary tree is an efficient string search data structure that can quickly find sensitive words. For longer texts or a large number of sensitive words, the use of a dictionary tree can speed up the matching process. The pre-collected sensitive words can be inserted into the dictionary tree, and then the prompt statement or the second text is traversed and matched using the dictionary tree to find the sensitive words and obtain their positions. The sensitive word detection of the prompt statement and / or generated text through the dictionary tree reduces string comparison, improves query efficiency and accuracy, significantly reduces query time, and improves detection efficiency.
[0079] In some optional implementations of this embodiment, the text generation device of this embodiment may further include: a feedback receiving unit, configured to receive user feedback information. And the text generation unit 303 may also be configured to input the prompt sentence and the historical feedback information into a large language model, and obtain the first text corresponding to the language type information returned by the large language model. The specific description and technical effects of this implementation method can be referred to Figure 1 The relevant contents of the corresponding implementation methods in the corresponding methods will not be repeated here.
[0080] The text generation device provided in the embodiment of the present application receives a text generation request including document type information through a request receiving unit 301, and matches and / or integrates the information in the text generation request with a pre-compiled prompt template through a prompt sentence generation unit 302 to obtain a prompt sentence corresponding to the document type information, and then inputs the prompt sentence into a large language model through a text generation unit 303 to obtain a first text corresponding to the document type information returned by the large language model. Compared with the prior art that can only generate text of a single document type, it can generate texts of multiple documents, thus realizing the generation of diversified texts. In addition, the detection and sending unit 304 traverses the second text through a pre-established sensitive word library, matches the characters of the second text with a pre-defined sensitive word set during the traversal process, and detects sensitive words in the second text; and if no sensitive words are detected in the second text, the second text is sent to the client. Compared with the prior art solution without a security detection mechanism, it ensures the compliance and professionalism of the text content.
[0081] Reference below Figure 4 , Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application includes: a processor 401, a memory 402 and a bus 403, wherein the memory 402 stores machine-readable instructions executable by the processor 401. When the electronic device runs the above-mentioned text generation method, the processor 401 communicates with the memory 402 via the bus 403, and the processor 401 executes the machine-readable instructions to perform Figure 1 The method steps described in the method of the corresponding embodiment.
[0082] The present application also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor when the processor is running. Figure 1 The method steps described in the text generation method of the corresponding embodiment.
[0083] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0084] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0085] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0086] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0087] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0088] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A text generation method, characterized in that: include: receiving a text generation request, wherein the text generation request includes document type information; Matching and / or integrating the information in the text generation request with a pre-compiled prompt template to obtain a prompt sentence corresponding to the document type information; Inputting the prompt sentence into the large language model, obtaining a first text corresponding to the script information returned by the large language model, and performing format processing on the first text to obtain a second text; The second text is traversed by using a pre-established sensitive word set, and during the traversal process, characters of the second text are matched with a pre-defined sensitive word set to detect sensitive words in the second text; And if no sensitive word is detected in the second text, sending the second text to the client.
2. The method according to claim 1, characterized in that The first text is formatted in a lightweight markup language format, and The performing format processing on the first text to obtain a second text comprises: The first text is formatted into a target format to obtain a second text.
3. The method according to claim 2, characterized in that The step of converting the first text into a target format to obtain a second text includes: Converting the first text into text in HTML format; The text in the HTML format is converted into a second text in a target format.
4. The method according to claim 1, characterized in that: The method also includes: traversing the prompt sentence with the consciousness through a pre-established sensitive word set, matching the characters of the prompt sentence with the pre-defined sensitive word set during the traversal process, and detecting the sensitive words in the prompt sentence.
5. The method according to claim 1, characterized in that The text generation request also includes at least one of the following information: subject, summary, reference content, language style, and identity.
6. The method according to claims 1-5, characterized in that: The sensitive word set is a dictionary tree, and The detection includes: using a dictionary tree method to perform sensitive word detection.
7. The method according to claims 1-5, characterized in that: The method further includes: receiving user feedback information; and The step of inputting the prompt sentence into a large language model and obtaining a first text returned by the large language model and corresponding to the script type information includes: The prompt sentence and the historical feedback information are input into a large language model, and a first text corresponding to the script type information returned by the large language model is obtained.
8. A text generation device, characterized in that: include: A request receiving unit, used for receiving a text generation request, wherein the text generation request includes document type information; A prompt sentence generating unit, used for matching and / or integrating the information in the text generation request with a pre-compiled prompt sentence template to obtain a prompt sentence corresponding to the text type information; A text generation unit, configured to input the prompt sentence into a large language model, obtain a first text corresponding to the script type information returned by the large language model, and perform format processing on the first text to obtain a second text; A detection and sending unit, configured to traverse the second text through a pre-established sensitive word set, match characters of the second text with a pre-defined sensitive word set during the traversal process, and detect sensitive words in the second text; And if no sensitive word is detected in the second text, sending the second text to the client.
9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the text generation method as described in any one of claims 1 to 7 are performed.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the text generation method as claimed in any one of claims 1 to 7.