An out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation
By employing dual contrastive learning and covariance contraction shared estimation, the problems of inaccurate decision boundaries and poor robustness of out-of-domain intent detection models in low-resource scenarios are solved, achieving higher accuracy in in-domain intent classification and better out-of-domain sample rejection capability.
Patent Information
- Application Number
- CN202611675519.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-28
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies struggle to build robust out-of-domain intent detection models in low-resource scenarios, especially when there is anisotropy in the feature space, resulting in inaccurate decision boundary settings and poor robustness to out-of-domain sample detection.
We employ a dual contrastive learning and covariance contraction shared estimation approach. By optimizing sample features and classifier representations through dual contrastive loss, we jointly estimate the shared covariance matrix and construct the Mahalanobis distance decision region, thereby improving the accuracy and robustness of out-of-domain intent detection.
In low-resource scenarios, it significantly improves the accuracy of in-domain intent classification and the ability to reject out-of-domain samples, reduces the false acceptance rate of out-of-domain samples, and provides a robust decision boundary solution.
Smart Images

Figure CN123180169A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing, and in particular to an out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation. Background Technology
[0002] With the rapid development of human-computer interaction technology, intent recognition systems based on natural language processing have been widely applied in scenarios such as intelligent customer service, voice assistants, and smart home control. In practical applications, systems typically can only recognize known intent categories contained in the training data. However, user input is often highly open-ended and unpredictable, frequently resulting in "out-of-domain" input that does not belong to any known intent category. For example, in a flight booking scenario, a user might inquire about the weather or engage in casual conversation; these inputs fall under out-of-domain intents. If the system lacks effective out-of-domain intent detection capabilities, it will incorrectly force out-of-domain inputs into a known category, thereby providing incorrect services and severely impacting user experience and system reliability.
[0003] Existing methods for detecting out-of-domain intent can be broadly categorized into supervised and unsupervised methods. Supervised methods utilize both in-domain data and labeled out-of-domain data during the training phase, modeling the detection task as a K+1 class classification problem, where the K+1 class represents out-of-domain intent. Unsupervised methods, on the other hand, use only in-domain data during training to obtain the decision boundaries of the in-domain data, primarily focusing on the distribution and feature structure of the known data.
[0004] Existing unsupervised out-of-domain intent detection methods can be broadly categorized into two types based on the source of the detected signal: confidence-based methods and distance-based methods. Confidence-based methods utilize information from the model's output layer for discrimination; typical examples include maximum confidence-based methods. Probabilistic methods and energy-score methods are similar in that the former uses the maximum class probability output by the model as a confidence index, while the latter makes a judgment based on an energy scalar. Both methods directly utilize the output distribution of the classifier, making them simple to implement but susceptible to the overconfidence problem of neural networks.
[0005] Distance-based methods do not rely on classifier outputs but instead measure the deviation between test samples and the distribution within the domain in the model's feature space. Commonly used metrics include cosine similarity and Mahalanobis distance. Early adaptive decision boundary (ADB) methods learned an adaptive spherical boundary radius for each known class, defining the domain region by the class center and this radius. Building on this, distance-aware ADB (DA-ADB) further introduced distance-aware representation learning to enhance the discriminative power of the boundary. However, these methods all assume that the known clusters are isotropically spherically distributed in the feature space, defining the boundary solely by the class center and a single radius, which fails to capture the inherent anisotropy in the feature space of the pre-trained language model.
[0006] A novel ellipsoid-based decision boundary method for open intent classification is disclosed in the proceedings of the Association for the Advancement of Artificial Intelligence (AAAI) Conference, Volume 40, Issue 41: AAAI-26 Technical Track 41 - AAAI Natural Language Processing Technical Track VI. This method first employs supervised contrastive learning to obtain a discriminative feature space of known samples. Secondly, a learnable matrix is applied to parameterize the ellipse as the boundary for each known class. This provides greater flexibility than a spherical boundary defined solely by the radius under the center and Euclidean distance. Furthermore, a novel dual loss function is used to optimize the boundary, balancing empirical risk and open space risk: expanding the boundary to cover known samples on one hand, and contracting it for synthetic pseudo-open samples on the other.
[0007] The above scheme uses learnable matrix parameters to directly parameterize the ellipsoidal shape of each category. While this provides greater flexibility, the parameterization process is entirely driven by training data and lacks statistical prior constraints. In low-resource scenarios with a very small number of known categories or insufficient sample size within each category, the class-by-class learnable matrix is severely over-parameterized, easily overfitting to the local distribution pattern of the training set. This leads to degraded covariance estimation, distorted ellipsoidal boundary shape, and a significant decrease in the ability to reject and generalize from out-of-domain inputs. Furthermore, while synthetic pseudo-open samples are used to shrink the boundary, there may be a large distribution offset between the distribution of pseudo-open samples and the actual distribution of out-of-domain inputs. This makes the direction of boundary shrinkage lack a true basis, potentially leading to over-shrinking of key regions or deviation in the shrinkage direction, thereby impairing the actual detection performance for out-of-domain inputs.
[0008] How to get rid of overparameterization of class-by-class learnable covariance in low-resource scenarios, construct intra-domain decision boundaries that can characterize directional anisotropy in a statistically robust way, and get rid of dependence on synthetic pseudo-open samples has become an urgent problem to be solved in the field of extra-domain intent detection.
[0009] Therefore, this application proposes an out-of-domain intent detection method based on dual contrastive learning and covariance contraction shared estimation. By introducing a dual contrastive learning mechanism in the representation learning stage, the method strengthens the bidirectional alignment between sample features and classifier representation. It also uses the residual vectors of all known classes to jointly estimate a covariance matrix shared by all known classes. Combined with Ledoit-Wolf contraction estimation, a statistically robust single-precision matrix is obtained. This matrix is used to construct a Mahalanobis distance decision region shared by all known classes, effectively improving the accuracy and robustness of out-of-domain intent detection.
[0010] The above content is only used to help understand the technical solution of the present invention and does not represent an admission that the above content is prior art. Summary of the Invention
[0011] This invention proposes an out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation, aiming to solve the technical problems of weak feature representation ability, inaccurate decision boundary setting, and poor robustness to out-of-domain sample detection in existing intent recognition models.
[0012] To achieve the above objectives, this invention proposes an out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation, comprising the following steps: S1. Obtain the input text and its corresponding K learnable category embedding vectors. Input the input text and the K learnable category embedding vectors into the encoder for encoding. Extract sample features from the encoding output and extract the classifier representation associated with the sample from the encoding output. S2. In the representation learning stage, based on the sample features and classifier representation, the sample features and classifier representation are jointly optimized through dual contrastive loss; and supervised contrastive loss is used to increase the similarity between features of the same type of samples and reduce the similarity between features of different types of samples; the total loss is jointly minimized to complete the representation learning, and the total loss includes at least classification loss, dual contrastive loss and supervised contrastive loss. S3. Boundary discrimination stage: Determine class centers for each class based on the features of training samples from all known classes; estimate the covariance matrix shared by all known classes based on the residual vectors of all training samples of all known classes relative to their respective class centers; shrink the covariance matrix to a scalar multiple of the identity matrix to obtain a single-precision matrix shared by all known classes; construct the Mahalanobis distance decision region for each known class using the class centers of each known class and the single-precision matrix; and set distance thresholds for each class. S4. For a test sample, determine a candidate category based on the distance between its sample features and the class centers of each category; calculate the Mahalanobis distance from the sample features of the test sample to the class center of the candidate category based on the single precision matrix; if the Mahalanobis distance is greater than the distance threshold corresponding to the candidate category, then determine that the test sample belongs to an out-of-domain category, otherwise determine that it belongs to the candidate category.
[0013] Preferably, in step S1, the encoder is a pre-trained language model encoder; The sample features are extracted by performing mean pooling on the hidden representations of all text region positions in the encoded output, and mapping the pooling results to the discrimination space via a mapping head. The extraction method of the classifier representation is as follows: directly take the hidden representation corresponding to the embedding vector position of the K learnable categories in the encoding output, and map it to the discrimination space through the same mapping head.
[0014] Preferably, in step S2, the dual contrast loss includes two symmetrical components: sample feature direction contrast loss and class anchor point direction contrast loss. The classifier corresponding to the same class of samples is used as the positive sample anchor point, and the classifier corresponding to the opposite class of samples is used as the negative sample anchor point. The spacing correction includes: setting an upper limit value for the cosine similarity between any two sample features, subtracting a first preset value from the cosine similarity between similar sample pairs, and adding a second preset value to the cosine similarity between dissimilar sample pairs. The classification loss is the cross-entropy loss, which is calculated using the inner product of the sample features and the classifier representation as classification logits.
[0015] Preferably, in step S2, the sample feature orientation contrast loss uses the sample features as anchors and the classifier representation as the target to be compared. The anchor-point orientation contrast loss uses the classifier as the anchor and the sample features as the target to be compared.
[0016] Preferably, in step S2, the upper limit value, the first preset value, and the second preset value in the supervised contrast loss are all preset constants, and the upper limit value is less than 1, while the first preset value and the second preset value are both greater than 0.
[0017] Preferably, step S3 further includes: A learnable distance threshold parameter is set for each known category, wherein the distance threshold parameter is mapped by the softplus function and used as the distance threshold for that category, and is iteratively updated under asymmetric hinge loss.
[0018] Preferably, in step S3, the asymmetric hinge loss is a weighted sum of the first and second terms; both the first and second terms are calculated based solely on the Mahalanobis distance of the known class training samples; the first term is the sum of the amounts by which the Mahalanobis distance of all known class training samples exceeds the distance threshold of their respective classes, used to increase the distance threshold; the second term is the sum of the amounts by which the distance threshold of all known class training samples exceeds the product of their Mahalanobis distance and a preset scaling factor, used to decrease the distance threshold.
[0019] Preferably, in step S3, when the distance threshold is iteratively updated under the asymmetric hinge loss, the learnable distance threshold parameter is randomly initialized with a standard normal distribution. In each iteration, the softplus function value is first calculated as the distance threshold, and then the gradient is calculated by substituting it into the asymmetric hinge loss and backpropagated to update the learnable distance threshold parameter.
[0020] Preferably, in step S4, the sample features of the test sample are normalized using the L2 norm before calculating the Euclidean distance and the Mahalanobis distance.
[0021] The beneficial effects of the technical solution of this invention are as follows: The dual contrastive learning framework is adopted, using the bidirectional contrastive relationship between sample features and their corresponding classifier representations as a supervision signal. This ensures that each sample has a definite positive sample of the same class, avoiding the dependence of traditional supervised contrastive learning on the availability of positive samples of the same class within a batch. This scheme decouples class and instance information and performs joint training from the perspectives of class and instance, and instance and instance. It can effectively improve the quality of representation distribution and is particularly suitable for low-resource scenarios with a large number of known intent categories or limited batch size.
[0022] By introducing a triple-margin correction mechanism into the supervised contrastive loss—applying an upper bound to the cosine similarity of sample pairs, a negative margin to similar pairs, and a positive margin to dissimilar pairs—the model is forced to align positive samples and separate negative samples with a larger cosine margin, ensuring a synergistic improvement in intra-class compactness and inter-class separation. The distribution of known clusters in the learned representation space becomes more regular, and the separability between intra-domain samples and potential out-of-domain samples under distance metrics is significantly enhanced, thus providing a high-quality feature foundation for downstream decision-making region discrimination.
[0023] In the boundary discrimination stage, a single shared precision matrix is used instead of the existing method of learning the covariance matrix for each known category. This significantly reduces the parameter size of covariance estimation compared to the independent estimation method for each category, and maintains robust covariance estimation even in extreme scenarios with a low proportion of known intentions or a very small number of categories. The closed-form shrinkage coefficient is directly solved from the training sample residuals, eliminating the need for parameter tuning through a validation set grid search. This provides a parameter-efficient and easy-to-implement Mahalanobis distance decision boundary solution for engineering applications.
[0024] By employing a two-stage collaborative design of representation learning and boundary discrimination, the learned decision boundary becomes more stable, significantly improving upon existing methods in both the in-domain intent classification and out-of-domain sample rejection objectives. This not only significantly enhances the classification accuracy of in-domain intents but also effectively strengthens the ability to reject out-of-domain samples, thereby reducing the false acceptance rate of out-of-domain samples while ensuring the correct classification of known intents. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of the overall structure of the model in a specific application example of the present invention; Figure 2 This is a flowchart of the intent detection system in a specific application example of the present invention; Figure 3 This is a diagram illustrating the steps of the representation learning stage in a specific application example of the present invention; Figure 4 This is a flowchart illustrating the adaptive boundary learning stage in a specific application example of the present invention. Figure 5 This is a visualization of the StackOverflow dataset in the Kaggle technical Q&A community scenario, as a specific application example of the present invention.
[0026] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0027] The solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0028] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indication will also change accordingly.
[0029] It should also be noted that when a component is described as "fixed to" or "set on" another component, it can be directly on the other component or there may be an intervening component present. When a component is described as "connected to" another component, it can be directly connected to the other component or there may be an intervening component present.
[0030] Furthermore, descriptions using terms such as "first" and "second" in this invention are for descriptive purposes only (e.g., to distinguish identical or similar elements) and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" and "second" may explicitly or implicitly include at least one of those features. Additionally, technical solutions from different embodiments can be combined with each other, but only if they are feasible for those skilled in the art. If a combination of technical solutions is contradictory or impossible to implement, such a combination should be considered nonexistent and not within the scope of protection claimed by this invention.
[0031] Intent recognition is one of the core subtasks in task-oriented dialogue systems. In real-world human-computer interaction scenarios, user input is highly open-ended and diverse, and predefined intent categories often cannot cover all user needs. Out-of-domain intent detection is a research task proposed to address this problem. Predefined intent categories are called in-domain intents, while user input expressing intents outside the predefined range is called out-of-domain intents. The goal of out-of-domain intent detection is to accurately classify in-domain intents while recognizing out-of-domain intents and refusing to provide erroneous responses.
[0032] Existing methods for detecting out-of-domain intent can be broadly categorized into supervised and unsupervised methods. Supervised methods utilize both in-domain data and labeled out-of-domain data during the training phase, modeling the detection task as a K+1 class classification problem, where the K+1 class represents out-of-domain intent. Unsupervised methods, on the other hand, use only in-domain data during training to obtain the decision boundaries of the in-domain data, primarily focusing on the distribution and feature structure of the known data.
[0033] Existing unsupervised out-of-domain intent detection methods can be broadly categorized into two types based on the source of the detected signal: confidence-based methods and distance-based methods. Confidence-based methods utilize information from the model's output layer for discrimination; typical examples include maximum confidence-based methods. Probabilistic methods and energy-score methods differ in that the former uses the maximum class probability output by the model as a confidence metric, while the latter uses an energy scalar for discrimination. Both methods directly utilize the classifier's output distribution, making them simple to implement but susceptible to the overconfidence problem inherent in neural networks. Distance-based methods, on the other hand, do not rely on the classifier output but instead measure the deviation between the test sample and the domain distribution within the model's feature space. Commonly used metrics include cosine similarity and Mahalanobis distance.
[0034] In recent years, the introduction of contrastive learning has significantly improved distance-based methods. By constructing positive and negative sample pairs, contrastive learning brings similar samples closer together and distancing dissimilar samples in the feature space, enabling the model to learn more discriminative feature representations and thus increasing the difference in distance metrics between intra-domain and out-of-domain samples. Supervised contrastive learning further utilizes label information to construct positive and negative samples, achieving more compact intra-class aggregation and greater inter-class separation compared to self-supervised contrastive learning. Building on this, researchers have proposed various improvement strategies to further optimize the structure of the feature space, such as learning a spherical decision region for each known intent class through adaptive decision boundaries, introducing local structural information through K-nearest neighbor contrastive learning, and enhancing inter-class separation through labeled prototype networks.
[0035] In adaptive decision boundary methods, traditional decision boundary learning methods assume that each known cluster is isotropically spherically distributed in the feature space. This fails to capture the inherent anisotropy of pre-trained language models like BERT in the representation space, leading to either an overly loose or overly tight fit of the boundary to the clusters. While recent methods like EliDecide introduce ellipsoidal morphology to enhance the geometric flexibility of the boundary, they independently learn a high-dimensional covariance matrix for each class. In extreme scenarios where the proportion of known classes is low or the number of classes is extremely small, severe overparameterization leads to degraded covariance estimation and distorted boundary morphology.
[0036] This invention proposes an out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation, comprising the following steps: S1. Obtain the input text and its corresponding K learnable category embedding vectors. Concatenate the input text and the K learnable category embedding vectors into an augmented input sequence. Encode the augmented input sequence using an encoder. Extract sample features from the text region of the encoded output. Extract the classifier representation associated with the sample from the position corresponding to the K learnable category embedding vectors in the encoded output.
[0037] In a preferred embodiment, the encoder is a pre-trained language model encoder, such as BERT or RoBERTa. The encoder processes the augmented input sequence and outputs the encoded output.
[0038] The sample features are used to correspond to parts of the input text. Specifically, they are extracted by performing mean pooling on the hidden representations of all text region positions in the encoded output to obtain a comprehensive text representation. Then, the pooling result is mapped to the discriminant space via a mapping head to obtain the sample features.
[0039] The classifier representation is used for the portion corresponding to the K learnable class embedding vectors. Specifically, it is extracted by directly taking the hidden representations corresponding to the positions of the K learnable class embedding vectors in the encoded output and mapping them to the discrimination space via the same mapping head. This ensures that the sample features and the classifier representation are in the same high-dimensional feature space, facilitating subsequent distance calculations and comparative learning.
[0040] Furthermore, such as Figure 1 The diagram shown is a schematic representation of the overall model structure according to an embodiment of the present invention. This structure includes two stages: representation learning and boundary learning.
[0041] Furthermore, the specific training and testing procedures are as follows: Figure 2 As shown.
[0042] S2. In the representation learning stage, based on the sample features and classifier representations obtained in step S1, the sample features and classifier representations are jointly optimized in the same representation space through dual contrastive loss; and supervised contrastive loss with margin correction is used to enhance the similarity between features of similar samples and reduce the similarity between features of dissimilar samples; the total loss is jointly minimized to complete the representation learning, and the total loss is the weighted sum of classification loss, dual contrastive loss and supervised contrastive loss. In a preferred embodiment, the dual contrast loss includes two symmetrical components: sample feature direction contrast loss and class anchor point direction contrast loss, wherein the classifier corresponding to the same class of samples is used as the positive sample anchor point, and the classifier corresponding to the opposite class of samples is used as the negative sample anchor point. The spacing correction includes: setting an upper limit value for the cosine similarity between any two sample features, subtracting a first preset value from the cosine similarity between similar sample pairs, and adding a second preset value to the cosine similarity between dissimilar sample pairs. The classification loss is the cross-entropy loss, which is calculated using the inner product of the sample features and the classifier representation as classification logits.
[0043] In a more preferred embodiment, the sample feature orientation contrast loss uses the sample features as anchors and the classifier representation as the target to be compared. The anchor-point orientation contrast loss uses the classifier as the anchor and the sample features as the target to be compared.
[0044] Furthermore, the upper limit value, the first preset value, and the second preset value in the supervised comparison loss are all preset constants, and the upper limit value is less than 1, while the first preset value and the second preset value are both greater than 0.
[0045] like Figure 3 As shown, the representation learning stage is a joint loss training based on dual contrastive learning. This training method is an introduction of a dual contrastive learning framework and includes the following steps: The sample features extracted in step S1 are multiplied by the inner product of the extracted K classifier representations to obtain the classification logits for the K categories. These logits are then compared with the true intent label of the input text, and the standard cross-entropy loss is calculated as the classification loss. A bidirectional symmetric contrastive learning mechanism is constructed. Specifically, the target classifier representation corresponding to samples of the same class is used as the positive sample anchor, and the target classifier representation corresponding to samples of different classes is used as the negative sample anchor. Symmetric contrastive terms are constructed in both directions, "from sample features to classifier representation" and "from classifier representation to sample features," respectively, and the dual contrastive loss is calculated. For sample features within the same batch, forward propagation is performed through two different Dropout operations to obtain two view features. A cosine upper bound is applied to the cosine similarity between these two view features; simultaneously, a negative spacing is applied to pairs of similar samples (to encourage features to move closer together), and a positive spacing is applied to pairs of dissimilar samples (to encourage features to move further apart), thus obtaining a triple-spacing supervised contrastive loss. The classification loss, dual contrastive loss, and triple-margin supervised contrastive loss calculated above are weighted and summed according to predetermined weights to form the total loss. This total loss is then used to iteratively update the parameters of the BERT encoder and the parameters of the K learnable intent embeddings (i.e., classifier representations) through backpropagation until the validation set metrics converge, completing the training of the representation learning phase.
[0046] Specifically, cross-entropy loss, dual contrast loss, and band loss are also set. A training mechanism that jointly optimizes supervised contrastive loss and constrained input is proposed. It is used to simultaneously obtain sample-level and class-level discriminative features in the same forward computation, and to shape the representation distribution through sample-side compactness constraints and class-side alignment constraints.
[0047] It employs the DualCL framework to simultaneously obtain the sample-level representation and the category-level representation related to the current input in the same forward computation.
[0048] Specifically, given the input sentence Construct an enhanced input sequence: ; in express There are several learnable class embedding vectors. The augmented input sequence is encoded by the BERT encoder to obtain the hidden representations of the last layer of BERT at all locations. ,in The total length of the sequence. express In sequence position The hidden representation vector at that location.
[0049] To obtain sample-level discriminative features Average pooling is performed on the vectors at all text region locations to obtain the aggregated text representation. The aggregated representation is then mapped to the discriminative space through a pooling mapping head consisting of a dense layer, ReLU activation, and Dropout. ; in , These are the learnable parameters for the mapping header.
[0050] For categorical features, directly take the BERT output at the position. The hidden representation at the location is denoted as By mapping to the same discrimination space through a mapping head that shares the same set of parameters with the sample side, we obtain... Category-level features: ; This design enables the simultaneous generation of sample-level features in each forward computation. Compared with category-level features Since both are located in the same discriminative feature space, they can directly perform inner product operations and contrastive learning, thereby supporting bidirectional semantic interaction between samples and categories.
[0051] To simultaneously optimize classification accuracy, sample-class alignment tightness, and inter-class geometric separability, this chapter introduces a three-loss co-training approach.
[0052] Cross-entropy loss: utilizing sample features With each category feature Primitive inner product construction The logit class supervises the classification accuracy of known classes using standard cross-entropy loss. , ; in Indicates sample The true intention of the label.
[0053] Dual contrastive loss: Treats sample representations and class representations as two heterogeneous views under the same label, and uses contrastive loss to bring them closer together bidirectionally. Push away the different : ; in For temperature coefficient, For batch size, and Representing samples respectively Normalized sample features and their true class-level features.
[0054] bring Constrained Supervised Contrast Loss: To obtain sample representations that are both compact and preserve open space, this chapter introduces a triple-constrained supervised contrast loss in addition to the standard supervised contrast loss. Constraints. Specifically, for each sample, through Data augmentation obtains two views and combines the two views within a batch into a single view. Dimension represents a matrix.
[0055] remember To construct a matrix representing the complete set of sample indices, To remove anchor points All sample index sets other than For anchor point A set of positive sample indices of the same type.
[0056] set up For the sample With sample Normalized cosine similarity, with The constrained similarity is: ; in Cut off by cosine , and Add to the same type and different types respectively . triple Each plays a different role in the representation space: Cosine truncation Set an upper limit on the similarity of all sample pairs. When the similarity of pairs of the same class exceeds the threshold, their gradients are truncated to suppress intra-class collapse. Similar negative spacing Subtract from the similarity of similar pairs This forces the model to be able to classify two samples as positive samples only when the alignment is higher, thus strengthening intra-class consistency; Heterogeneous positive spacing Add to the similarity of heterogeneous pairs ,exist The contribution of dissimilar pairs is amplified in the denominator, thus increasing the inter-class distance.
[0057] Based on the standard supervised contrast loss, the original similarity is replaced with the adjusted similarity to obtain the final band. Constraint-based supervised contrast loss: ; in This is the temperature coefficient.
[0058] The weighted combination of the above three losses is the overall optimization objective: ; in These are the weighting coefficients for each loss component.
[0059] S3. After completing representation learning, proceed to the boundary discrimination stage. Calculate the mean of all training sample features in each known category as the class center of that category. Calculate the residual vector between each training sample feature and the class center of its category. Based on the residual vectors of all training samples in all known categories, jointly estimate a covariance matrix shared by all known categories. Shrink the shared covariance matrix to a scalar multiple of the identity matrix. The shrinkage coefficient is solved by the Ledoit-Wolf formula in closed form using the residual vectors of all training samples. Invert the shrunken covariance matrix to obtain the precision matrix. Construct Mahalanobis distance decision regions for each known category using the class centers of each known category and the shared single precision matrix. Each known category shares the same precision matrix and is distinguished only by its own class center.
[0060] In a preferred embodiment, the asymmetric hinge loss is a weighted sum of a first term and a second term; both the first and second terms are calculated based solely on the Mahalanobis distance of the training samples of known categories; the first term is the sum of the amounts by which the Mahalanobis distance of all training samples of known categories exceeds the distance threshold of their respective categories, used to increase the distance threshold; the second term is the sum of the amounts by which the distance threshold of all training samples of known categories exceeds the product of their Mahalanobis distance and a preset scaling factor, used to decrease the distance threshold.
[0061] In addition, it also includes: setting a learnable distance threshold parameter for each known category, wherein the distance threshold parameter is mapped by the softplus function and used as the distance threshold for that category, and is iteratively updated under asymmetric hinge loss.
[0062] Specifically, in this embodiment, for each test sample, the Euclidean distance from the sample features of the test sample to the class center of each class is calculated sequentially, and the class center with the smallest Euclidean distance is selected as the candidate class center; the Mahalanobis distance from the sample features of the test sample to the candidate class center is calculated, and the Mahalanobis distance is calculated based on the precision matrix; if the Mahalanobis distance is greater than the distance threshold of the class to which the candidate class center belongs, the test sample is determined to be an out-of-domain class, otherwise the test sample is determined to be an in-domain class to which the candidate class center belongs.
[0063] In a preferred embodiment, when the distance threshold is iteratively updated under the asymmetric hinge loss, the learnable distance threshold parameter is randomly initialized with a standard normal distribution. In each iteration, the softplus function value is first calculated as the distance threshold, and then the gradient is calculated by substituting it into the asymmetric hinge loss and backpropagated to update the learnable distance threshold parameter.
[0064] In a more preferred embodiment, the sample features of the test samples are normalized using the L2 norm before calculating the Euclidean and Mahalanobis distances.
[0065] like Figure 4 As shown, the boundary learning stage is a decision boundary optimization based on Mahalanobis distance with covariance shrinkage. This decision boundary is determined by three factors: the centroid of each known class. A single-precision matrix shared by all known categories (composed of the shrunken covariance matrix). Taking the inverse yields the unified form that determines various decision regions, as well as the adaptive distance threshold for each class. This includes the following steps: Acquire the sample features from the completed Phase 1 training. These sample features are encoded by BERT and obtained through masked mean pooling, and have been projected onto a unit sphere under L2 normalization.
[0066] The features of the training set samples are aggregated according to the known intent categories, the class center of each known intent category is calculated, and the geometric center position of each known intent category in the representation space is obtained.
[0067] Calculate the residuals of all training samples relative to their respective class centers, and use the sample covariance corresponding to all residuals as the statistical description of the within-class distribution to obtain the shared sample covariance matrix.
[0068] Closed-loop shrinkage is applied to the sample covariance, and it is then fused with the isotropic target matrix by a weighted average of the shrinkage coefficients. The inverse matrix of the shrinkage covariance is then taken as the accuracy matrix shared by all known intent classes.
[0069] During the online inference phase, L2-normalized features are extracted from the sample to be detected. The nearest class center index is first determined in the sense of Euclidean distance. Then, the Mahalanobis distance between the sample and the class center and the corresponding class threshold are compared to determine whether it is an intra-domain intent or an extra-domain intent of that class.
[0070] For each known intent class, a learnable threshold parameter is constructed as the Mahalanobis distance threshold for that class. The thresholds for each class are iteratively updated under loss-driven conditions until the validation set metrics converge.
[0071] Specifically, the pre-trained model obtained from the first stage of representation training is used in the training set. Forward inference extracts the discriminative features of each training sample. For the first A class, whose centroid is defined as the mean of the features of all samples in that class: ; in Indicates the first training set The number of samples in the class.
[0072] Then, the covariance matrix is statistically analyzed, and a shared covariance matrix is jointly estimated. ; in The total number of samples in the training set is determined. Then, a closed-form contraction estimation is introduced to direct the sample covariance towards an isotropic objective. shrink: ; in It is a D-dimensional identity matrix. for The eigenvalue mean (as a scalar of an isotropic target). This refers to the shrinkage strength. Automatic estimation from data using the Ledoit-Wolf closed-form formula. Define known class samples and the... The Mahalanobis distance between centroids is: ; because This distance is shared by all classes and is equivalent to all classes sharing the same boundary shape, differing only in the centroid location and the distance threshold.
[0073] After determining the boundary geometry, the actual decision boundary also requires a distance threshold for each class. This chapter introduces a learnable scalar parameter for each known class. The distance threshold is mapped to a strictly positive value through the activation function:
[0074] First item This measures how much the Mahalanobis distance of samples from a known class exceeds a distance threshold for that class, and is used to increase that distance threshold. ; Second item This measures how small the Mahalanobis distance of a known class of samples is relative to a distance threshold for that class, and is used to reduce that distance threshold. ; The two factors are weighted and summed using a tradeoff coefficient to form the boundary training total loss: ; Trade-off coefficient This determines the relative strength of the two losses in the optimization process.
[0075] Thus, we obtain the covariance shrinkage decision boundary with shape sharing and variable distance threshold.
[0076] After completing the second phase of decision boundary training, the centroid is used. Shrinking covariance With adaptive distance threshold The three elements are used for reasoning on the test samples. For the test samples, the discriminative features are first extracted by the encoder and the pooling mapping head. Then, the two steps of category pre-selection and boundary determination are performed in sequence.
[0077] Category pre-selection: Calculate the Euclidean distance from the sample features to the centroids of all known classes, and select the closest class as the candidate class. ; Boundary determination: Calculate the distance from the sample to the centroid of the candidate class. If the distance exceeds the adaptive distance threshold corresponding to the class, it is determined to be an out-of-domain sample; otherwise, it is classified into the candidate class.
[0078] ; ; Through a two-step reasoning mechanism of Euclidean distance pre-selection and boundary determination, the model completes two tasks—known intent classification and out-of-domain intent detection—within the same framework.
[0079] like Figure 5As shown, Stack Overflow is a benchmark dataset for domain intent recognition in developer question-and-answer scenarios, originating from the world's largest technical question-and-answer community for programmers. This dataset contains 20 independent technical intent categories, covering multiple technical fields such as mainstream programming languages, frameworks, and development tools. In this experiment, 5 intent categories were used as known in-domain intents for training and testing, while the remaining 15 intent categories were considered unknown in-domain intents and only appeared during the testing phase. During the training phase, only in-domain data participated in representation learning and boundary learning.
[0080] Figure 5 (a) is a t-SNE two-dimensional projection drawn according to the true intent labels. Five shapes are used to represent the test samples of the five known intent categories in the domain (visual-studio, apache, wordpress, linq, matlab), and × is used to represent the test samples of all 15 intent categories outside the domain. It can be seen that in the representation space learned by the method of this invention, the intent categories in the domain form compact clusters and are separated from each other, while the intent samples outside the domain are scattered in the transition area between the clusters in the domain. This reflects the compactness and separability of the clusters in the domain achieved by this method in the representation learning stage.
[0081] Figure 5 (b) To mark the prediction results of the decision boundary learned by this method for the same t-SNE two-dimensional projection, that is, after performing the nearest class center pre-selection in the sense of Euclidean distance and the decision region determination in the sense of Mahalanobis distance for each test sample, the samples determined to be in-domain intentions are displayed with the shape corresponding to their class, and the Mahalanobis distance decision regions of each known class are superimposed (dashed ellipses in the figure), and the samples determined to be out-of-domain intentions are displayed outside each decision region with × mark.
[0082] Compare Figure 5 (a) and Figure 5 (b) As can be seen, the method of the present invention can correctly classify intra-domain intent samples into corresponding clusters and correctly reject intra-domain intent samples outside each decision region. The shape label distribution of intra-domain clusters is highly consistent with the distribution under the real labels, and the intra-domain regions marked with × are also highly consistent with the intra-domain regions under the real labels. After the first stage of representation training and the second stage of boundary training, the learned decision boundaries meet the design expectations, realizing intra-domain classification and intra-domain intent detection.
[0083] To further quantitatively verify the effectiveness of the method described in this embodiment, two publicly available intent recognition datasets, BANKING and SNIPS, were introduced for comparative verification, building upon the StackOverflow dataset mentioned above. BANKING is a fine-grained intent recognition dataset for the banking customer service domain, containing 77 intent categories; SNIPS is an intent recognition dataset for intelligent voice assistants, containing 7 intent categories. Based on the open-world assumption, the proportion of known categories in each dataset was set to 25%, 50%, and 75% of the total number of categories, respectively. The remaining categories were considered out-of-domain intents, and out-of-domain intent samples were not used in training and validation, only introduced during the testing phase. Evaluation metrics included overall accuracy (ACC), macro-average F1 score, and F1 scores (F1-known and F1-open) for in-domain and out-of-domain categories, respectively, to comprehensively reflect the performance of each method in both in-domain intent classification and out-of-domain intent rejection.
[0084] To ensure fairness in the comparison, the method in this embodiment was evaluated under the same experimental conditions as the comparison methods: all used the same BERT-based pre-trained model as the encoder, and the feature dimension was 768; the in-domain and out-of-domain classifications of each dataset were completely identical under the three known class ratios; each dataset and combination of known class ratios was repeatedly experimented with the same 5 random seeds, and the average value was taken. The differences between the comparison methods lie only in the way the representation learning and decision boundary are constructed. The methods compared include: ADB, which learns an isotropic spherical boundary for each known class; DA-ADB, which introduces distance awareness on the basis of ADB; and EliDecide, which independently learns the covariance matrix for each known class to parameterize the ellipsoid shape.
[0085] Table 1 shows a comparison of the overall accuracy and macro-average F1 score of each method under different known class proportions, while Table 2 shows a comparison of in-domain class F1 (F1-known) and out-of-domain class F1 (F1-open).
[0086] Table 1. Comparison of ACC and F1 scores for different methods under different known class proportions.
[0087] Table 2. Comparison of F1-known and F1-open methods for different proportions of known categories.
[0088] As shown in Tables 1 and 2, the overall performance of the method in this embodiment is superior to the comparative methods mentioned above on all three datasets. This advantage stems from the synergistic effect of the two stages. On the one hand, in the representation learning stage, this embodiment improves intra-class compactness and suppresses excessive aggregation of similar samples by using dual contrast and distance constraints, thus preserving an open space for identifiable out-of-domain intents and obtaining a high-quality intent representation that is both intra-class compact and conducive to open discrimination. On the other hand, in the boundary discrimination stage, this embodiment replaces the class-by-class learning of the covariance matrix with a shrinking covariance estimate shared by all known categories, reducing the amount of covariance parameters from K×D², which increases with the number of categories and the square of the feature dimension, to D² (where K is the number of intra-domain categories and D is the feature dimension 768).
[0089] The advantages of the two-stage collaboration described above are particularly evident on the SNIPS dataset, which has a very small number of known categories. SNIPS contains only 7 intent categories, and with a known category ratio of 25%, the number of known categories available for training is extremely limited, representing a typical low-resource scenario. Under this setting, EliDecide, which learns the covariance matrix independently for each known category, performs poorly, with its F1 score and out-of-domain F1 score (F1-open) dropping sharply to 49.79% and 16.79%, respectively, meaning it almost fails to achieve the core objective of out-of-domain intent rejection. In contrast, this embodiment, through the combination of shared shrinkage covariance estimation and discriminative representation, still achieves F1 scores and out-of-domain F1 scores as high as 92.49% and 95.72%, respectively, under the same setting. This demonstrates that the method in this embodiment can maintain robust out-of-domain intent detection performance in low-resource scenarios with a very small number of known categories, significantly enhancing the ability to reject out-of-domain intents while ensuring the accuracy of in-domain intent classification.
[0090] Furthermore, this invention also proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the aforementioned out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation. When executed, the computer program may include the flowcharts of the respective embodiments of the out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation described above. Any references to memory, storage, databases, or other media used in this application and its embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0091] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation that includes a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, apparatus, article, or out-of-domain intent detection method. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage shared estimation that includes the element.
[0092] The above description is only a preferred embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural changes made based on the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A method for detecting out-of-domain intent based on dual contrastive learning and covariance shrinkage sharing estimation, characterized in that, Includes the following steps: S1. Obtain the input text and its corresponding K learnable category embedding vectors. Input the input text and the K learnable category embedding vectors into the encoder for encoding. Extract sample features from the encoding output and extract the classifier representation associated with the sample from the encoding output. S2, Representation learning stage: Based on the sample features and classifier representation, the sample features and classifier representation are jointly optimized by dual contrastive loss; Supervised contrastive loss is used to enhance the similarity between features of similar samples and reduce the similarity between features of dissimilar samples; the total loss is jointly minimized to complete representation learning, wherein the total loss includes at least classification loss, dual contrastive loss and supervised contrastive loss; S3, Boundary discrimination stage: Determine the class centers of each class based on the features of training samples of all known classes; Based on the residual vectors of all training samples of all known categories relative to their respective class centers, the covariance matrix shared by all known categories is estimated; the covariance matrix is scalar-folded to the identity matrix to obtain a single-precision matrix shared by all known categories; the Mahalanobis distance decision region for each known category is constructed using the class centers of each known category and the single-precision matrix; and a distance threshold is set for each category. S4. For a test sample, determine a candidate category based on the distance between its sample features and the class centers of each category; calculate the Mahalanobis distance from the sample features of the test sample to the class center of the candidate category based on the single precision matrix; if the Mahalanobis distance is greater than the distance threshold corresponding to the candidate category, then determine that the test sample belongs to an out-of-domain category, otherwise determine that it belongs to the candidate category.
2. The out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage sharing estimation according to claim 1, characterized in that, In step S1, the encoder is a pre-trained language model encoder; The sample features are extracted by performing mean pooling on the hidden representations of all text region positions in the encoded output, and mapping the pooling results to the discrimination space via a mapping head. The extraction method of the classifier representation is as follows: directly take the hidden representation corresponding to the embedding vector position of the K learnable categories in the encoding output, and map it to the discrimination space through the same mapping head.
3. The out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage sharing estimation according to claim 1, characterized in that, In step S2, the dual contrast loss includes two symmetric components: sample feature direction contrast loss and class anchor point direction contrast loss. The classifier corresponding to the same class of samples is used as the positive sample anchor point, and the classifier corresponding to the opposite class of samples is used as the negative sample anchor point. The spacing correction includes: setting an upper limit value for the cosine similarity between any two sample features, subtracting a first preset value from the cosine similarity between similar sample pairs, and adding a second preset value to the cosine similarity between dissimilar sample pairs. The classification loss is the cross-entropy loss, which is calculated using the inner product of the sample features and the classifier representation as classification logits.
4. The out-of-domain intent detection method based on dual contrastive learning and covariance contraction sharing estimation according to claim 3, characterized in that, The sample feature orientation contrast loss uses the sample features as anchors and the classifier as the target to be compared. The anchor-point orientation contrast loss uses the classifier as the anchor and the sample features as the target to be compared.
5. The out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage sharing estimation according to claim 4, characterized in that, The upper limit, the first preset value, and the second preset value in the supervised comparison loss are all preset constants, and the upper limit is less than 1, while the first preset value and the second preset value are both greater than 0.
6. The out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage sharing estimation according to claim 1, characterized in that, Step S3 also includes: A learnable distance threshold parameter is set for each known category, wherein the distance threshold parameter is mapped by the softplus function and used as the distance threshold for that category, and is iteratively updated under asymmetric hinge loss.
7. The out-of-domain intent detection method based on dual contrastive learning and covariance contraction sharing estimation according to claim 6, characterized in that, In step S3, the asymmetric hinge loss is a weighted sum of the first and second terms; and both the first and second terms are calculated based solely on the Mahalanobis distance of the known class training samples; the first term is the sum of the excess amounts of the Mahalanobis distance of all known class training samples that are greater than the distance threshold of their respective classes, used to increase the distance threshold; the second term is the sum of the excess amounts of the distance threshold of all known class training samples that are greater than the product of their Mahalanobis distance and a preset scaling factor, used to decrease the distance threshold.
8. The out-of-domain intent detection method based on dual contrastive learning and covariance contraction sharing estimation according to claim 7, characterized in that, In step S3, when the distance threshold is iteratively updated under the asymmetric hinge loss, the learnable distance threshold parameter is randomly initialized with a standard normal distribution. In each iteration, the softplus function value is first calculated as the distance threshold, and then the gradient is calculated by substituting it into the asymmetric hinge loss and backpropagating to update the learnable distance threshold parameter.
9. The out-of-domain intent detection method based on dual contrastive learning and covariance shrinkage sharing estimation according to claim 1, characterized in that, In step S4, the sample features of the test sample are normalized by L2 norm before calculating the Euclidean distance and Mahalanobis distance.
