Offset detection method, device, electronic device and storage medium
Through the interpretation model of vector representation set and text processing model, the offset between the text set to be detected and the reference text set is solved, and the problem that the existing technology cannot determine the reason for the offset is achieved, and the performance of machine learning models is degraded diagnosis and optimization.
Patent Information
- Application Number
- CN202111128237.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-26
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2041-09-26
AI Technical Summary
Existing offset detection techniques can only detect whether the data set is offset, but cannot determine the cause of the offset and cannot provide an explainable offset detection method.
By obtaining the vector representation set of the reference text set, the target text set and the text set to be detected, the difference between the text set to be detected and the target text set in terms of specific objects, and the interpretation model of the text processing model is used to determine the importance of the object to the output results. Degree, determine whether the text set to be detected is offset, and explain the reason for the offset.
It realizes accurate detection of whether the text set is offset, and can explain the reason for the offset, avoiding performance degradation caused by using unsuitable training models.
Smart Images

Figure CN113836889B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and more specifically, to an offset detection method, device, electronic device, and storage medium. Background Art
[0002] Training data is an important part of machine learning. After a machine model is trained using training data, if the information distribution of the input data of the machine model is the same or similar to that of the training data, the performance of the machine model will be very good. However, when the input data of the machine model deviates from the training data (that is, the information distribution of the input data changes compared to the information distribution of the training data), the performance of the machine model will decline.
[0003] At present, there are some technologies that provide data set offset detection, but the existing offset detection technology can only detect whether the data set has offset, but cannot determine the cause of the offset. Therefore, it is necessary to provide an explainable offset detection method that can detect the offset of the data set and determine the cause of the offset. Summary of the invention
[0004] The purpose of this application is to provide an offset detection method, device, electronic device and storage medium, including the following technical solutions:
[0005] A method for detecting an offset, the method comprising:
[0006] Obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set;
[0007] A vector representation set of a first text set is obtained; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents feature values of N objects in the first text set that are ranked top N in importance of the output processing result of the text processing model in the reference text set; the first text set is any one of the reference text set, the target text set, and the text set to be detected;
[0008] Determine the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N;
[0009] It is determined whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
[0010] In the above method, preferably, the target text set is a subset of the reference text set.
[0011] In the above method, preferably, the step of determining the difference between the to-be-detected text set and the target text set in terms of the N objects based on the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N comprises:
[0012] Obtaining a first difference between a vector representation of the reference text set having a length less than or equal to N and a vector representation of the target text set having a length less than or equal to N, and a second difference between a vector representation of the reference text set having a length less than or equal to N and a vector representation of the to-be-detected text set having a length less than or equal to N;
[0013] A third difference between the to-be-detected text set and the target text set is determined according to the first difference and the second difference.
[0014] In the above method, preferably, determining the third difference between the to-be-detected text set and the target text set according to the first difference and the second difference comprises:
[0015] The difference between the first difference and the second difference is determined as a third difference between the to-be-detected text set and the target text set.
[0016] In the above method, preferably, the step of obtaining the vector representation set of the first text set includes:
[0017] Determining the importance of each object in the reference text set to the output processing result of the text processing model by using the interpretation model of the text processing model;
[0018] Determine an object in the reference text set that ranks Nth in importance to the output processing result of the text processing model;
[0019] Determine the importance of the Nth ranked object in the target text set to the processing result output by the text processing model and the importance of the Nth ranked object in the to-be-detected text set to the processing result output by the text processing model by using the interpretation model of the text processing model;
[0020] Based on the importance of the Nth ranked object in the first text set to the output processing result of the text processing model and the frequency of occurrence of the Nth ranked object in the first text set, the feature value of the Nth ranked object in the first text set is determined.
[0021] In the above method, preferably, the step of using the interpretation model of the text processing model to determine the importance of each object in the reference text set to the processing result output by the text processing model includes:
[0022] For any one of the objects in the reference text set, using the interpretation model of the text processing model to determine the positive score and the negative score of each sentence in the reference text set where the any one of the objects appears;
[0023] Normalizing the positive scores and negative scores of each sentence in which the arbitrary object appears in the reference text set to obtain a normalized positive score and a normalized negative score of each sentence in which the arbitrary object appears in the reference text set;
[0024] The normalized positive scores and normalized negative scores of all sentences in which any one of the objects appears are averaged to obtain the importance of any one of the objects to the processing result output by the text processing model.
[0025] In the above method, preferably, determining whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference comprises:
[0026] comparing the difference to a threshold value;
[0027] If the difference is greater than a threshold, it is determined that the to-be-detected text set and the reference text set are offset in the N objects.
[0028] A deviation detection device, comprising:
[0029] A text set acquisition module is used to obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set;
[0030] A vector representation set acquisition module is used to obtain a vector representation set of a first text set; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents the feature values of the top N objects in the reference text set in terms of importance of the output processing result of the text processing model in the first text set; the first text set is any one of the reference text set, the target text set and the text set to be detected;
[0031] A difference determination module, used for determining the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N;
[0032] The offset judgment module is used to determine whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
[0033] An electronic device, comprising:
[0034] Memory, used to store programs;
[0035] A processor is used to call and execute the program in the memory, and implement each step of the offset detection method as described above by executing the program.
[0036] A readable storage medium stores a computer program, and when the computer program is executed by a processor, each step of the offset detection method described in any one of the above items is implemented.
[0037] It can be seen from the above scheme that the present application provides an offset detection method, device, electronic device and storage medium, which performs offset detection on a text set to be detected through a reference text set (used to train a text processing model) and a target text set with the same / similar information distribution as the reference text set, specifically including: obtaining a vector representation set of each text set, the vector representation set of each text set including vector representations of different lengths, a vector of length N representing the feature values of the top N objects in the reference text set in terms of importance of the output processing result of the text processing model in the first text set, and then, based on the vector representation of each text set with a length less than or equal to N, determining the difference between the text set to be detected and the target text set in terms of the N words represented by the vector representation of length N, and determining whether the text set to be detected is offset in terms of the N objects represented by the vector representation of length N based on the difference. Since whether the text set to be tested is offset relative to the reference text set in terms of the N objects represented by the vector representation of length N is determined based on the features of the top N objects in the reference text set ranked in importance with respect to the output processing results of the text processing model, that is, whether the text set to be tested is offset in terms of the objects represented by the vector representation of length N is related to the N objects corresponding to the vector representation of length N. Therefore, it can be clearly explained whether the text set to be tested is offset in terms of the objects represented by the vector representation of length N, and when it is determined that an offset occurs, it can be determined why the offset occurs, that is, the features of the objects represented by the vector representation of length N have changed. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 A flowchart of an implementation of the offset detection method provided in an embodiment of the present application;
[0040] Figure 2 A flowchart for determining the difference between a text set to be detected and a target text set in the above N objects according to a vector representation of a reference text set whose length is less than or equal to N, a vector representation of a target text set whose length is less than or equal to N, and a vector representation of a text set to be detected whose length is less than or equal to N provided in an embodiment of the present application;
[0041] Figure 3 A flowchart for implementing obtaining a vector representation set of a first text set provided in an embodiment of the present application;
[0042] Figure 4 A flowchart for implementing the method of using an interpretation model of a text processing model to determine the importance of each object in a reference text set to an output processing result of the text processing model provided in an embodiment of the present application;
[0043] Figure 5 An example diagram of an offset detection result provided in an embodiment of the present application;
[0044] Figure 6 Another example diagram of the offset detection result provided in the embodiment of the present application;
[0045] Figure 7 A schematic diagram of a structure of an offset detection device provided in an embodiment of the present application;
[0046] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0047] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims and the above drawings are used to distinguish similar parts, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated herein. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0049] The offset detection method provided in the embodiment of the present application can be used in an electronic device, which can be a terminal device, such as a personal computer, an industrial computer, etc., or a network server, or can include a terminal device and a network server.
[0050] In the field of machine learning, after a text processing model is trained by a text set (referred to as the reference text set), before using the trained text processing model to process a new text set (referred to as the to-be-detected text set), it is possible to first determine whether the to-be-detected text set is offset relative to the reference text set. If an offset occurs, it means that the trained text processing model is not suitable for processing the to-be-detected text set, or that the trained text processing model will have poor performance when processing the to-be-detected text set. If no offset occurs, it means that the trained text processing model is still suitable for processing the to-be-detected text set, or that the trained text processing model will not deteriorate when processing the to-be-detected text set.
[0051] If it is determined that the text set to be detected has shifted relative to the reference text set, the trained text processing model may no longer be used to process the text set to be detected, thereby avoiding invalid text processing.
[0052] The purpose of this application is to detect whether the text set to be detected is offset from the reference text set, and the reason for the offset. To achieve this purpose, an embodiment of this application is proposed:
[0053] like Figure 1 As shown, a flowchart of an implementation of the offset detection method provided in an embodiment of the present application may include:
[0054] Step S101: obtaining a reference text set, a target text set and a text set to be detected;
[0055] The reference text set is a text set used to train a text processing model. The text processing model may include but is not limited to any of the following models: a text classification model, a human-computer interaction model, a translation model (for conversion between different languages), and the like.
[0056] The target text set has the same or similar information distribution as the reference text set. That is, the target text set is not offset relative to the reference text set. The target text set can be generated based on the reference text set.
[0057] For any text set, the information distribution of the text set may include the distribution of objects (characters, words or phrases, etc.) in the text set; the distribution of objects may include but is not limited to any of the following: the frequency of occurrence of the object in the text set; a parameter positively correlated with the frequency of occurrence of the object in the text set, etc.
[0058] Step S102: obtaining a vector representation set of a first text set; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents the feature values of the top N objects in the reference text set that are ranked in importance to the output processing result of the text processing model in the first text set; the first text set is any one of the reference text set, the target text set and the text set to be detected.
[0059] In an embodiment of the present application, the feature values of the M objects (e.g., M words) in the reference text set that are ranked before M (M is a positive integer) in terms of importance to the output result of the text processing model in the reference text set can be first obtained, and then the feature values of the N objects in the first text set that are ranked before N (N is a positive integer less than or equal to M) in terms of importance to the output result of the text processing model in the reference text set constitute a vector representation of length N of the reference text set. As an example, N=1, 2, 3, ..., M, then the vector representation of the reference text set contains M vector representations. Of course, in an embodiment of the present application, the value of N is not limited to this method, and there can be other value methods, for example, N=4, 5, 6, ..., M, then the vector representation of the reference text set contains M-3 vector representations.
[0060] For the top M objects in the reference text set that are ranked in importance with respect to the output processing results of the text processing model, feature values of the M objects in the target text set and feature values of the M objects in the text set to be detected are obtained.
[0061] For the target text set, the feature values of the top N objects in the reference text set ranked in importance to the output processing result of the text processing model in the target text set constitute a vector representation of the target text set with a length of N.
[0062] For the text set to be detected, the feature values of the top N objects in the reference text set that are ranked in importance to the output processing results of the text processing model in the text set to be detected constitute a vector representation of the text set to be detected with a length of N.
[0063] The number of vector representations in the three vector representation sets (i.e., the vector representation set of the reference text set, the vector representation set of the target text set, and the vector representation set of the text set to be detected) is the same, and in different vector representation sets, vector representations of the same length correspond to the same object.
[0064] Step S103: Determine the differences between the text set to be detected and the target text set in N objects based on the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the text set to be detected whose length is less than or equal to N.
[0065] That is, in the embodiment of the present application, the difference between the to-be-detected text set and the target text set in terms of N objects is associated with a vector representation of the reference text set whose length is less than or equal to N.
[0066] Step S104: determining whether there is an offset between the to-be-detected text set and the reference text set in terms of the N objects according to the above differences.
[0067] Since the above differences are associated with vector representations of the reference text set whose length is less than or equal to N, it can be determined based on the above differences whether the text set to be detected and the reference text set are offset in the above N objects.
[0068] Among them, the deviation between the text set to be detected and the reference text set in terms of the above N objects refers to the fact that the distribution of the above N objects in the text set to be detected has changed significantly compared with the distribution of the above N objects in the reference text set, and this significant change will affect the performance of the text processing model.
[0069] The offset detection method provided in the embodiment of the present application performs offset detection on a text set to be detected by using a reference text set (used for training a text processing model) and a target text set having the same / similar information distribution as the reference text set, and specifically comprises: obtaining vector representation sets of each text set, the vector representation set of each text set including vector representations of different lengths, a vector of length N representing the feature values of the top N objects in the reference text set in the first text set that are ranked in importance of the output processing result of the text processing model, and then, based on the vector representations of each text set whose length is less than or equal to N, determining the difference between the text set to be detected and the target text set in terms of the N words represented by the vector representation of length N, and determining whether the text set to be detected has offset in terms of the N objects represented by the vector representation of length N based on the difference. Since whether the text set to be tested has shifted relative to the reference text set in terms of the N objects represented by the vector representation of length N is determined based on the features of the top N objects in the reference text set ranked in importance with respect to the output processing result of the text processing model, that is, whether the text set to be tested has shifted in terms of the objects represented by the vector representation of length N is related to the N objects corresponding to the vector representation of length N. Therefore, it can be clearly explained whether the text set to be tested has shifted in terms of the objects represented by the vector representation of length N, and when it is determined that a shift has occurred, it can be determined that it is because the features of the objects represented by the vector representation of length N have changed.
[0070] In an optional embodiment, the target text set may be a subset of the reference text set.
[0071] Optionally, some texts can be randomly selected from the reference text set as the target text set; or,
[0072] Part of the text can be extracted from the reference text set as the target text set according to certain rules. For example, each text in the reference text set has a unique identification code, and the text whose identification code meets the conditions can be extracted as the target text set. For example, text whose identification code is an even number or an odd number can be extracted as the target text set, or text whose identification code is a multiple of 3 can be extracted as the target text set.
[0073] Since the target text set is extracted from the reference text set, the information distribution of the target text set is similar or identical to that of the reference text set.
[0074] In an optional embodiment, a flowchart for implementing the above-mentioned determination of the difference between the to-be-detected text set and the target text set in the above-mentioned N objects based on the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N is as follows: Figure 2 As shown, it may include:
[0075] Step S201: Obtain a first difference between a vector representation of a reference text set whose length is less than or equal to N and a vector representation of a target text set whose length is less than or equal to N, and a second difference between a vector representation of a reference text set whose length is less than or equal to N and a vector representation of a text set to be detected whose length is less than or equal to N.
[0076] The first difference is calculated in the same way as the second difference, optionally,
[0077] The first difference may be calculated by: summing the Euclidean distances between each vector representation of the reference text set whose length is less than or equal to N and each vector representation of the target text set whose length is less than or equal to N.
[0078] The second difference may be calculated by: summing the Euclidean distances between each vector representation of the reference text set whose length is less than or equal to N and each vector representation of the to-be-detected text set whose length is less than or equal to N.
[0079] Taking N=4, 5, 6, ..., M as an example, when N=5, what is obtained is the first difference between the vector representation of length 4 and length 5 of the reference text set and the vector representation of length 4 and length 5 of the target text set, and the second difference between the vector representation of length 4 and length 5 of the reference text set and the vector representation of length 4 and length 5 of the text set to be detected. Specifically,
[0080] The first difference is calculated as:
[0081] Calculate the Euclidean distance between the vector representation of the reference text set with a length of 4 and the vector representation of the target text set with a length of 4 (denoted as the first Euclidean distance), and the Euclidean distance between the vector representation of the reference text set with a length of 5 and the vector representation of the target text set with a length of 5 (denoted as the second Euclidean distance).
[0082] The sum of the first Euclidean distance and the second Euclidean distance is taken as the first difference.
[0083] The second difference is calculated as:
[0084] Calculate the Euclidean distance between the vector representation of the reference text set with a length of 4 and the vector representation of the text set to be detected with a length of 4 (denoted as the third Euclidean distance), and the Euclidean distance between the vector representation of the reference text set with a length of 5 and the vector representation of the text set to be detected with a length of 5 (denoted as the fourth Euclidean distance).
[0085] The sum of the third Euclidean distance and the fourth Euclidean distance is taken as the second difference.
[0086] Step S202: Determine the third difference between the text set to be detected and the target text set according to the first difference and the second difference. The third difference is the difference between the text set to be detected and the target text set in terms of the above N objects.
[0087] The embodiment of the present application considers that the target text set has no offset or a small offset relative to the reference text set. If the text set to be detected has no offset or a small offset relative to the reference text set, then the feature change (i.e., the change in information distribution) of the text set to be detected relative to the reference text set should be similar to the feature change of the target text set relative to the reference text set. Based on this,
[0088] The difference between the first difference and the second difference can be determined as the third difference between the text set to be detected and the target text set. In other words, the difference between the difference of the target text set relative to the reference text set and the difference of the text set to be detected relative to the reference text set is used as an indicator for determining whether the text set to be detected is offset relative to the reference text set.
[0089] Optionally, the third difference may be the absolute value of the difference between the first difference and the second difference, or the third difference may be the square of the difference between the first difference and the second difference.
[0090] As an example, the third difference can be calculated by the following formula:
[0091]
[0092] Where Ref represents the reference text set, h0 represents the target text set, Pert represents the text set to be detected, Dis(h0,Pert) represents the difference between the text set to be detected and the target text set in the above N objects, n represents the number of vector representations with a length less than or equal to N, r t (Ref) represents the tth vector representation in the vector representation of the reference text set whose length is less than or equal to N, r t (h0) represents the tth vector representation in the vector representation of the target text set whose length is less than or equal to N, r t (Pert) represents the tth vector representation in the vector representation of the text set to be detected whose length is less than or equal to N, r t (Ref), r t (h0), r t (Pert) has the same length, and EUC() means calculating the Euclidean distance.
[0093] In an optional embodiment, a flowchart for implementing the above-mentioned obtaining of the vector representation set of the first text set is as follows: Figure 3 As shown, it may include:
[0094] Step S301: using the interpretation model of the text processing model (which may be recorded as the first interpretable model) to determine the importance of each object in the reference text set to the output processing result of the text processing model.
[0095] In an embodiment of the present application, Explainable Artificial Intelligence (XAI) is introduced to perform offset detection, specifically, the importance of each object in the reference text set to the output processing result of the text processing model is determined based on XAI.
[0096] According to the scope of explanation of explainable artificial intelligence, XAI can be divided into global explanation and local explanation. Among them, the global explanation method takes the model to be explained (i.e., the machine learning model) as a whole to explain the behavior of the model. It may involve describing the entire reasoning process of the model, such as presenting all weights, features, and their interactions. Local explanation includes describing the behavior of the model on a specific case or a group of cases, which can provide more detailed insights into the model's predictions by showing which features of the case have the greatest impact on the model's predictions. Local explanation also includes training an explainable model (such as decision trees, linear regression, logistic regression, Bayesian models, generalized linear models, generalized additive models, or K nearest neighbors and manipulable probabilistic logic models, etc.) to approximate the machine learning model, so that the trained explainable model can determine the degree of influence of each feature on the model's prediction results.
[0097] The specific implementation method can refer to the existing solution, which is no longer similar here.
[0098] Step S302: Determine the object in the reference text set that is ranked Nth in importance to the output processing result of the text processing model.
[0099] Step S303: Use the interpretation model of the text processing model to determine the importance of the Nth ranked object in the target text set to the output processing result of the text processing model, and the importance of the Nth ranked object in the text set to be detected to the output processing result of the text processing model.
[0100] In the embodiment of the present application, in addition to using the interpretable model (i.e., the first interpretable model) to determine the importance of each object in the reference text set to the output processing result of the text processing model, the interpretable model (i.e., the second interpretable model) is also used to determine the importance of each object in the target text set to the output processing result of the text processing model, and the interpretable model (i.e., the third interpretable model) is used to determine the importance of each object in the to-be-detected text set to the output processing result of the text processing model. Then, from the importance of each object in the target text set to the output processing result of the text processing model, the importance of the object ranked Nth in importance to the output processing result of the text processing model in the reference text set is extracted, and from the importance of each object in the to-be-detected text set to the output processing result of the text processing model, the importance of the object ranked Nth in importance to the output processing result of the text processing model in the reference text set is extracted. Optionally, if the target text set does not contain an object ranked Nth in importance for the output processing result of the text processing model in the reference text set, then, in the target text set, the object ranked Nth in importance for the output processing result of the text processing model in the reference text set has a preset value for importance to the output processing result of the text processing model, such as zero or a value close to zero. Similarly, if the to-be-detected text set does not contain an object ranked Nth in importance for the output processing result of the text processing model in the reference text set, then, in the to-be-detected text set, the object ranked Nth in importance for the output processing result of the text processing model in the reference text set has a preset value for importance to the output processing result of the text processing model, such as zero or a value close to zero.
[0101] Step S304: Determine the feature value of the Nth ranked object in the first text set based on the importance of the Nth ranked object in the first text set to the output processing result of the text processing model and the frequency of occurrence of the Nth ranked object in the first text set.
[0102] Optionally, a logarithm operation may be performed on the frequency of occurrence of the object ranked Nth in the reference text set in the first text set to obtain an operation result.
[0103] The importance of the Nth-ranked object in the first text set to the output processing result of the text processing model is multiplied by the above operation result to obtain the feature value of the Nth-ranked object in the reference text set in the first text set.
[0104] In an optional embodiment, a flowchart for implementing the above-mentioned determination of the importance of each object in the reference text set to the output processing result of the text processing model by using the interpretation model of the text processing model is as follows: Figure 4 As shown, it may include:
[0105] Step S401: For any object in the reference text set, the interpretation model of the text processing model is used to determine the positive score and negative score of each sentence in the reference text set where the object appears.
[0106] Step S402: normalizing the positive scores and negative scores of each sentence in the reference text set where any one of the above objects appears, to obtain a normalized positive score and a normalized negative score of each sentence in the reference text set where any one of the above objects appears.
[0107] Among them, the positive score represents the degree to which the sentence containing any of the above objects has a positive impact on the processing result of the text processing model, and the negative score represents the degree to which the sentence containing any of the above objects has a negative impact on the processing result of the text processing model.
[0108] Optionally, the sum of the positive scores and negative scores of all sentences in which any of the above objects appear can be calculated to obtain the total score; for each score (positive score or negative score), the quotient of the score and the total score can be calculated to obtain the normalized value of the score.
[0109] Step S403: averaging the normalized positive scores and normalized negative scores of all sentences in which any of the above objects appear, to obtain the importance of any of the above objects to the output processing result of the text processing model.
[0110] Figure 4 The method shown can be determined by the following formula:
[0111] Degree=Mean(Norm(gradient(T i )))
[0112] Among them, Degree represents the object T i The importance of the output of the text processing model. Mean( ) represents the mean, Norm( ) represents the normalization operation, and gradient(T i ) represents each occurrence object T in the reference text set determined by the interpretation model of the text processing model i The positive and negative scores of the sentences. gradient(T i ) is similar to the following matrix structure:
[0113] Sent + -
[0114] Sent1 0.1 0.4
[0115] Sent2 0.2 0.5
[0116] The above matrix indicates that the interpretation model of the text processing model determines the occurrence of object T in the reference text set. i The sentence Sent1 has a positive score of 0.1 and a negative score of 0.4. The interpretation model of the text processing model determines that object T appears in the reference text set. i The sentence Sent2 has a positive score of 0.2 and a negative score of 0.5.
[0117] Optionally, the object ranked N can be calculated by the following formula (assuming T i ) in the first text set:
[0118]
[0119] Where D represents the first text set, TF(T i ) represents the object T i The frequency of occurrence in the first text set, for example, object T i When it is a word, TF(T i ) represents word T i The word frequency.
[0120] In an optional embodiment, one implementation method of determining whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference may be:
[0121] The above difference is compared with a threshold; the threshold may be 0, or a value close to 0, such as 0.1, 0.11, 0.04, etc.
[0122] If the comparison result shows that the difference is greater than the threshold, it is determined that the text set to be detected and the reference text set are offset in the above N objects. Otherwise, it is determined that the text set to be detected and the reference text set are not offset in the above N objects.
[0123] like Figure 5 As shown, an example diagram of the offset detection result provided in an embodiment of the present application, in which the top 100 words ranked by importance of the output results of the text processing model in the reference text set are used for offset detection. In this example diagram, the change in the distribution of these 100 words in the target text set is similar to the change in the distribution of these 100 words in the text set to be detected, so the difference between the text set to be detected and the target text set in the first 100 words is close to zero.
[0124] like Figure 6As shown in FIG. 1 , another example diagram of the offset detection result provided by an embodiment of the present application is used. In this example, the 100 words ranked in importance of the output result of the text processing model in the reference text set are used for offset detection. In this example diagram, the distribution of these 100 words in the target text set varies greatly compared to the distribution of these 100 words in the reference text set, and the difference between the text set to be detected and the target text set in the first 100 words is also large. Figure 6 It can be seen that starting from the 4th word in the first 100 words mentioned above, the changes in the distribution of each word in the target text set and its distribution in the text set to be detected are quite different, making the difference between the 4th to 100th aspects of the first 100 words in the text set to be detected and the target text set no longer close to zero.
[0125] Corresponding to the method embodiment, the embodiment of the present application further provides a deviation detection device. A structural schematic diagram of the deviation detection device provided in the embodiment of the present application is shown in FIG. Figure 7 As shown, it may include:
[0126] A text set acquisition module 701, a vector representation set acquisition module 702, a difference determination module 703 and an offset determination module 704, wherein:
[0127] The text set acquisition module 701 is used to obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set;
[0128] The vector representation set acquisition module 702 is used to obtain a vector representation set of a first text set; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents the feature values of the top N objects in the reference text set in terms of importance of the output processing result of the text processing model in the first text set; the first text set is any one of the reference text set, the target text set and the text set to be detected;
[0129] The difference determination module 703 is used to determine the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N;
[0130] The offset judgment module 704 is used to determine whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
[0131] The offset detection device provided in the embodiment of the present application performs offset detection on a text set to be detected by using a reference text set (used for training a text processing model) and a target text set having the same / similar information distribution as the reference text set, specifically comprising: obtaining a vector representation set of each text set, the vector representation set of each text set including vector representations of different lengths, a vector with a length of N representing the feature values of the top N objects in the reference text set that are ranked in importance of the output processing result of the text processing model in the first text set, then, based on the vector representations of each text set whose length is less than or equal to N, determining the difference between the text set to be detected and the target text set in terms of the N words represented by the vector representation with a length of N, and determining whether the text set to be detected is offset in terms of the N objects represented by the vector representation with a length of N based on the difference. Since whether the text set to be tested has shifted relative to the reference text set in terms of the N objects represented by the vector representation of length N is determined based on the features of the top N objects in the reference text set ranked in importance with respect to the output processing result of the text processing model, that is, whether the text set to be tested has shifted in terms of the objects represented by the vector representation of length N is related to the N objects corresponding to the vector representation of length N. Therefore, it can be clearly explained whether the text set to be tested has shifted in terms of the objects represented by the vector representation of length N, and when it is determined that a shift has occurred, it can be determined that it is because the features of the objects represented by the vector representation of length N have changed.
[0132] In an optional embodiment, the target text set is a subset of the reference text set.
[0133] In an optional embodiment, the difference determination module 703 includes:
[0134] A first obtaining module, used for obtaining a first difference between a vector representation of the reference text set whose length is less than or equal to N and a vector representation of the target text set whose length is less than or equal to N, and a second difference between a vector representation of the reference text set whose length is less than or equal to N and a vector representation of the text set to be detected whose length is less than or equal to N;
[0135] The first determination module is used to determine a third difference between the to-be-detected text set and the target text set according to the first difference and the second difference.
[0136] In an optional embodiment, the determining module is used to:
[0137] The difference between the first difference and the second difference is determined as a third difference between the to-be-detected text set and the target text set.
[0138] In an optional embodiment, the vector representation set obtaining module includes:
[0139] A second determination module, configured to determine the importance of each object in the reference text set to the output processing result of the text processing model by using the interpretation model of the text processing model;
[0140] A third determination module is used to determine the object ranked Nth in importance in the reference text set with respect to the output processing result of the text processing model;
[0141] A fourth determination module is used to determine the importance of the Nth ranked object in the target text set to the processing result output by the text processing model, and the importance of the Nth ranked object in the to-be-detected text set to the processing result output by the text processing model by using the interpretation model of the text processing model;
[0142] The fifth determination module is used to determine the feature value of the Nth-ranked object in the first text set based on the importance of the Nth-ranked object in the first text set to the output processing result of the text processing model and the frequency of occurrence of the Nth-ranked object in the first text set.
[0143] In an optional embodiment, the fourth determining module includes:
[0144] a sixth determination module, configured to determine, for any object in the reference text set, a positive score and a negative score of each sentence in the reference text set where the any object appears, using the interpretation model of the text processing model;
[0145] A second obtaining module is used to normalize the positive scores and negative scores of each sentence in which the arbitrary object appears in the reference text set, so as to obtain the normalized positive scores and normalized negative scores of each sentence in which the arbitrary object appears in the reference text set;
[0146] The third acquisition module is used to average the normalized positive scores and normalized negative scores of all sentences in which any one of the objects appears, so as to obtain the importance of any one of the objects to the output processing result of the text processing model.
[0147] In an optional embodiment, the offset determination module includes:
[0148] A comparison module, for comparing the difference with a threshold value;
[0149] The seventh determination module is used to determine that the to-be-detected text set and the reference text set are offset in terms of the N objects if the difference is greater than a threshold.
[0150] Corresponding to the method embodiment, the present application also provides an electronic device, a structural schematic diagram of the electronic device is shown as follows Figure 8 As shown, it may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0151] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0152] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application, etc.;
[0153] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0154] The memory 3 stores a program, and the processor 1 can call the program stored in the memory 3, and the program is used to:
[0155] Obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set;
[0156] A vector representation set of a first text set is obtained; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents feature values of N objects in the first text set that are ranked top N in importance of the output processing result of the text processing model in the reference text set; the first text set is any one of the reference text set, the target text set, and the text set to be detected;
[0157] Determine the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N;
[0158] It is determined whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
[0159] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0160] The embodiment of the present application further provides a storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0161] Obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set;
[0162] A vector representation set of a first text set is obtained; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents feature values of N objects in the first text set that are ranked top N in importance of the output processing result of the text processing model in the reference text set; the first text set is any one of the reference text set, the target text set, and the text set to be detected;
[0163] Determine the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N;
[0164] It is determined whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
[0165] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0166] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0167] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0168] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0169] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0170] It should be understood that in the embodiments of the present application, the various embodiments and features can be combined with each other to solve the aforementioned technical problems.
[0171] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0172] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for detecting an offset, the method comprising: Obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set; A vector representation set of a first text set is obtained; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents feature values of N objects in the first text set that are ranked top N in importance of the output processing result of the text processing model in the reference text set; the first text set is any one of the reference text set, the target text set, and the text set to be detected; Determine the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N; It is determined whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
2. According to the method of claim 1, the target text set is a subset of the reference text set.
3. The method according to claim 1, wherein the difference between the to-be-detected text set and the target text set in terms of the N objects is determined based on the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N, comprising: Obtaining a first difference between a vector representation of the reference text set having a length less than or equal to N and a vector representation of the target text set having a length less than or equal to N, and a second difference between a vector representation of the reference text set having a length less than or equal to N and a vector representation of the to-be-detected text set having a length less than or equal to N; A third difference between the to-be-detected text set and the target text set is determined according to the first difference and the second difference.
4. The method according to claim 3, wherein determining the third difference between the to-be-detected text set and the target text set according to the first difference and the second difference comprises: The difference between the first difference and the second difference is determined as a third difference between the to-be-detected text set and the target text set.
5. The method according to claim 1, wherein obtaining the vector representation set of the first text set comprises: Determining the importance of each object in the reference text set to the output processing result of the text processing model by using the interpretation model of the text processing model; Determine an object in the reference text set that ranks Nth in importance to the output processing result of the text processing model; Determine the importance of the Nth ranked object in the target text set to the processing result output by the text processing model and the importance of the Nth ranked object in the to-be-detected text set to the processing result output by the text processing model by using the interpretation model of the text processing model; Based on the importance of the Nth ranked object in the first text set to the output processing result of the text processing model and the frequency of occurrence of the Nth ranked object in the first text set, the feature value of the Nth ranked object in the first text set is determined.
6. The method according to claim 5, wherein the step of using the interpretation model of the text processing model to determine the importance of each object in the reference text set to the output processing result of the text processing model comprises: For any one of the objects in the reference text set, using the interpretation model of the text processing model to determine the positive score and the negative score of each sentence in the reference text set where the any one of the objects appears; Normalizing the positive scores and negative scores of each sentence in which the arbitrary object appears in the reference text set to obtain a normalized positive score and a normalized negative score of each sentence in which the arbitrary object appears in the reference text set; The normalized positive scores and normalized negative scores of all sentences in which any one of the objects appears are averaged to obtain the importance of any one of the objects to the processing result output by the text processing model.
7. The method according to claim 1, wherein determining whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference comprises: comparing the difference to a threshold value; If the difference is greater than a threshold, it is determined that the to-be-detected text set and the reference text set are offset in the N objects.
8. A deviation detection device, comprising: A text set acquisition module is used to obtain a reference text set, a target text set and a text set to be detected; wherein the reference text set is a text set used for training a text processing model, and the target text set has the same or similar information distribution as the reference text set; A vector representation set acquisition module is used to obtain a vector representation set of a first text set; different vector representations in the vector representation set have different lengths, and a vector representation with a length of N represents the feature values of the top N objects in the reference text set in terms of importance of the output processing result of the text processing model in the first text set; the first text set is any one of the reference text set, the target text set and the text set to be detected; A difference determination module, used for determining the difference between the to-be-detected text set and the target text set in terms of the N objects according to the vector representation of the reference text set whose length is less than or equal to N, the vector representation of the target text set whose length is less than or equal to N, and the vector representation of the to-be-detected text set whose length is less than or equal to N; The offset judgment module is used to determine whether the to-be-detected text set and the reference text set are offset in the N objects according to the difference.
9. An electronic device, comprising: Memory, used to store programs; A processor is used to call and execute the program in the memory, and implement each step of the offset detection method as described in any one of claims 1 to 7 by executing the program.
10. A readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the offset detection method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for locating XML text
CN104537084A
Text processing method and device, and device for text processing
CN112199963A
