A chat content detection method, system and storage medium
Patent Information
- Application Number
- CN202410011163.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-03
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2044-01-03
AI Technical Summary
[0003]当前,对话模型无法结合对话过程中的上下文进行答复,通常只考虑用户所提问的最后一句,使得对话过程过于僵硬,影响用户使用体验
[0052] This application constructs training samples corresponding to specific scenarios, enabling the trained content detection model to perceive the scenario and focus its attention on text categories. The training process considers chat scenarios and references the context of the dialogue, improving the user experience. Furthermore, the content detection model is relatively easy and cost-effective to build, facilitating training through descriptive language.
Smart Images

Figure CN117851884B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, system, and storage medium for detecting chat content. Background Technology
[0002] Compared to traditional modeling methods for single-turn content, text category modeling methods for multi-turn dialogues need to consider the issue of messages from multiple people, and also involve much more extended content understanding than traditional content modeling.
[0003] Currently, dialogue models cannot respond by taking into account the context of the conversation, and usually only consider the last sentence of the user's question, making the dialogue too rigid and affecting the user experience. Summary of the Invention
[0004] The purpose of this application is to provide a method, system, and storage medium for detecting chat content, which comprehensively considers the context of the conversation, the content, and other background information of both parties, thereby improving the user experience.
[0005] To address the aforementioned technical problems, this application provides a method for detecting chat content, the specific technical solution of which is as follows:
[0006] Construct training samples corresponding to the scene; the training samples include the scene, text, and text category.
[0007] Based on the training samples, a content detection model is obtained by training a generative pre-trained model; wherein, during the training process of the training samples, the scene and the text are masked.
[0008] The content detection model is applied to detect the chat content, and the detection results are obtained.
[0009] Optionally, the training samples corresponding to the construction scenario include:
[0010] Construct scene information; the scene information includes chat scene and post square scene;
[0011] The scene information is used as scene markers and concatenated to the front end of the training samples;
[0012] The scenario information is obtained, and the text and text category corresponding to the business scenario are concatenated to form a training sample.
[0013] Optionally, when concatenating the scene information as scene markers to the front end of the training samples, the method further includes:
[0014] Add basic information about both parties in the dialogue to the training samples.
[0015] Optionally, before the text and text category corresponding to the splicing business scenario, the following should also be included:
[0016] The training samples are labeled based on the manual annotation results to obtain the text category.
[0017] Optionally, when constructing training samples corresponding to a scene, the following may also be included:
[0018] Adjust the proportion of each of the aforementioned text categories and set an upper limit on the number of training samples.
[0019] Optionally, the process of masking the scene and the text includes:
[0020] A first masking identifier is added after both the scene and the text; correspondingly, a second masking identifier is added after the text category; during the training process of the training samples, objects containing the first masking identifier do not participate in weight updates, while objects containing the second masking identifier participate in weight updates.
[0021] Optionally, the content detection model is applied to detect the chat content, and the detection results include:
[0022] The content detection model is used to process each word segment in the chat content to obtain a corresponding array;
[0023] Calculate the decoding probability for each of the arrays;
[0024] The word segment corresponding to the maximum decoding probability is taken as the detection result.
[0025] Optionally, when taking the word segment corresponding to the maximum decoding probability as the detection result, the method further includes:
[0026] Set the number of markers to be output in the detection results;
[0027] The decoding probabilities are sorted from largest to smallest to obtain a probability sequence;
[0028] Take the word segment corresponding to the decoding probability in the head of the probability sequence that is the same as the number of output tags of the detection result, and use it as the detection result.
[0029] This application also provides a chat content detection system, including:
[0030] A sample construction module is used to construct training samples corresponding to a scene; the training samples include scenes, text, and text categories.
[0031] The model training module is used to train a content detection model using a generative pre-trained model based on the training samples; wherein, during the training process of the training samples, the scene and the text are masked.
[0032] The content detection module is used to apply the content detection model to detect the chat content and obtain the detection results.
[0033] Optionally, the sample building module includes:
[0034] A scene construction unit is used to construct scene information; the scene information includes chat scenes and post square scenes;
[0035] A marker splicing unit is used to splice the scene information as scene markers to the front end of the training samples;
[0036] The sample assembly unit is used to acquire the scene information, splice the text and text category corresponding to the business scene, and assemble them into a training sample.
[0037] Optionally, the sample building module also includes:
[0038] The basic information setting unit is used to add basic information about both parties in the dialogue to the training samples.
[0039] Optionally, the sample assembly unit also includes:
[0040] The category labeling subunit is used to label the training samples based on the manual annotation results to obtain the text category.
[0041] Optionally, the sample building module includes:
[0042] The sample configuration unit is used to adjust the proportion of each of the text categories and set the upper limit of the number of training samples.
[0043] Optionally, the model training module includes:
[0044] The masking processing unit is configured to add a first masking processing identifier after both the scene and the text; correspondingly, a second masking processing identifier is added after the text category; during the training process of the training samples, objects containing the first masking processing identifier do not participate in weight updates, while objects containing the second masking processing identifier participate in weight updates.
[0045] Optionally, the content detection module includes:
[0046] The decoding unit is used to process each word segment in the chat content using the content detection model to obtain a corresponding array; calculate the decoding probability of each array; and take the word segment corresponding to the maximum decoding probability as the detection result.
[0047] Optionally, the decoding unit may also include:
[0048] The parameter setting unit is used to set the number of output tags for the detection result; sort the decoding probabilities from largest to smallest to obtain a probability sequence; and take the word segment corresponding to the decoding probability that is the same as the number of output tags for the detection result in the head of the probability sequence as the detection result.
[0049] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.
[0050] This application also provides a server, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described above when it invokes the computer program in the memory.
[0051] This application provides a method for detecting chat content, comprising: constructing training samples corresponding to a scene; the training samples including a scene, text, and text category; training a content detection model using a generative pre-trained model based on the training samples; wherein, during the training process of the training samples, the scene and the text are masked; and applying the content detection model to detect the chat content to obtain a detection result.
[0052] This application constructs training samples corresponding to specific scenarios, enabling the trained content detection model to perceive the scenario and focus its attention on text categories. The training process considers chat scenarios and references the context of the dialogue, improving the user experience. Furthermore, the content detection model is relatively easy and cost-effective to build, facilitating training through descriptive language.
[0053] This application also provides a chat content detection system and storage medium, which have the aforementioned beneficial effects, and will not be elaborated here. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0055] Figure 1A flowchart illustrating a chat content detection method provided in an embodiment of this application;
[0056] Figure 2 This is a schematic diagram of a model learning process provided in an embodiment of this application;
[0057] Figure 3 This is a schematic diagram of a chat content detection system provided in an embodiment of this application. Detailed Implementation
[0058] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0059] Please refer to Figure 1 , Figure 1 A flowchart illustrating a chat content detection method provided in this application embodiment, the method comprising:
[0060] S101: Construct training samples corresponding to the scene; the training samples include the scene, text, and text category;
[0061] S102: Based on the training samples, a generative pre-trained model is used to train a content detection model; wherein, during the training process of the training samples, the scene and the text are masked.
[0062] S103: Apply the content detection model to detect the chat content and obtain the detection result.
[0063] First, construct the training samples corresponding to the scenario. This scenario refers to the application context of the chat content, including but not limited to public chat scenarios, such as posting or having conversations in the form of comments under posts. It should be noted that the training samples differ for different scenarios. Specifically, since the training samples include scenario, text, and text category, the scenario in the training samples under different scenarios corresponds to the scenario in which it is applied, while the text is the actual dialogue content of the users, attached by the business scenario, and the text category refers to the text category of the text in the current scenario. This will yield training samples including scenario, text, and text category. The scenario can contain basic information about the scenario, i.e., the basic user information of the two or more parties in the conversation. When constructing the training samples, the following steps can be followed:
[0064] S1011: Construct scene information; the scene information includes chat scene and post square scene;
[0065] S1012: The scene information is used as a scene marker and concatenated to the front end of the training sample;
[0066] S1013: Obtain the scene information, splice the text and text category corresponding to the business scene, and assemble them into a training sample.
[0067] For example, a feasible training sample could be as follows:
[0068] Scene: Dialogue;
[0069] Basic information: User 1, male, age 29; User 2, female, age 28.
[0070] Text: [SPEAKER_0] Copy 0; [SPEKAER_1] Copy 1.
[0071] Text category: Test text category 2, where [SPEAKER_0] and [SPEKAER_1] are the chatter's tags.
[0072] The text category mentioned above is set as the test text category. When actually setting up training samples, it can be labeled with a specific text category. It should be noted that different content can be assigned different text categories. This embodiment aims to construct data with different text categories for different scenarios, such as chat data from a group chat room. Its basic information includes age and gender, and may also include the administrative addresses of the users in the conversation.
[0073] In addition, the proportion of different text categories and the upper limit of the number of training samples can be set in advance.
[0074] For each new text category, only data needs to be provided. There is no need to consider changes to the model structure during subsequent training. A unified model structure can be used to train different scenarios and different text categories.
[0075] After the training samples are constructed, a generative pre-trained model is used to train the content detection model. The generative pre-trained model refers to the GPT (Generative Pre-trained Transformer) model to obtain the content detection model.
[0076] During training, scene and text are masked, and only the text category is processed. The purpose of masking is to prevent scene and text from participating in weight updates and gradient backpropagation during training. Specifically, when performing masking, a first masking identifier is added after both scene and text; correspondingly, a second masking identifier is added after the text category. During training on training samples, objects containing the first masking identifier do not participate in weight updates, while objects containing the second masking identifier do participate in weight updates.
[0077] Thus, the trained content detection model learns the final text category. See also Figure 2 , Figure 2 This is a schematic diagram of a model learning process provided in an embodiment of this application. Figure 2 The text below, "Conversation User 1: Age 29, Gender...Normal," can be identified as belonging to the following text category after study. Figure 2 The rightmost text at the top center reads "Normal". The EOS to the right of "Normal" is the eos_token, used to indicate that model training has stopped.
[0078] After training the content detection model, it can be applied to detect chat content. The detection result includes a determination of the text category of the chat content. This determination depends on the text categories used during training. If the text categories set during training only include "abnormal" and "normal," then the detection result can determine whether the chat content is normal or abnormal. If normal, when replying to the user, the system can consider the preceding text and recent conversations, and even basic information about both parties, to create a more intelligent dialogue and improve the user experience.
[0079] It should be noted that the detection results obtained in this embodiment are classification results for chat content, not intelligent response statements that can be directly applied to dialogue replies. After determining the category of chat content using this embodiment, it can guide targeted responses, enabling the response content to incorporate information from the preceding dialogue.
[0080] This application's embodiments construct training samples corresponding to specific scenarios, enabling the trained content detection model to perceive the scenario and focus its attention on text categories. The training process considers chat scenarios and references the context of the dialogue, improving the user experience. Furthermore, the content detection model is relatively easy and cost-effective to build, facilitating training through descriptive language.
[0081] Based on the above embodiments, as a preferred embodiment, when applying the content detection model to detect the chat content and obtaining the detection result, the specific steps may include the following:
[0082] The first step is to process each word segment in the chat content using the content detection model to obtain the corresponding array;
[0083] The second step is to calculate the decoding probability of each array.
[0084] The third step is to take the word segment corresponding to the maximum decoding probability as the detection result.
[0085] In specific detection, a content detection model can be used to process the word segments in the chat content, with each word corresponding to an array. The method of word segmentation is not limited here; it can be based on a dictionary or semantics, etc. Then, the decoding probability of each array is calculated, and the word segment corresponding to the maximum decoding probability is taken as the detection result.
[0086] It should be noted that if the decoding parameters are set to, for example, topK=1, the word segment corresponding to the maximum decoding probability is taken as the detection result. However, if the decoding parameters are adjusted, i.e., the number of output tags for the detection result is set, for example, topK=2, the decoding probabilities can be sorted from largest to smallest to obtain a probability sequence. Then, the word segment corresponding to the decoding probability at the head of the probability sequence that is the same as the number of output tags for the detection result is taken as the detection result. Adjusting the decoding parameters can make the content detection model more stable and reduce the generation of tags outside the desired category.
[0087] The chat content detection system provided in the embodiments of this application will be described below. The detection system described below can be referred to in correspondence with the chat content detection method described above.
[0088] See Figure 3 , Figure 3 This is a schematic diagram of a chat content detection system provided in an embodiment of this application. This application also provides a chat content detection system, including:
[0089] A sample construction module is used to construct training samples corresponding to a scene; the training samples include scenes, text, and text categories.
[0090] The model training module is used to train a content detection model using a generative pre-trained model based on the training samples; wherein, during the training process of the training samples, the scene and the text are masked.
[0091] The content detection module is used to apply the content detection model to detect the chat content and obtain the detection results.
[0092] Based on the above embodiments, as a preferred embodiment, the sample construction module includes:
[0093] A scene construction unit is used to construct scene information; the scene information includes chat scenes and post square scenes.
[0094] A marker splicing unit is used to splice the scene information as scene markers to the front end of the training samples;
[0095] The sample assembly unit is used to acquire the scene information, splice the text and text category corresponding to the business scene, and assemble them into a training sample.
[0096] Based on the above embodiments, as a preferred embodiment, the sample construction module further includes:
[0097] The basic information setting unit is used to add basic information about both parties in the dialogue to the training samples.
[0098] Based on the above embodiments, as a preferred embodiment, the sample assembly unit further includes:
[0099] The category labeling subunit is used to label the training samples based on the manual annotation results to obtain the text category.
[0100] Based on the above embodiments, as a preferred embodiment, the sample construction module includes:
[0101] The sample configuration unit is used to adjust the proportion of each of the text categories and set the upper limit of the number of training samples.
[0102] Based on the above embodiments, as a preferred embodiment, the model training module includes:
[0103] The masking processing unit is configured to add a first masking processing identifier after both the scene and the text; correspondingly, a second masking processing identifier is added after the text category; during the training process of the training samples, objects containing the first masking processing identifier do not participate in weight updates, while objects containing the second masking processing identifier participate in weight updates.
[0104] Based on the above embodiments, as a preferred embodiment, the content detection module includes:
[0105] The decoding unit is used to process each word segment in the chat content using the content detection model to obtain a corresponding array; calculate the decoding probability of each array; and take the word segment corresponding to the maximum decoding probability as the detection result.
[0106] Based on the above embodiments, as a preferred embodiment, the decoding unit further includes:
[0107] The parameter setting unit is used to set the number of output tags for the detection result; sort the decoding probabilities from largest to smallest to obtain a probability sequence; and take the word segment corresponding to the decoding probability that is the same as the number of output tags for the detection result in the head of the probability sequence as the detection result.
[0108] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, can perform the steps provided in the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0109] This application also provides a server, which may include a memory and a processor. The memory stores a computer program, and when the processor calls the computer program in the memory, it can implement the steps provided in the above embodiments. Of course, the server may also include various network interfaces, power supplies, and other components.
[0110] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. As the system provided in the embodiments corresponds to the method provided in the embodiments, the description is relatively simple; relevant parts can be found in the method section.
[0111] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
[0112] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for detecting chat content, characterized in that, include: Construct training samples corresponding to the scenario; The training samples include scenes, text, and text categories; Based on the training samples, a content detection model is obtained by training a generative pre-trained model; wherein, during the training process of the training samples, the scene and the text are masked. The content detection model is applied to detect the chat content to obtain the detection results; The process of masking the scene and the text includes: A first masking identifier is added after both the scene and the text; correspondingly, a second masking identifier is added after the text category; during the training process of the training samples, objects containing the first masking identifier do not participate in weight updates, while objects containing the second masking identifier participate in weight updates. The content detection model is applied to detect the chat content, and the detection results include: The content detection model is used to process each word segment in the chat content to obtain a corresponding array; Calculate the decoding probability for each of the arrays; The word segment corresponding to the maximum decoding probability is taken as the detection result.
2. The detection method according to claim 1, characterized in that, The training samples corresponding to the constructed scenario include: Construct scene information; the scene information includes chat scene and post square scene; The scene information is used as scene markers and concatenated to the front end of the training samples; The scenario information is obtained, and the text and text category corresponding to the business scenario are concatenated to form a training sample.
3. The detection method according to claim 2, characterized in that, When the scene information is used as a scene marker and concatenated to the front end of the training samples, it also includes: Add basic information about both parties in the dialogue to the training samples.
4. The detection method according to claim 2, characterized in that, Before the text and text category corresponding to the splicing business scenario, it also includes: The training samples are labeled based on the manual annotation results to obtain the text category.
5. The detection method according to claim 4, characterized in that, When constructing training samples corresponding to a scene, the following are also included: Adjust the proportion of each of the aforementioned text categories and set an upper limit on the number of training samples.
6. The detection method according to claim 1, characterized in that, When taking the word segment corresponding to the maximum decoding probability as the detection result, the method further includes: Set the number of markers to be output in the detection results; The decoding probabilities are sorted from largest to smallest to obtain a probability sequence; Take the word segment corresponding to the decoding probability in the head of the probability sequence that is the same as the number of output tags of the detection result, and use it as the detection result.
7. A chat content detection system, characterized in that, include: The sample construction module is used to construct training samples corresponding to the scenario. The training samples include scenes, text, and text categories; The model training module is used to train a content detection model using a generative pre-trained model based on the training samples; wherein, during the training process of the training samples, the scene and the text are masked. The content detection module is used to apply the content detection model to detect the chat content and obtain the detection results; The model training module includes: The masking processing unit is configured to add a first masking processing identifier after both the scene and the text; correspondingly, a second masking processing identifier is added after the text category; during the training process of the training samples, objects containing the first masking processing identifier do not participate in weight updates, while objects containing the second masking processing identifier participate in weight updates. The content detection module includes: The decoding unit is used to process each word segment in the chat content using the content detection model to obtain a corresponding array; calculate the decoding probability of each array; and take the word segment corresponding to the maximum decoding probability as the detection result.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Processing method and device for neural network model and electronic equipment
CN113298248A
System and method for identifying object information in image or video data
US20220188577A1