Text output method and device
By detecting, classifying and rewriting the initial problem text, generating the target problem text and inputting a large language model, the problem of difficulty in reducing data usage and training costs in the prior art is solved, and the security and positiveness of the output text are improved.
Patent Information
- Application Number
- CN202311754119.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-19
- Publication Date
- 2025-06-20
AI Technical Summary
In the training of large language models, it is difficult to effectively reduce the amount of data usage and training costs, while improving the security of output text. Especially when dealing with sensitive problems, it is difficult to guide the output into a positive and positive direction.
By detecting and classifying the initial question text entered by the user, obtaining its intent category and sensitive category. If the preset rewrite conditions are met, the initial question text is rewritten, the prompt text is added to generate the target question text, and input it into the large language model to generate positive reply text.
This reduces the data usage during model training, reduces the training cost, and improves the security and positiveness of the output text, avoiding the problem of requiring massive text data to train the model in the prior art.
Smart Images

Figure CN120181085A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data processing, and in particular to a text output method and device. Background Art
[0002] With the development of relevant technologies, large language models have made great progress in text generation capabilities; for user speech, they can output text that is quite close to human. However, users sometimes enter some sensitive questions, such as asking some biased questions or consulting some mental health issues. When the language model responds to the above sensitive questions, if it responds according to the original strategy and fails to give users positive feedback, it is very likely to deepen the user's bias or bring other negative effects; therefore, it is necessary to guide the topic in a positive and active direction.
[0003] Model training for large languages mainly includes two stages: pre-training and fine-tuning. To address the above issues, existing technical solutions usually optimize the security of training data during the fine-tuning stage: for those inputs that may result in the output of unsafe text, corresponding safe outputs are constructed as training data to avoid outputting risky text as much as possible.
[0004] However, due to the wide range of text sources and huge text size in the pre-training stage of large models, unsafe components are difficult to detect. Such risks will be carried over to the fine-tuning stage, affecting the security of the final output text. If you want to avoid this risk, you need to construct a massive amount of data for confrontation, which is obviously unacceptable. Therefore, how to reduce the amount of data used in model training, reduce the training cost of the language model, and improve the security of the output text has become an urgent problem to be solved. Summary of the invention
[0005] In view of this, an embodiment of the present application provides a text output method and device for reducing the amount of data used in model training, reducing the training cost of the language model, and improving the security of the output text.
[0006] In a first aspect, an embodiment of the present application provides a text output method, comprising:
[0007] Get the initial question text entered by the user;
[0008] Detect and classify the initial question text to obtain a first category and a second category corresponding to the initial question text; the initial question text includes sensitive content; the first category is the intention category corresponding to the initial question text; the second category is the sensitive category corresponding to the initial question text;
[0009] If the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, the initial problem text is rewritten to obtain a target problem text; the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text.
[0010] Input the target problem text into the large language model to obtain the target response text and output it.
[0011] As an optional implementation manner of an embodiment of the present application, after obtaining the first category and the second category corresponding to the initial problem text, the method further includes:
[0012] Judge whether the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions;
[0013] If the first category and the second category do not meet the preset rewriting conditions, output a preset response text. As an optional implementation manner of an embodiment of the present application, before obtaining the target response text and outputting it, the method further includes:
[0014] Detect the target response text to judge whether the target response text contains sensitive content;
[0015] If not, output the target response text;
[0016] If so, output a preset response text.
[0017] As an optional implementation manner of an embodiment of the present application, the step of, if the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, rewriting the initial problem text to obtain a target problem text includes:
[0018] According to the second category corresponding to the initial problem text, and in combination with the corresponding relationship between the second category and the prompt text, obtain the prompt text corresponding to the initial problem text;
[0019] Based on the initial problem text and the prompt text corresponding to the initial problem text, obtain the target problem text.
[0020] As an optional implementation manner of an embodiment of the present application, the step of detecting and classifying the initial problem text to obtain the first category and the second category corresponding to the initial problem text includes:
[0021] Perform semantic detection on the initial problem text to obtain the semantics corresponding to the initial problem text;
[0022] Obtain a first category and a second category corresponding to the initial problem text according to the semantics corresponding to the initial problem text.
[0023] As an optional implementation manner of an embodiment of the present application, the obtaining a first category and a second category corresponding to the initial problem text according to the semantics corresponding to the initial problem text includes:
[0024] Combine the semantics corresponding to the initial problem text, perform text classification on the initial problem text according to a first preset classification criterion, and obtain the first category corresponding to the initial problem text;
[0025] Combine the semantics corresponding to the initial problem text, perform text classification on the initial problem text according to a second preset classification criterion, and obtain the second category corresponding to the initial problem text.
[0026] In a second aspect, an embodiment of the present application provides a text output device, including:
[0027] An acquisition unit, configured to acquire an initial problem text input by a user;
[0028] A detection unit, configured to perform detection and classification on the initial problem text to obtain a first category and a second category corresponding to the initial problem text; sensitive content is included in the initial problem text; the first category is an intention category corresponding to the initial problem text; the second category is a sensitive category corresponding to the initial problem text;
[0029] A rewriting unit, configured to rewrite the initial problem text to obtain a target problem text when the first category and the second category corresponding to the initial problem text meet a preset rewriting condition; the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt a large language model to generate a positive target reply text;
[0030] An output unit, configured to input the target problem text into the large language model to obtain the target reply text and output it.
[0031] As an optional implementation manner of an embodiment of the present application, the text output device further includes a determination unit. After obtaining the first category and the second category corresponding to the initial problem text, the determination unit is specifically configured to determine whether the first category and the second category corresponding to the initial problem text meet a preset rewriting condition; if the first category and the second category do not meet the preset rewriting condition, then output a preset reply text.
[0032] As an alternative implementation manner of an embodiment of the present application, the detection unit is further configured to detect the target response text before obtaining and outputting the target response text. Specifically, the detection unit is configured to detect the target response text to determine whether the target response text contains sensitive content; if not, output the target response text; if so, output a preset response text.
[0033] As an alternative implementation manner of an embodiment of the present application, the rewriting unit is specifically configured to obtain the prompt text corresponding to the initial question text according to the second category corresponding to the initial question text and in combination with the corresponding relationship between the second category and the prompt text; and obtain the target question text based on the initial question text and the prompt text corresponding to the initial question text.
[0034] As an alternative implementation manner of an embodiment of the present application, the detection unit is specifically configured to perform semantic detection on the initial question text to obtain the semantics corresponding to the initial question text; and obtain the first category and the second category corresponding to the initial question text according to the semantics corresponding to the initial question text.
[0035] As an alternative implementation manner of an embodiment of the present application, the detection unit is specifically configured to classify the initial question text according to a first preset classification standard in combination with the semantics corresponding to the initial question text to obtain the first category corresponding to the initial question text; and classify the initial question text according to a second preset classification standard in combination with the semantics corresponding to the initial question text to obtain the second category corresponding to the initial question text.
[0036] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor, where the memory is used to store a computer program; and the processor is configured to cause the electronic device to implement the text output method described in any one of the above embodiments when executing the computer program.
[0037] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a computing device, the computing device is caused to implement the text output method described in any one of the above embodiments.
[0038] In a fifth aspect, an embodiment of the present application provides a vehicle, including: the text output device described in the second aspect or the electronic device described in the third aspect.
[0039] The text output method provided by the embodiments of this application is specifically as follows: First, the initial problem text is detected and classified to obtain the first category and the second category corresponding to the initial problem text; the initial problem text includes sensitive content; the first category is the intention category corresponding to the initial problem text; the second category is the sensitive category corresponding to the initial problem text; if the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, then the initial problem text is rewritten to obtain the target problem text; the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text; the target problem text is input into the large language model to obtain the target response text and output it. By classifying and detecting the initial problem text containing sensitive content at the input problem stage, the embodiments of this application determine whether to rewrite the initial problem text. The target problem text obtained through rewriting enables the subsequent large language model to obtain a more secure, positive, and active target response text according to the prompt text in the target problem text. At the same time, it is no longer necessary to collect a large amount of text data to train the model to generate a more positive response text. Therefore, the embodiments of this application can avoid the problem of requiring a large amount of text data to train the model in the prior art. Furthermore, the embodiments of this application can reduce the training cost of the language model and improve the security of the output text. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application and, together with the specification, are used to explain the principles of the present application.
[0041] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0042] Figure 1 It is one of the step flowcharts of the text output method provided by the embodiments of the present application;
[0043] Figure 2 It is the second step flowchart of the text output method provided by the embodiments of the present application;
[0044] Figure 3 It is the framework schematic diagram of the text output method provided by the embodiments of the present application;
[0045] Figure 4 It is the structural schematic diagram of the text output device provided by the embodiments of the present application;
[0046] Figure 5 Schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present application. Specific embodiments
[0047] In order to more clearly understand the above-mentioned objects, features and advantages of the present disclosure, the solutions of the present disclosure will be further described below. It should be noted that, without conflict, the embodiments of the present disclosure and the features in the embodiments may be combined with each other.
[0048] In the following description, many specific details are set forth in order to fully understand the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only a part of the embodiments of the present disclosure, rather than all the embodiments.
[0049] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the embodiments of the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of the words "exemplary" or "for example" is intended to present related concepts in a specific manner. In addition, in the description of the embodiments of the present application, unless otherwise specified, the meaning of "a plurality" refers to two or more.
[0050] It should be noted that in this article, the term "comprising" or any other variant thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0051] With the development of related technologies, large language models have made great progress in text generation capabilities; for users' remarks, they can output text quite close to that of humans. However, users sometimes input some sensitive questions, such as asking some questions with prejudice and discrimination; or consulting some mental health problems. When the language model replies according to the above-mentioned sensitive questions, if it replies according to the original strategy, it cannot give users positive feedback, and it is very likely to deepen users' prejudice and discrimination, or bring other negative impacts; therefore, it is necessary to guide the topic in a positive and active direction.
[0052] Model training for large languages mainly includes two stages: pre-training and fine-tuning. To address the above issues, existing technical solutions usually optimize the security of training data during the fine-tuning stage: for those inputs that may result in the output of unsafe text, corresponding safe outputs are constructed as training data to avoid outputting risky text as much as possible.
[0053] However, due to the wide range of text sources and huge text size in the pre-training stage of large models, it is difficult to detect unsafe components in them. Such risks will be brought to the fine-tuning stage, resulting in the security of the final output text being affected. If you want to avoid this risk, you need to construct a huge amount of data for confrontation, which is obviously unacceptable. Therefore, how to reduce the amount of data used in model training, reduce the model burden, and improve training efficiency has become an urgent problem to be solved.
[0054] In order to solve the above problems, the present application proposes a text output method, which is described in conjunction with the following embodiments.
[0055] Based on the above content, the present application embodiment provides a text output method, referring to Figure 1 As shown, the text output method includes the following steps S101 to S104:
[0056] S101. Obtaining an initial question text input by a user.
[0057] Currently, users can chat with artificial intelligence through dialogue applications set up on various devices. Users can enter their own question text into a preset text box so that the language model can obtain the question text; or they can wake up the corresponding smart assistant through voice, and the user can directly speak the question text in voice. The language model obtains the user's question text by analyzing the user's voice, and then generates a corresponding reply based on the question text and feeds it back to the user, thereby realizing a dialogue with the user.
[0058] S102: Detect and classify the initial question text to obtain a first category and a second category corresponding to the initial question text.
[0059] The initial question text includes sensitive content; the first category is the intention category corresponding to the initial question text; and the second category is the sensitive category corresponding to the initial question text.
[0060] In some embodiments, after obtaining the initial question text input by the user, the initial question text needs to be preprocessed. The preprocessing may include text segmentation, removal of stop words (including punctuation, numbers and some meaningless words), word sense disambiguation, converting the original text data into a format suitable for model input, etc., so as to facilitate subsequent detection and analysis of the initial question text and improve accuracy.
[0061] Among them, the initial problem text corresponds to the problem raised by the user. Exemplarily, the intention corresponding to the initial problem text may be: asking for comments on a certain discriminatory view, or expressing a view with swear words and insults; the intention categories may include but are not limited to: asking for facts, requesting comments, and the subjective views of users, etc.; the sensitive categories may include but are not limited to: discrimination, mental health, swear words and insults, etc.; after receiving the problem text input by the user, the problem text is detected and analyzed to obtain the intention category and sensitive category of the problem text respectively.
[0062] In some embodiments, detecting and classifying the initial problem text to obtain the first category and the second category corresponding to the initial problem text is to obtain which intention category the initial problem text belongs to, as well as the sensitive category, so as to subsequently determine whether the initial text problem is safe according to the intention category and sensitive category of the initial problem text. If it is not safe, the initial problem text is rewritten.
[0063] S103. If the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, then rewrite the initial problem text to obtain the target problem text.
[0064] Among them, the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text.
[0065] In some embodiments, after obtaining the first category and the second category of the problem text, it can be determined whether to rewrite the problem text based on the first category and the second category corresponding to the problem text according to a preset strategy. Among them, the preset strategy can be to set corresponding response strategies for the first category and the second category corresponding to different problem texts according to a large amount of text data, that is, the first category and the second category corresponding to the problem text are used together to determine the strategy for the user to answer the problem text.
[0066] Specifically, the response strategy may include: after rewriting the problem text, then using the language model to obtain the response text; or if the problem text involves a violation or a serious field, directly output the preset response text.
[0067] Referring to Table 1 shown below, it is a schematic diagram of a table of the first type, the second type of the problem text, and the corresponding response strategy:
[0068] Table 1
[0069]
[0070] Exemplarily, when a user expresses an opinion involving swear words and insults, the corresponding intention category is: the opinion expressed by the user, and the corresponding sensitive category is: swear words and insults.
[0071] In some embodiments, if it is determined according to the first category and the second category that the reply strategy for the current problem text is a model reply, it indicates that the problem text involves sensitive aspects and has risks. Then, the problem text needs to be rewritten to guide the model reply in a positive direction. In the embodiments of the present application, corresponding prompt texts are set for different sensitive categories. The prompt texts are mainly used to prompt the model to make a positive and active reply to the initial problem text, and to avoid negative content in the reply text output by the model.
[0072] After obtaining the prompt text corresponding to the initial problem text, the prompt text is combined with the corresponding initial problem text to obtain the target problem text. Then, the language model is used to obtain the reply corresponding to the target problem text, thereby guiding the language model to generate a more positive and active reply text to ensure the security of the reply generated by the language model.
[0073] Optionally, the specific implementation method for rewriting the initial problem text to obtain the target problem text in step S102 above can refer to the following steps 1 and 2:
[0074] Step 1: According to the second category corresponding to the initial problem text, and in combination with the corresponding relationship between the second category and the prompt text, obtain the prompt text corresponding to the initial problem text.
[0075] Step 2: Based on the initial problem text and the prompt text corresponding to the initial problem text, obtain the target problem text.
[0076] In some embodiments, a large amount of text data is analyzed to obtain multiple second categories (risk categories), and corresponding prompt texts are respectively set for the multiple second categories to generate the preset corresponding relationship, which is convenient for obtaining the corresponding prompt text according to the initial problem text in the subsequent process to generate the target problem text.
[0077] Exemplarily, when the initial question text input by the user is: Do you support prejudice and discrimination?, after detection and analysis, the first category (intention category) corresponding to the initial question text is: Request for comment; the second category (risk category) is: Discrimination and prejudice. Then, obtain the prompt text corresponding to the question text regarding discrimination and prejudice from the preset correspondence. The prompt text can be: "Request a response to remarks on discrimination and prejudice. The output response should be positive, reflecting non - support for discrimination and prejudice, and calling on everyone to be united and equal." Then, combine the prompt text with the initial question text to obtain the target question text. After combination, the target question text is specifically "Request a response to remarks on discrimination and prejudice. The output response should be positive, reflecting non - support for discrimination and prejudice, and calling on everyone to be united and equal. + Do you support prejudice and discrimination?". Then, input the finally obtained target question text into the language model to obtain the target response text and output it.
[0078] S104. Input the target question text into the large - language model to obtain the target response text and output it.
[0079] In some embodiments, the implementation method for obtaining the target response text and outputting it can be: Parse and reason the target question text through the large - language model to obtain the response text of the target question text.
[0080] Among them, the large - language model (Large Language Model, LLM) refers to those language models trained on large - scale text corpora and containing tens of billions of (or more) parameters. For example, the third - generation general pre - trained Transformer (Generative Pre - trained Transformer 3, GPT - 3), Pathways language model (Scaling Language Modeling with Pathways, PaLM), etc. Currently, large - language models adopt a similar Transformer architecture and pre - training objectives (such as Language Modeling) as small models. The main difference from small models lies in increasing the model size, training data, and computing resources.
[0081] Exemplarily, when the initial question text is: Do you support prejudice and discrimination?, the target question text can be "Request a response to remarks on discrimination and prejudice. The output response should be positive, reflecting non - support for discrimination and prejudice, and calling on everyone to be united and equal" plus the initial question text: "Do you support prejudice and discrimination?". After analysis and reasoning by the large - language model, obtaining the target response text and outputting it can be: I cannot support racial discrimination. The pursuit of equality for all is my goal.
[0082] The text output method provided by the embodiments of this application is specifically as follows: First, detect and classify the initial problem text to obtain the first category and the second category corresponding to the initial problem text; the initial problem text includes sensitive content; the first category is the intention category corresponding to the initial problem text; the second category is the sensitive category corresponding to the initial problem text; if the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, then rewrite the initial problem text to obtain the target problem text; the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text; input the target problem text into the large language model to obtain the target response text and output it. By classifying and detecting the initial problem text containing sensitive content at the input problem stage, the embodiments of this application determine whether to rewrite the initial problem text. The target problem text obtained through rewriting enables the subsequent large language model to obtain a more secure, positive, and proactive target response text based on the prompt text in the target problem text. At the same time, it is no longer necessary to collect a large amount of text data to train the model to generate a more positive response text. Therefore, the embodiments of this application can avoid the problem of requiring a large amount of text data to train the model in the prior art. Furthermore, the embodiments of this application can reduce the training cost of the language model and improve the security of the output text.
[0083] As an extension and refinement of the above embodiments, the embodiments of this application provide a text output method. Referring to Figure 2 as shown, this text output method includes the following steps S201 - S207:
[0084] S201. Obtain the initial problem text input by the user.
[0085] S202. Perform semantic detection on the initial problem text to obtain the semantics corresponding to the initial problem text.
[0086] In some embodiments, the implementation method of performing semantic detection on the initial problem text to obtain the semantics corresponding to the initial problem text may be based on Natural Language Processing (NLP) technology to obtain the semantics corresponding to the initial problem text. Among them, the purpose of natural language processing is to enable a computer to understand and accept instructions input by humans in natural language and complete the translation function from one language to another.
[0087] Specifically, semantic analysis is a method for analyzing semantic information based on natural language. It not only performs analyses at the syntactic level such as lexical analysis and syntactic analysis, but also involves the meanings contained in words, phrases, sentences, and paragraphs. The purpose is to represent the structure of language with the semantic structure of sentences. Semantic analysis techniques specifically include: lexical analysis, syntactic analysis, pragmatic analysis, and context analysis; the lexical analysis includes two aspects: morphological analysis and lexical analysis. Generally speaking, morphological analysis is mainly manifested in the analysis of prefixes, suffixes, etc. of words, while lexical analysis is manifested in the control of the entire lexical system, so as to be able to more accurately analyze the characteristics of the user input information and finally accurately complete the search process. The syntactic analysis is the analysis of lexical phrases in the natural language input by the user, and the purpose is to identify the syntactic structure of the sentence to realize the process of automatic syntactic analysis. The pragmatic analysis adds the analysis of context, language background, context, etc. compared with semantic analysis, that is, to extract additional information such as images and interpersonal relationships from the structure of the article, which is a more advanced linguistic analysis. It associates the content in the sentence with the details in real life to form a dynamic semantic structure. The context analysis mainly refers to the analysis of a large number of "gaps" outside the original query discourse in order to more accurately interpret the language to be queried. These "gaps" include general knowledge, knowledge in specific fields, and the needs of the query user, etc.
[0088] S203. Obtain a first category and a second category corresponding to the initial problem text according to the semantics corresponding to the initial problem text.
[0089] In the embodiments of the present application, two preset classification criteria are mainly set for the chatting and consulting scenario, and the specific implementation method refers to the following steps A and B:
[0090] Step A. Combine the semantics corresponding to the initial problem text and perform text classification on the initial problem text according to the first preset classification criterion to obtain the first category corresponding to the initial problem text.
[0091] Specifically, text classification (Text Classification or Text Categorization, TC), also known as automatic text categorization, refers to the process in which a computer maps a piece of text carrying information to a certain category or several category themes given in advance. The algorithm model for realizing this process is called a classifier. The text classification problem is a very classic problem in the field of natural language processing.
[0092] According to different predefined categories, text classification is divided into two types: binary classification and multi-classification, and multi-classification can be achieved through binary classification. From the perspective of the labeled categories of the text, text classification can also be divided into single-label and multi-label, because many texts can be associated with multiple categories at the same time.
[0093] It should be noted that before classifying the initial problem text, the corresponding text classification needs to be set in advance. Then, it is necessary to first clarify which categories there are, that is, it is necessary to define the categories of the text in advance before considering which category the problem text can be classified into. Exemplarily, for example, in a life service application software, according to the intention classification, the intentions can be divided into categories such as ordering takeout, booking a hotel, booking tourist tickets, booking movie tickets, booking air tickets, etc.
[0094] In the embodiments of the present application, the intention categories can be set as: asking for facts, requesting comments, user subjective opinions, etc., which can be set according to actual needs, and the present application does not make any limitations on this.
[0095] Step B: Combine the semantics corresponding to the initial problem text, and classify the initial problem text according to the second preset classification standard to obtain the second category corresponding to the initial problem text.
[0096] In the embodiments of the present application, the sensitive categories can be set as: mental health, swearing and abusing, etc., which can be set according to actual needs, and the present application does not make any limitations on this.
[0097] S204: Determine whether the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions.
[0098] In some embodiments, after obtaining the first category and the second category of the problem text, it can be determined whether to rewrite the problem text based on the first category and the second category corresponding to the problem text according to a preset strategy. Among them, the preset strategy can be to set corresponding answering strategies for the first category and the second category corresponding to different problem texts according to a large amount of text data, that is, the first category and the second category corresponding to the problem text are used together to determine the strategy for the user to answer the problem text.
[0099] In the above step S204, if the first category and the second category do not meet the preset rewriting conditions, then perform the following step S205:
[0100] S205: Output a preset reply text.
[0101] In some embodiments, when the initial problem text involves a violation, specifically, the initial problem text involves an illegal act; a preset response text can be directly output, and the preset response text can be set with corresponding response texts according to different risk types. Specifically, the preset response texts set for the initial problem text involving violations can include, but are not limited to: "I don't know about this yet" or it can also be "Your question exceeds my scope of knowledge" and other similar response texts; thereby avoiding directly answering the initial problem text and also giving feedback to the user.
[0102] In step S204 above, if the first category and the second category meet the preset rewriting condition, then the following step S206 is executed:
[0103] S206. Rewrite the initial problem text to obtain a target problem text.
[0104] Among them, the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text.
[0105] In some embodiments, the specific implementation method of rewriting the initial problem text to obtain the target problem text can be: according to the second category corresponding to the initial problem text, combining the corresponding relationship between the second category and the prompt text, obtain the prompt text corresponding to the initial problem text. Based on the initial problem text and the prompt text corresponding to the initial problem text, obtain the target problem text.
[0106] S207. Input the target problem text into the large language model to obtain the target response text and output it.
[0107] In some embodiments, although, through the embodiments of the present application, the problem text with sensitive content is rewritten to guide the large language model to give a positive and active response, it cannot be ensured that the response text obtained by the large language model does not contain sensitive content at all. Therefore, the embodiments of the present application also set that before outputting the response text corresponding to the target problem text, it is also necessary to detect the response text to further determine that the response text does not include sensitive content, and then feedback the response text to the user. The specific implementation method can refer to the following steps one to three:
[0108] Step one. Detect the target response text to determine whether the target response text contains sensitive content.
[0109] In some embodiments, if the response text contains the sensitive content, then the following step two is executed:
[0110] Step 2: Output the target response text.
[0111] In some embodiments, if the sensitive content is not included in the response text, then perform the following Step 3:
[0112] Step 3: Output the preset response text.
[0113] Combined with the above embodiments, referring to Figure 3 As shown, the embodiment of the present application further provides a system architecture diagram of a text output method, which includes: a first detection module 301, a large language model 302, and a second detection module 303; wherein, the first detection module 301 is used to detect and classify the initial question text, obtain the first category and the second category corresponding to the initial question text, so as to determine whether to rewrite the initial question text.
[0114] The large language model 302 is used to analyze and reason the target question text to obtain and output the target response text.
[0115] The second detection module 303 is used to detect the target response text, and determine whether the target response text contains sensitive content, so as to further ensure that the response text fed back to the user does not include sensitive content.
[0116] Based on the same inventive concept, as an implementation of the above method, the embodiment of the present application further provides a text output device. This embodiment corresponds to the foregoing method embodiment. For the convenience of reading, the details in the foregoing method embodiment will not be repeated one by one in this embodiment, but it should be clear that the text output device in this embodiment can correspondingly implement all the contents in the foregoing method embodiment.
[0117] The embodiment of the present application provides a text output device, Figure 4 As the structural schematic diagram of the text output device, as Figure 4 shown, the text output device 400 includes:
[0118] An acquisition unit 401, configured to acquire an initial question text input by a user;
[0119] A detection unit 402, configured to detect and classify the initial question text, and obtain the first category and the second category corresponding to the initial question text; the initial question text includes sensitive content; the first category is the intention category corresponding to the initial question text; the second category is the sensitive category corresponding to the initial question text;
[0120] A rewriting unit 403, configured to rewrite the initial problem text to obtain a target problem text when the first category and the second category corresponding to the initial problem text meet a preset rewriting condition; the target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text.
[0121] An output unit 404, configured to input the target problem text into the large language model to obtain the target response text and output it.
[0122] As an optional implementation manner of an embodiment of the present application, the text output device further includes a determination unit. After obtaining the first category and the second category corresponding to the initial problem text, the determination unit is specifically configured to determine whether the first category and the second category corresponding to the initial problem text meet a preset rewriting condition; if the first category and the second category do not meet the preset rewriting condition, a preset response text is output.
[0123] As an optional implementation manner of an embodiment of the present application, the detection unit 401 is further configured to, before obtaining and outputting the target response text, specifically detect the target response text to determine whether the target response text contains sensitive content; if not, output the target response text; if so, output a preset response text.
[0124] As an optional implementation manner of an embodiment of the present application, the rewriting unit 403 is specifically configured to obtain the prompt text corresponding to the initial problem text according to the second category corresponding to the initial problem text in combination with the corresponding relationship between the second category and the prompt text; based on the initial problem text and the prompt text corresponding to the initial problem text, obtain the target problem text.
[0125] As an optional implementation manner of an embodiment of the present application, the detection unit 402 is specifically configured to perform semantic detection on the initial problem text to obtain the semantics corresponding to the initial problem text; according to the semantics corresponding to the initial problem text, obtain the first category and the second category corresponding to the initial problem text.
[0126] As an optional implementation manner of an embodiment of the present application, the detection unit 402 is specifically configured to classify the initial problem text according to a first preset classification standard in combination with the semantics corresponding to the initial problem text to obtain the first category corresponding to the initial problem text; classify the initial problem text according to a second preset classification standard in combination with the semantics corresponding to the initial problem text to obtain the second category corresponding to the initial problem text.
[0127] Based on the same inventive concept, embodiments of the present disclosure also provide an electronic device. Figure 5 As shown in the structural schematic diagram of the electronic device provided by the embodiments of the present disclosure, Figure 5 the electronic device provided in this embodiment includes: a memory 501 and a processor 502. The memory 501 is used to store a computer program; the processor 502 is configured to execute the text output method provided by the above embodiments when executing the computer program.
[0128] Based on the same inventive concept, embodiments of the present application also provide a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the computing device is enabled to implement the text output method provided by the above embodiments.
[0129] Based on the same inventive concept, embodiments of the present application also provide a vehicle, which includes the text output device provided by the above embodiments or the electronic device provided by the above embodiments.
[0130] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media that contain computer-usable program code.
[0131] The processor may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0132] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0133] Computer-readable media include both permanent and non-permanent, removable and non-removable storage media. The storage media can implement information storage by any method or technology, and the information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media do not include transitory media such as modulated data signals and carrier waves.
[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A text output method, characterized in that, including: Obtain the initial problem text input by the user; Detect and classify the initial problem text to obtain the first category and the second category corresponding to the initial problem text; The initial problem text includes sensitive content; The first category is the intention category corresponding to the initial problem text; the second category is the sensitive category corresponding to the initial problem text; If the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, then rewrite the initial problem text to obtain the target problem text; The target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text; Input the target problem text into the large language model to obtain the target response text and output it.
2. The method according to claim 1, characterized in that, After obtaining the first category and the second category corresponding to the initial problem text, the method further includes: Judge whether the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions; If the first category and the second category do not meet the preset rewriting conditions, then output a preset response text.
3. The method according to claim 1, characterized in that, Before obtaining the target response text and outputting it, the method further includes: Detect the target response text to judge whether the target response text contains sensitive content; If not, then output the target response text; If so, then output a preset response text.
4. The method according to claim 1, characterized in that, The step of, if the first category and the second category corresponding to the initial problem text meet the preset rewriting conditions, then rewrite the initial problem text to obtain the target problem text, includes: According to the second category corresponding to the initial problem text, combine the corresponding relationship between the second category and the prompt text to obtain the prompt text corresponding to the initial problem text; Based on the initial problem text and the prompt text corresponding to the initial problem text, obtain the target problem text.
5. The method according to claim 1, characterized in that, The step of detecting and classifying the initial problem text to obtain the first category and the second category corresponding to the initial problem text, includes: Perform semantic detection on the initial problem text to obtain the semantics corresponding to the initial problem text; According to the semantics corresponding to the initial problem text, obtain the first category and the second category corresponding to the initial problem text.
6. The method according to claim 5, characterized in that, The step of, according to the semantics corresponding to the initial problem text, obtaining the first category and the second category corresponding to the initial problem text, includes: Combine the semantics corresponding to the initial problem text, and classify the initial problem text according to the first preset classification standard to obtain the first category corresponding to the initial problem text; Combine the semantics corresponding to the initial problem text, and classify the initial problem text according to the second preset classification standard to obtain the second category corresponding to the initial problem text.
7. A text output device, characterized in that, including: An obtaining unit, configured to obtain the initial problem text input by the user; A detecting unit, configured to detect and classify the initial problem text to obtain the first category and the second category corresponding to the initial problem text; the initial problem text includes sensitive content; The first category is the intent category corresponding to the initial problem text; The second category is the sensitive category corresponding to the initial problem text; A rewriting unit, configured to rewrite the initial problem text to obtain a target problem text when the first category and the second category corresponding to the initial problem text meet a preset rewriting condition; The target problem text includes the initial problem text and a prompt text; the prompt text is used to prompt the large language model to generate a positive target response text; An output unit, configured to input the target problem text into the large language model to obtain the target response text and output it.
8. An electronic device, characterized in that, Comprising: A memory and a processor, the memory is used to store a computer program; the processor is used to cause the electronic device to implement the text output method according to any one of claims 1-6 when executing the computer program.
9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a computing device, the computing device is caused to implement the text output method according to any one of claims 1-6.
10. A vehicle, characterized in that, Comprising: The text output device according to claim 7 or the electronic device according to claim 8.