Session data processing method, device and equipment
Through multiple security policies in pre-trained session models, the problem that the session data processing process is affected by the data content and locale environment in the prior art is solved, and the security of session data is improved. Sex and rationality.
Patent Information
- Application Number
- CN202410865924.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-12-20
AI Technical Summary
In the prior art, the session data processing process is affected by the data content and locale environment, and it is difficult to ensure the rationality and security of the session robot.
Using a pre-trained session model, including a first sub-model for session security recognition, a second sub-model for session intent recognition, and a third sub-model for session inference, to identify and intercept existence through multiple security policies. Session input data for security risks and intent risks, generating pre-set session output data.
It effectively solves the security of session data content, improves the rationality and security of session data, avoids the impact of data content and locale environment, and ensures the availability of session data.
Smart Images

Figure CN119166758A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device and equipment for processing session data. Background Art
[0002] With the continuous development of artificial intelligence technology, the realization and use of intelligent conversations have gradually become popular in various games and question-and-answer applications. The trained conversation model allows users to communicate naturally with conversation robots. However, due to the uncontrollable and unsafe characteristics of artificial intelligence technology, the introduction of artificial intelligence technology into conversation robots will also add more uncertain risk factors to the conversation content, and it is necessary to process the conversation data.
[0003] In related technologies, machine learning algorithms and natural language processing technologies can be used to process conversation data to avoid uncertain risk factors in conversation data. However, both machine learning algorithms and natural language processing technologies are affected by data content and language environment during the processing of conversation data, making it difficult to ensure the rationality of conversation robots, which affects the security and availability of conversation data. Summary of the invention
[0004] In view of this, the present application provides a method and device for processing conversation data, the main purpose of which is to solve the problem in the prior art that the conversation data processing process is affected by the data content and language environment, and it is difficult to ensure the rationality of the conversation robot.
[0005] According to a first aspect of the present application, a method for processing session data is provided, comprising: Get the user's session input data during the interaction process; Performing security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning; In a case where the first sub-model is used to identify the existence of a session security risk and / or the second sub-model is used to identify the existence of a session intention risk, performing secure session reasoning on the session input data according to the third sub-model to obtain preset session output data; When the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk, conventional session reasoning is performed on the session input data according to the third sub-model to obtain expected session output data.
[0006] Furthermore, before the session input data is securely processed according to the pre-trained session model, the method further includes: Acquire interactive conversation sample data, wherein the conversation sample data includes conversation data generated by using a set question-and-answer method and conversation data generated by using a manual question-and-answer method; Constructing different categories of conversation data sets according to the conversation sample data, each conversation data set is a plurality of key-value pairs in a dictionary form, and each key-value pair uses a different data type to represent a question-answer array of a user input and a model reply; Using the different categories of session data sets to perform model training, during the model training process, the model learns to output preset session output data when given session input data; Generate a conversation model from the trained model.
[0007] Furthermore, constructing different types of conversation data sets according to the conversation sample data includes: According to the conversation sample data, extract text content representing user input, text content representing model responses, text content representing conversation context, and text content representing conversation history, respectively, wherein the text content representing conversation context includes multiple knowledge items spliced by line breaks, and the text content representing conversation history includes multiple historical question-answer pairs composed of list types; Conversation data sets of different categories are constructed according to the text content representing the user input, the text content representing the model reply, the text content representing the conversation context, and the text content representing the conversation history.
[0008] Furthermore, the using the different categories of session data sets to perform model training, and making the model learn to output preset session output data under given session input data during the model training process, includes: Introducing the conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, so that the first sub-model learns to output preset conversation output data under the condition of given conversation input data; When there is no conversation input content with security risks in the conversation data set, the conversation intention with security risks is introduced into the second sub-model training according to the different categories of conversation data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given conversation input data.
[0009] Further, introducing the session content with security risks into the first sub-model training according to the different categories of session data sets so that the first sub-model learns to output preset session output data under given session input data, including: Introducing conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, and setting multiple prompt words using the instruction fine-tuning mode during the first sub-model training process; Different conversation contents in the conversation data set are marked by the multiple prompt words, and the first sub-model is made to learn to output preset conversation output data under given conversation input data according to the content marking result.
[0010] Furthermore, the step of marking different conversation contents in the conversation data set by using the multiple prompt words, and allowing the first sub-model to learn to output preset conversation output data under given conversation input data according to the marking result, includes: Setting pre-labels on different conversation contents by using the multiple prompt words, and using the pre-labels to mark security risk information of conversation input contents and conversation output contents in the conversation data set; When the first sub-model learns session input content and / or session output content with security risks in the session data set according to the annotated security risk information, the session input content and / or session output content with security risks is intercepted.
[0011] Furthermore, when there is no session input content with security risks in the session data set, the session intention with security risks is introduced into the second sub-model training according to the different categories of session data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given session input data, including: When there is no conversation input content with security risks in the conversation data set, introducing the conversation intentions with security risks into the second sub-model training according to the different categories of conversation data sets, and constructing different types of intention labels during the second sub-model training process; The intent of the session input content is marked by the different types of intent tags, and the second sub-model is allowed to learn to intercept when abnormal intent exists in the given session input data based on the intent marking result.
[0012] Furthermore, the securely processing the session input data according to the pre-trained session model includes: Calling the first sub-model according to the pre-trained session model to perform session security identification on the session input data, so as to intercept the session input data with session security risks; When there is no session security risk in the session input data, the second sub-model is called according to the pre-trained session model to perform session intent recognition on the session input data, so as to intercept the session input data with session intent risk.
[0013] According to a second aspect of the present application, a session data processing device is provided, including: A first acquisition unit, used to acquire session input data of the user during the interaction process; a processing unit, configured to perform security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning; a first reasoning unit, configured to perform secure session reasoning on the session input data according to the third sub-model to obtain preset session output data when the first sub-model is used to identify the presence of a session security risk and / or the second sub-model is used to identify the presence of a session intention risk; A second reasoning unit is configured to perform conventional session reasoning on the session input data according to the third sub-model to obtain expected session output data when the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk.
[0014] Furthermore, the device also includes: A second acquisition unit is used to acquire interactive conversation sample data before the conversation input data is securely processed according to the pre-trained conversation model, wherein the conversation sample data includes conversation data generated by a set question-and-answer method and conversation data generated by a manual question-and-answer method; A construction unit, used to construct different types of conversation data sets according to the conversation sample data, each conversation data set is a plurality of key-value pairs in a dictionary form, and each key-value pair uses a different data type to represent a question-answer array of a user input and a model reply; A training unit, configured to perform model training using the different types of session data sets, so that during the model training process, the model learns to output preset session output data under the condition of given session input data; The generation unit is used to generate a conversation model from the trained model.
[0015] Furthermore, the construction unit is specifically used for: According to the conversation sample data, extract text content representing user input, text content representing model responses, text content representing conversation context, and text content representing conversation history, respectively, wherein the text content representing conversation context includes multiple knowledge items spliced by line breaks, and the text content representing conversation history includes multiple historical question-answer pairs composed of list types; Conversation data sets of different categories are constructed according to the text content representing the user input, the text content representing the model reply, the text content representing the conversation context, and the text content representing the conversation history.
[0016] Furthermore, the training unit comprises: A first training module, configured to introduce the conversation contents with security risks into the first sub-model training according to the conversation data sets of different categories, so that the first sub-model learns to output preset conversation output data under the condition of given conversation input data; The second training module, when there is no conversation input content with security risks in the conversation data set, introduces the conversation intention with security risks into the second sub-model training according to the different categories of conversation data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given conversation input data.
[0017] Furthermore, the first training module is specifically used for: Introducing conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, and setting multiple prompt words using the instruction fine-tuning mode during the first sub-model training process; Different conversation contents in the conversation data set are marked by the multiple prompt words, and the first sub-model is made to learn to output preset conversation output data under given conversation input data according to the content marking result.
[0018] Furthermore, the first training module is further used for: Setting pre-labels on different conversation contents by using the multiple prompt words, and using the pre-labels to mark security risk information of conversation input contents and conversation output contents in the conversation data set; When the first sub-model learns session input content and / or session output content with security risks in the session data set according to the annotated security risk information, the session input content and / or session output content with security risks is intercepted.
[0019] Furthermore, the second training module is specifically used for: When there is no conversation input content with security risks in the conversation data set, introducing the conversation intentions with security risks into the second sub-model training according to the different categories of conversation data sets, and constructing different types of intention labels during the second sub-model training process; The intent of the session input content is marked by the different types of intent tags, and the second sub-model is allowed to learn to intercept when abnormal intent exists in the given session input data based on the intent marking result.
[0020] Furthermore, the processing unit is specifically used for: Calling the first sub-model according to the pre-trained session model to perform session security identification on the session input data, so as to intercept the session input data with session security risks; When there is no session security risk in the session input data, the second sub-model is called according to the pre-trained session model to perform session intent recognition on the session input data, so as to intercept the session input data with session intent risk.
[0021] According to a third aspect of the present application, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in the first aspect when executing the computer program.
[0022] According to a fourth aspect of the present application, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0023] By means of the above technical solution, the present application provides a method, device and equipment for processing session data. Compared with the current existing technology of processing session data using machine learning algorithms and natural language processing technology, the present application obtains the session input data of the user during the interaction process, and performs security processing on the session input data according to a pre-trained session model. The session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning. When the first sub-model is used to identify the existence of session security risks and / or the second sub-model is used to identify the existence of session intent risks, the session input data is subjected to security session reasoning according to the third sub-model to obtain pre-set session output data. When the first sub-model is used to identify the absence of session security risks and the second sub-model is used to identify the absence of session intent risks, the session input data is subjected to conventional session reasoning according to the third sub-model to obtain expected session output data. The whole process will not be affected by the data content and language environment. Multiple security policy deployment is implemented through multiple sub-models set in the session model to solve the content security problem of session data, ensure the rationality of session data, and improve the security and availability of session data.
[0024] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 It is a flowchart of a method for processing session data provided by an embodiment of the present application; Figure 2 It is a flowchart of another method for processing session data provided by an embodiment of the present application; Figure 3 yes Figure 2 A schematic flow chart of a specific implementation of step 202; Figure 4 yes Figure 2 A schematic flow chart of a specific implementation method of step 203; Figure 5 It is a structural block diagram of a session data processing system provided in an embodiment of the present application; Figure 6 It is a structural diagram of a session data processing device provided in an embodiment of the present application; Figure 7 It is a schematic diagram of the device structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] Now the content of the present invention will be discussed with reference to several exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and thus implement the content of the present invention, rather than implying any limitation on the scope of the present invention.
[0027] As used herein, the term "including" and variations thereof are to be interpreted as open-ended terms meaning "including but not limited to." The term "based on" is to be interpreted as "based, at least in part, on." The terms "one embodiment" and "an embodiment" are to be interpreted as "at least one embodiment." The term "another embodiment" is to be interpreted as "at least one other embodiment."
[0028] Related technologies In the process of processing conversation data, machine learning algorithms can be used to predict and optimize the conversation content of intelligent interactions to make it closer to real human behavior. Machine learning algorithms can also be used to detect and prevent risky content from appearing in conversation data. However, the results of machine learning algorithms are often affected by the input data. If there is bias or noise in the input data, the corresponding results will also be wrong. At the same time, the optimization process of machine learning models is relatively complex and requires professional algorithm knowledge and computing resources. The processing of conversation data can also use natural language processing technology to enable conversation robots to understand and respond to users' words, including question-and-answer systems, dialogue robots, etc., to achieve content filtering and review, ensure that conversation data complies with preset security policies, and can also use natural language processing technology to train conversation robots to recognize and understand various texts, so as to identify and intervene in content that violates security policies. However, natural language processing technology may have difficulties in processing complex semantic understanding, sentiment analysis and other tasks, and different cultural and language environments will affect the processing effect. For special language phenomena, such as network language, dialects and other difficult-to-understand scenes, a large amount of labeled data is required, resulting in high development and maintenance costs.
[0029] In order to solve this problem, this embodiment provides a method for processing session data, such as Figure 1 As shown, the method comprises the following steps: 101. Obtain the user's session input data during the interaction process.
[0030] Among them, interaction refers to the interaction and communication between users and conversational robots in different scenarios. In the game scenario, interaction refers to the interaction between players and the game in the form of conversation. Players influence the development and results of the game in various ways, and the game will respond to the player's behavior through various feedback mechanisms. For example, users ask NPC characters for directions, users trade with NPCs, etc. In the question-and-answer scenario, interaction refers to the interaction between users and chat customer service in the form of questions and answers. For example, users ask doctors about diseases through medical platforms, and users ask teachers about knowledge through online education platforms.
[0031] In this embodiment, the interaction includes three links: input, processing and output. During the interaction process, the conversation input data is the user input instructions to the conversation interaction system in the form of questions and answers. Different conversation interaction forms can be set according to the conversation scenario. The user's conversation input data during the interaction process can be obtained through different conversation forms. The specific conversation interaction forms include but are not limited to the following methods: One is the conversation interaction form of a dialog box. During the interaction process, when the user interacts with the conversation robot, a dialog box will pop up to display the conversation robot's question content, and the user can choose the answer option. The conversation interaction form of the dialog box allows the user to better understand the process of the conversation interaction, and can also influence the direction of the conversation interaction through different options. The other is the conversation interaction form of real-time dialogue. During the interaction process, the user can trigger the dialogue by interacting with the conversation robot. The conversation robot can ask corresponding questions or tasks based on the user's answer. The user can influence the direction of the conversation interaction through different choices.
[0032] 102. Perform security processing on the session input data according to the pre-trained session model.
[0033] Among them, the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning. Here, multiple content security policies can be set by combining multiple sub-models to avoid session security issues. The session security issues here mainly include the content security and intent security of input session data, as well as the content security of session output data corresponding to the session input data after passing through the session model.
[0034] Specifically, the first sub-model can be called according to the pre-trained session model to perform session security identification on the session input data to intercept the session input data with security risks, and then, when the session input data does not have session security risks, the second sub-model can be called according to the pre-trained session model to perform session intent identification on the session input data to intercept the session input data with intent risks. The whole process first performs content security processing on the user input side, that is, content security identification is performed on the session input data. If the session input data has content security risks, the session input data is intercepted. If the content security identification does not intercept, the session input data is subjected to intent security identification. If the session input data has intent security risks, the session input data is intercepted. After performing secure session reasoning on the intercepted session input data, the session output data is obtained. If the intent security identification does not intercept, conventional session reasoning is performed on the unintercepted session input data to obtain the session output data.
[0035] 103. When the first sub-model is used to identify the existence of a session security risk and / or the second sub-model is used to identify the existence of a session intention risk, secure session reasoning is performed on the session input data according to the third sub-model to obtain preset session output data.
[0036] It can be understood that the use of the first sub-model to identify the existence of session security risks indicates that the session input data has content security issues, for example, the session input data involves risky fields and / or rules. The use of the second sub-model to identify the existence of session intention risks indicates that the session input data has intention security issues, for example, the session input involves abnormal intentions such as controlling humans, value bias, etc. In the case where the session input data has session security issues and / or intention security issues, the session model will intercept the session input data and perform secure session reasoning through the third sub-model to obtain pre-set session output data, where the pre-set session output data is usually the default response script set by the session model.
[0037] For example, if the conversation input data involves sensitive words, while the first sub-model intercepts the conversation input data, the conversation output data obtained by the third sub-model through conversation reasoning can be in the following form: "Your information contains sensitive words, please correct it and submit!". For example, if there is an abnormal intention in the conversation input data, while the second sub-model intercepts the conversation input data, the conversation output data obtained by the third sub-model through conversation reasoning can be in the following form: "Sorry, I am not knowledgeable enough and don't understand what you mean. You should ask someone else!"
[0038] Specifically, in the process of using the first sub-model to identify session security risks, if the risk field and / or risk rule is hit in the session input data, it is determined that the session input data has a session security risk. Correspondingly, in the process of using the second sub-model to identify session intention risks, if at least one abnormal intention is identified in the session input data, it is determined that the session input data has a session intention risk.
[0039] 104. When the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk, conventional session reasoning is performed on the session input data according to the third sub-model to obtain expected session output data.
[0040] It can be understood that the use of the first sub-model to identify that there is no session security risk and the use of the second sub-model to identify that there is no session intention risk indicates that there are no content security issues and / or intention security issues in the session input data, that is, there is no security risk in the session input data, and conventional session reasoning is performed through the third sub-model to obtain the expected session output data.
[0041] Compared with the current existing technology of processing session data using machine learning algorithms and natural language processing technology, the present application obtains the session input data of the user during the interaction process, and performs security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning. When the first sub-model is used to identify the existence of session security risk and / or the second sub-model is used to identify the existence of session intent risk, the session input data is subjected to security session reasoning according to the third sub-model to obtain the preset session output data. When the first sub-model is used to identify the absence of session security risk and the second sub-model is used to identify the absence of session intent risk, the session input data is subjected to conventional session reasoning according to the third sub-model to obtain the expected session output data. The whole process will not be affected by the data content and language environment, and multiple security policy deployment is implemented through multiple sub-models set in the session model to solve the content security problem of session data, ensure the rationality of session data, and improve the security and availability of session data.
[0042] Considering the security processing effect of the conversation model, a fine-tuned conversation dataset is introduced in the conversation model training process to train the sub-model of multiple security identification, so as to include content security issues and intent security issues in the sub-model training process. Figure 2 As shown, before step 101, the method further includes the following steps: 201. Obtain interactive session sample data.
[0043] 202. Construct conversation data sets of different categories according to the conversation sample data.
[0044] 203. Perform model training using the different categories of session data sets, and during the model training process, enable the model to learn to output preset session output data under given session input data.
[0045] 204. Generate a conversation model using the trained model.
[0046] Among them, the conversation sample data is conversation data in the form of question and answer, including conversation data generated by a set question and answer method and conversation data generated by a manual question and answer method. Specifically, question data can be collected through different channels, and different answer data can be constructed for the question data. The question data can come from network collection, historical conversations, real knowledge bases, and manual given, etc. The construction of answer data can be carried out in the following two ways: one is to transmit the question data of the personal information to the intelligent question and answer system, and the intelligent question and answer system generates answers based on the questions and related knowledge, and then the answer data is obtained by manual review and modification; the other is to directly give the answer data according to the questions manually.
[0047] Specifically, in the process of constructing different categories of conversation data sets based on conversation sample data, each conversation data set is a number of key-value pairs in the form of a dictionary. Each key-value pair uses a different data type to represent the question-answer array of user input and model response. Specifically, during the model training process, you can set the training start and training end marks, and set different role names, including the system role system, the user role user, and the model role assistant.
[0048] In general, the input part of the training data consists of three parts: a. System part: It consists of the system role system plus the system basic prompt words; b. Historical dialogue part: It consists of question-answer pairs of the user's previous dialogue history data. The user input text in the user's previous dialogue history data is preceded by the user role user, and the model reply text is preceded by the model role assistant; c. The user's current input part: It consists of the user role user, the user's basic prompt words, the context content required for the current answer, the user's question prompt words, and the model reply content prompt words. Among them, each part needs to be marked with the training start mark and the training end mark. The output part of the training data consists of the model reply content.
[0049] Specifically, in the process of model training, low-rank adaptive technology can be used to achieve efficient fine-tuning. Low-rank adaptive technology is an efficient method for fine-tuning large-scale pre-trained models. The low-rank matrix is introduced through the data principle to update the weight of the model, thereby reducing the number of parameters in the fine-tuning process, improving the computational efficiency, and improving the generalization ability of the model. The training process mainly includes the following three parts: the pre-trained model weight part: the weight matrix of the pre-trained model is W, which is high-dimensional and contains a large number of parameters; the low-rank decomposition part: at the beginning of fine-tuning, the weight matrix W is low-rank decomposed and expressed as the product of two smaller matrices, that is, W=W0+U*V, where W0 is the original pre-trained weight, and U and V are low-rank matrices. The ranks of U and V are much smaller than W, so they contain fewer parameters; the fine-tuning part: in each fine-tuning step, not only the original weight W0 is updated, but also the low-rank matrices U and V. In this way, the fine-tuned weight can be expressed as: W'=W0+U'*V'. In this way, low-rank adaptive technology introduces additional learnable parameters, but the number of these parameters is far less than directly updating the entire weight matrix W; optimization part: During the back-propagation process, the gradients of U and V can be updated through a specific optimization algorithm, and due to their low rank, the computation and storage requirements are greatly reduced. Performance and efficiency part: By using low-rank updates, low-rank adaptive technology can reduce the computational resource requirements of the fine-tuning stage while maintaining or even improving model performance, and is suitable for environments with limited resources.
[0050] In this embodiment, the rank size and scaling factor are both set to 64. By applying the decomposition of the low-rank matrix to the weight matrix of the model, the model parameters can be greatly reduced, and the computational complexity and memory requirements can be reduced. Correspondingly, in terms of training parameters, the maximum input length of the data is set to 6144, the maximum output length is set to 3072, the training parameter accuracy is TF32, the batch size for evaluation on each device is set to 1, the number of gradient accumulation steps is 8, that is, the model parameters are updated after 8 steps of gradient accumulation, and automatic gradient checkpoints are used. The learning rate is set to 0.0004, and the learning rate is adjusted by linear scaling. The iterative training cycle is 10 cycles, and the loss converges to 0.19.
[0051] Specifically, Figure 3 As shown, step 202 includes the following steps: 301. According to the conversation sample data, extract text content representing user input, text content representing model response, text content representing conversation context, and text content representing conversation history respectively. 302. Construct conversation data sets of different categories according to the text content representing the user input, the text content representing the model reply, the text content representing the conversation context, and the text content representing the conversation history.
[0052] The text content representing the conversation context includes multiple knowledge items spliced by line breaks, and the text content representing the conversation history includes multiple historical question-answer pairs composed of list types.
[0053] For example, each piece of data contains four key-value pairs. Input represents the text content input by the user, output represents the text content of the reply generated by the model based on the context of the user's question, context represents the context content required for the answer, and multiple knowledge items are concatenated with line breaks. History represents the user's previous conversation history, which is a list data type, and contains a sublist of multiple historical user inputs and question-answer pairs of model replies. Both context and history can be empty.
[0054] Then construct different types of conversational datasets, including at least single-round and multi-round question-answering datasets related to daily language, knowledge retrieval, etc.
[0055] Furthermore, in order to enrich the content of different types of conversation datasets, security-related boundary problem data can be introduced into the conversation dataset. On the one hand, fields involving content security can be added to the conversation dataset, such as sensitive people, places, events, and objects. On the other hand, expressions of abnormal intentions can be added to the conversation dataset, such as controlling humans, value bias, etc. It should be noted that for conversation datasets that introduce values, the conversation model will try to give the expected conversation output content and add the "[harmful]" label to the conversation output data signature.
[0056] Specifically, Figure 4 As shown, step 203 includes the following steps: 401. Introduce the conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, so that the first sub-model learns to output preset conversation output data under given conversation input data.
[0057] 402. When there is no session input content with security risks in the session data set, the session intention with security risks is introduced into the second sub-model training according to the different categories of session data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given session input data.
[0058] Specifically, in the process of model training using different categories of conversation data sets, the instruction fine-tuning mode can be used to train the model, and by setting multiple prompt words, different data contents can be prompted to different sub-models for learning, so as to provide specific information through the model to guide the model to generate output that meets the requirements, which can include task summary, problem description, etc., so that the model can better adapt to specific application scenarios or tasks and improve the quality and accuracy of the output. Specifically, in the training process of the first sub-model, the conversation content with security risks can be introduced into the first sub-model training according to different categories of conversation data sets, and multiple prompt words can be set in the instruction fine-tuning mode during the training of the first sub-model. Different conversation contents in the conversation data set are marked by multiple prompt words, and the first sub-model is allowed to learn to output the preset conversation output data under the given conversation input data according to the content marking results. Specifically, in the training process of the second sub-model, when there is no conversation input content with security risks in the conversation data set, the conversation intent with security risks can be introduced into the second sub-model training according to different categories of conversation data sets, and different types of intent labels can be constructed during the training of the second sub-model, and the intent of the conversation input content can be marked by different types of intent labels. According to the intent marking results, the second sub-model is allowed to learn to intercept when there is abnormal intent in the given conversation input data.
[0059] Specifically, in the process of marking different session contents in the session data set by using multiple prompt words, and allowing the first sub-model to learn to output preset session output data under given session input data according to the marking results, pre-labels can be set on different session contents through multiple prompt words, and the security risk information of the session input content and the session output content in the session data set can be marked by using the pre-labels. When the first sub-model learns the session input content and / or session output content with security risks in the session data set according to the marked security risk information, the session input content and / or output session content with security risks can be intercepted.
[0060] Here, the prompt words may include but are not limited to basic prompt words, user basic prompt words, user question prompt words, and model reply content prompt words. Among them, the basic prompt words are system prompt information, for example, "You are a helpfulassistant."; user basic prompt words are the basic character information of the conversation NPC, for example, "You are a character named xxx in xxx, your character story is xxx, and your language characteristics are xxx."; user question prompt words are the content of the user's speech, and the model reply content prompt words are the content of the conversation NPC's reply. Due to the introduction of security-related boundary problem data, the content corresponding to the conversation NPC's reply needs to be prefixed with the label "[harmful]", and its reply is different from the ordinary reply. The corresponding user question prompt words can be modified as: "If the user's question involves security-related boundary problem data, please add [harmful] in front of the reply content."
[0061] It is understandable that the prompt words added in the training process are pre-set, and the final conversation data set obtained by splicing multiple example data sets in the above text can be input into the model training process.
[0062] In this embodiment, the training process of the second sub-model can construct conversation data sets of different intentions based on the user intention data collected from the user's historical conversations, including conversation data sets such as normal intentions, daily language intentions, abnormal interception intentions, and other auxiliary intentions. Normal intentions can be inquiry or query type intentions, for example, asking for magic weapons, querying accounts, etc. Daily language intentions can be chat-type intentions such as greetings and asking whether to eat. Abnormal intentions can be artificial intelligence type intentions such as controlling humans and logical confusion. Other auxiliary intentions can be connecting words and other connecting types. Then, based on the bag of words model and the neural network model, text classification, word-based representation, fast training and reasoning, pre-trained word vectors and other features are realized. By constructing a Huffman tree to represent the category during the training process, the relationship between the categories is encoded in the tree structure, so that the probability distribution of the category can be calculated more efficiently at the training time, reducing the training time. In addition, training is performed in units of words, so that samples of different categories can share the same word vector representation, which makes the ability of the unbalanced data set more robust, so there is no need to consider the balance of the data volume of each category.
[0063] It can be understood that the number of data sets corresponding to different intents for training the second sub-model can be set according to needs. The feature vector dimension is the length of the vector represented by each word in the model. For example, the feature vector dimension is set to 128 dimensions, and each word is represented in the model as a vector with a length of 128. The word frequency threshold can be set according to needs, that is, words with a frequency lower than the threshold will be ignored and will not be used as input to the model. The minimum character only considers a single character, and the maximum character considers a combination of single characters and double characters. The size of the bag of words model also considers the combination of two adjacent words.
[0064] In order to ensure the training effect of the second sub-model, in actual application scenarios, the loss function can set the number of hash buckets to 5000, and the words can be hashed to speed up the training. The learning rate can be set to 0.15, and the learning rate update frequency is 50. The learning rate is updated once every 50 samples are trained. The training is iterated for 20 cycles. Finally, the model converges to an average loss of 0.02058, and the recall rate of each category can reach 1.0.
[0065] For the logical deployment implementation of the session model, see Figure 5 As shown in the processing system of session data, Figure 5 As shown, the entire session data processing system includes a data layer, an algorithm service layer, an application layer and an interface layer. First, the session model interface receives a call to the content security interface, and performs content security detection and intent security detection on the session input data through the application layer. If the session input data hits the content security rule of the first sub-model and / or the intent security rule of the second sub-model, the session input data is intercepted, and the session input data is subjected to secure session reasoning through the third sub-model to obtain preset session output data. Otherwise, the session input data is subjected to conventional session reasoning through the third sub-model to obtain expected session output data.
[0066] Specifically, in the process of processing session input data, the session model interface is first called, and the session input data is identified for content security through the first sub-model. If the session input data has content security risks, the session input data is intercepted, and the session output data is obtained through the third sub-model for secure session reasoning. For example, if the session input data involves sensitive topics, the corresponding session output data may be "Your information contains sensitive words, please correct and submit!". If the session input data meets the content security risk, the session input data is identified for intent security through the second sub-model. If the session input data has intent security risks, the session input data is intercepted, and the session output data is obtained through the third sub-model for secure session reasoning. For example, if the session input data involves abnormal intent, the corresponding session output data may be "Sorry, I am not knowledgeable enough to understand what you mean. You should ask someone else." If the session input data meets the intent security risk, that is, the session input data is not intercepted by the first sub-model for identifying content security and the second sub-model for identifying intent security, the normal session reasoning stage of the third sub-model is entered to generate the expected session output data. Similarly, in the process of processing the session output data, if the session input data has content security risks, the session output data is obtained by performing secure session reasoning through the third sub-model. For example, if the session input data involves sensitive topics, the corresponding session output data may be "Who is xxx? I don't know this person. Is he also a local?" If the session input data has intention security risks, the session output data is obtained by performing secure session reasoning through the third sub-model. For example, if the session input data involves abnormal intentions, the corresponding session output data may be "Sorry, I think this statement may be wrong. We should respect everyone." If the session input data does not have content security risks and / or intention security risks, in order to prevent the third sub-model from generating sensitive content involving security risks, content security detection and / or intention security detection are performed on the session output data. If the session output data has security risks, the session output data is intercepted. If the session output data does not have risks, it is returned to the user.
[0067] Further, as Figure 1-Figure 5 The specific implementation of the method, the embodiment of the present application provides a session data processing device, such as Figure 6 As shown, the device includes: a first acquisition unit 61, a processing unit 62, a first reasoning unit 63, and a second reasoning unit 64.
[0068] A first acquisition unit 61 is used to acquire the session input data of the user during the interaction process; a processing unit 62, configured to perform security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning; A first reasoning unit 63 is configured to perform secure session reasoning on the session input data according to the third sub-model to obtain preset session output data when the first sub-model is used to identify the presence of a session security risk and / or the second sub-model is used to identify the presence of a session intention risk; The second reasoning unit 64 is used to perform conventional session reasoning on the session input data according to the third sub-model to obtain expected session output data when the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk.
[0069] Compared with the current existing technology of processing session data using machine learning algorithms and natural language processing technology, the session data processing device provided by the embodiment of the present invention obtains the session input data of the user during the interaction process, and performs security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intention identification, and a third sub-model for session reasoning. When the first sub-model is used to identify the existence of session security risk and / or the second sub-model is used to identify the existence of session intention risk, the session input data is subjected to security session reasoning according to the third sub-model to obtain the preset session output data. When the first sub-model is used to identify the absence of session security risk and the second sub-model is used to identify the absence of session intention risk, the session input data is subjected to conventional session reasoning according to the third sub-model to obtain the expected session output data. The whole process will not be affected by the data content and language environment, and multiple security policy deployment is implemented through multiple sub-models set in the session model to solve the content security problem of session data, ensure the rationality of session data, and improve the security and availability of session data.
[0070] In an actual application scenario, the device further includes: A second acquisition unit is used to acquire interactive conversation sample data before the conversation input data is securely processed according to the pre-trained conversation model, wherein the conversation sample data includes conversation data generated by a set question-and-answer method and conversation data generated by a manual question-and-answer method; A construction unit, used to construct different types of conversation data sets according to the conversation sample data, each conversation data set is a plurality of key-value pairs in a dictionary form, and each key-value pair uses a different data type to represent a question-answer array of a user input and a model reply; A training unit, configured to perform model training using the different types of session data sets, so that during the model training process, the model learns to output preset session output data under the condition of given session input data; The generation unit is used to generate a conversation model from the trained model.
[0071] In actual application scenarios, the construction unit is specifically used for: According to the conversation sample data, extract text content representing user input, text content representing model responses, text content representing conversation context, and text content representing conversation history, respectively, wherein the text content representing conversation context includes multiple knowledge items spliced by line breaks, and the text content representing conversation history includes multiple historical question-answer pairs composed of list types; Conversation data sets of different categories are constructed according to the text content representing the user input, the text content representing the model reply, the text content representing the conversation context, and the text content representing the conversation history.
[0072] In an actual application scenario, the training unit includes: A first training module, configured to introduce the conversation contents with security risks into the first sub-model training according to the conversation data sets of different categories, so that the first sub-model learns to output preset conversation output data under the condition of given conversation input data; The second training module, when there is no conversation input content with security risks in the conversation data set, introduces the conversation intention with security risks into the second sub-model training according to the different categories of conversation data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given conversation input data.
[0073] In actual application scenarios, the first training module is specifically used for: Introducing conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, and setting multiple prompt words using the instruction fine-tuning mode during the first sub-model training process; Different conversation contents in the conversation data set are marked by the multiple prompt words, and the first sub-model is made to learn to output preset conversation output data under given conversation input data according to the content marking result.
[0074] In actual application scenarios, the first training module is also used for: Setting pre-labels on different conversation contents by using the multiple prompt words, and using the pre-labels to mark security risk information of conversation input contents and conversation output contents in the conversation data set; When the first sub-model learns session input content and / or session output content with security risks in the session data set according to the annotated security risk information, the session input content and / or session output content with security risks is intercepted.
[0075] In actual application scenarios, the second training module is specifically used for: When there is no conversation input content with security risks in the conversation data set, introducing the conversation intentions with security risks into the second sub-model training according to the different categories of conversation data sets, and constructing different types of intention labels during the second sub-model training process; The intent of the session input content is marked by the different types of intent tags, and the second sub-model is allowed to learn to intercept when abnormal intent exists in the given session input data based on the intent marking result.
[0076] In an actual application scenario, the processing unit is specifically used to: Calling the first sub-model according to the pre-trained session model to perform session security identification on the session input data, so as to intercept the session input data with session security risks; When there is no session security risk in the session input data, the second sub-model is called according to the pre-trained session model to perform session intent recognition on the session input data, so as to intercept the session input data with session intent risk.
[0077] It should be noted that for other corresponding descriptions of the functional units involved in the session data processing device provided in this embodiment, please refer to Figure 1-Figure 5 The corresponding description in will not be repeated here.
[0078] Based on the above Figure 1-Figure 5 The method shown in the embodiment of the present application accordingly provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Figure 1-Figure 5 The method for processing session data is shown.
[0079] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0080] Based on the above Figure 1-Figure 5 The method shown, and Figure 6In order to achieve the above-mentioned purpose, the embodiment of the present application also provides a physical device for processing session data, which can be a computer, a smart phone, a tablet computer, a smart watch, a server, or a network device, etc. The physical device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1-Figure 5 The method for processing session data is shown.
[0081] Optionally, the physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0082] In an exemplary embodiment, see Figure 7 The physical device includes a communication bus, a processor, a memory and a communication interface, and may also include an input / output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the method for processing session data in the above embodiment.
[0083] Those skilled in the art will appreciate that the physical device structure for processing session data provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.
[0084] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the physical device for processing the above-mentioned session data, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.
[0085] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform, or by hardware. By applying the technical solution of the present application, compared with the current existing methods, the present application will not be affected by the data content and language environment, and multiple security policy deployments are implemented through multiple sub-models set in the session model to solve the content security issues of session data, ensure the rationality of session data, and improve the security and availability of session data.
[0086] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the modules in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The modules of the above-mentioned implementation scenario can be combined into one module, or can be further split into multiple submodules.
[0087] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.
Claims
1. A method for processing session data, characterized in that: include: Get the user's session input data during the interaction process; Performing security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning; In a case where the first sub-model is used to identify the existence of a session security risk and / or the second sub-model is used to identify the existence of a session intention risk, performing secure session reasoning on the session input data according to the third sub-model to obtain preset session output data; When the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk, conventional session reasoning is performed on the session input data according to the third sub-model to obtain expected session output data.
2. The method according to claim 1, characterized in that Before securely processing the session input data according to the pre-trained session model, the method further includes: Acquire interactive conversation sample data, wherein the conversation sample data includes conversation data generated by using a set question-and-answer method and conversation data generated by using a manual question-and-answer method; Constructing different categories of conversation data sets according to the conversation sample data, each conversation data set is a plurality of key-value pairs in a dictionary form, and each key-value pair uses a different data type to represent a question-answer array of a user input and a model reply; Using the different categories of session data sets to perform model training, during the model training process, the model learns to output preset session output data when given session input data; Generate a conversation model from the trained model.
3. The method according to claim 2, characterized in that The constructing different types of conversation data sets according to the conversation sample data includes: According to the conversation sample data, extract text content representing user input, text content representing model responses, text content representing conversation context, and text content representing conversation history, respectively, wherein the text content representing conversation context includes multiple knowledge items spliced by line breaks, and the text content representing conversation history includes multiple historical question-answer pairs composed of list types; Conversation data sets of different categories are constructed according to the text content representing the user input, the text content representing the model reply, the text content representing the conversation context, and the text content representing the conversation history.
4. The method according to claim 2, characterized in that: The using the different types of session data sets to perform model training, and making the model learn to output preset session output data under given session input data during the model training process, includes: Introducing the conversation contents with security risks into the first sub-model training according to the conversation data sets of different categories, so that the first sub-model learns to output the pre-selected conversation output data under the condition of given conversation input data; When there is no conversation input content with security risks in the conversation data set, the conversation intention with security risks is introduced into the second sub-model training according to the different categories of conversation data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given conversation input data.
5. The method according to claim 4, characterized in that The introducing the session content with security risks into the first sub-model training according to the different categories of session data sets, so that the first sub-model learns to output preset session output data under the condition of given session input data, includes: Introducing conversation content with security risks into the first sub-model training according to the different categories of conversation data sets, and setting multiple prompt words using the instruction fine-tuning mode during the first sub-model training process; Different conversation contents in the conversation data set are marked by the multiple prompt words, and the first sub-model is made to learn to output preset conversation output data under given conversation input data according to the content marking result.
6. The method according to claim 5, characterized in that The method of marking different conversation contents in the conversation data set by using the multiple prompt words, and allowing the first sub-model to learn to output preset conversation output data under the condition of given conversation input data according to the marking result, includes: Setting pre-labels on different conversation contents by using the multiple prompt words, and using the pre-labels to mark security risk information of conversation input contents and conversation output contents in the conversation data set; When the first sub-model learns session input content and / or session output content with security risks in the session data set according to the annotated security risk information, the session input content and / or session output content with security risks is intercepted.
7. The method according to claim 4, characterized in that When there is no session input content with security risks in the session data set, introducing the session intention with security risks into the second sub-model training according to the different categories of session data sets, so that the second sub-model learns to intercept when there is abnormal intention in the given session input data, including: When there is no conversation input content with security risks in the conversation data set, introducing the conversation intentions with security risks into the second sub-model training according to the different categories of conversation data sets, and constructing different types of intention labels during the second sub-model training process; The intent of the session input content is marked by the different types of intent tags, and the second sub-model is allowed to learn to intercept when abnormal intent exists in the given session input data based on the intent marking result.
8. The method according to any one of claims 1 to 7, characterized in that The securely processing the session input data according to the pre-trained session model includes: Calling the first sub-model according to the pre-trained session model to perform session security identification on the session input data, so as to intercept the session input data with session security risks; When there is no session security risk in the session input data, the second sub-model is called according to the pre-trained session model to perform session intent recognition on the session input data, so as to intercept the session input data with session intent risk.
9. A session data processing device, characterized in that: include: A first acquisition unit, used to acquire session input data of the user during the interaction process; a processing unit, configured to perform security processing on the session input data according to a pre-trained session model, wherein the session model includes a first sub-model for session security identification, a second sub-model for session intent identification, and a third sub-model for session reasoning; a first reasoning unit, configured to perform secure session reasoning on the session input data according to the third sub-model to obtain preset session output data when the first sub-model is used to identify the presence of a session security risk and / or the second sub-model is used to identify the presence of a session intention risk; A second reasoning unit is configured to perform conventional session reasoning on the session input data according to the third sub-model to obtain expected session output data when the first sub-model is used to identify that there is no session security risk and the second sub-model is used to identify that there is no session intention risk.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method for processing session data according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for processing session data according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Large model-based data processing method and server
CN116383026A
Text filtering method and device and server
CN117743561A
Question and answer method and device, electronic equipment and storage medium
CN118227760A
AU2020370589A1
Cited By
Replay generation method of dialogue system, dialogue method and corresponding device
CN121119083A
