From Zero to Hero: Cold-Start Anomaly Detection (2024)

Abstract: When first deploying an anomaly detection system, e.g., to detect out-of-scope queries in chatbots, there are no observed data, making data-driven approaches ineffective. Zero-shot anomaly detection methods offer a solution to such "cold-start" cases, but unfortunately they are often not accurate enough. This paper studies the realistic but underexplored cold-start setting where an anomaly detection model is initialized using zero-shot guidance, but subsequently receives a small number of contaminated observations (namely, that may include anomalies). The goal is to make efficient use of both the zero-shot guidance and the observations. We propose ColdFusion, a method that effectively adapts the zero-shot anomaly detector to contaminated observations. To support future development of this new setting, we propose an evaluation suite consisting of evaluation protocols and metrics.

heading: 1 Introduction
text: Anomaly detection methods aim to flag data that violate accepted norms. For example, a customer support chatbot may be designed to answer queries about particular intents (in-scope) but not about other intents (out-of-scope). Unlike related tasks such as out-of-scope intent discovery and classification, which rely on large labeled in-scope data, anomaly detection approaches relax the labeling assumption and treat the problem as a one-class classification task (Lin et al., 2020; Zhang et al., 2021b; Mou et al., 2022; Zheng et al., 2020; Zhan et al., 2021; Lin and Xu, 2019; Zeng et al., 2021; Zhang et al., 2021a; Xu et al., 2020). Most anomaly detection methods (Reiss et al., 2021; Qiu et al., 2021; Zhang et al., 2023) require previous observations for training and are effective when many past observations are available. Such methods are not effective for systems just after deployment, as they lack access to any past observations. Zeroshot anomaly detection (Jeong et al., 2023; Li et al.,
2024; Zhou et al., 2024) uses descriptions of the normal classes and does not require training data. While zero-shot methods can be used for freshly deployed systems, they result in reduced accuracy as the descriptions often fail to properly express the distribution of real data.
We explore the cold-start setting which provides two types of guidance: i) a textual description of each normal class, serving as initial guidance, such as predefined topic names in chatbot systems; ii) a stream of t contaminated observations (that may include anomalies), e.g., real user queries. It is particularly relevant in real-world applications where, shortly after deployment, a short stream of user queries becomes available but the queries are not labeled into intent types and some of them are outof-scope. To our knowledge, the only work that deals with a similar setting (Jeong et al., 2023) assumes prior knowledge of anomalies, that observations come from a single normal class and that they are not contaminated by anomalies.
To tackle the cold-start setting, we present ColdFusion, a method for adapting a zero-shot model given the distribution of a limited observation stream. Our method is very effective, achieving considerably better results than pure zero-shot and observation-based methods. To encourage future research on this promising new setting, we provide evaluation protocols and metrics. Our contributions are:
1. Proposing the new setting of cold-start anomaly detection.
2. Presenting ColdFusion for tackling the setting.
3. Introducing a dedicated evaluation suite consisting of evaluation protocols and metrics.

heading: 2 Cold-Start Anomaly Detection
text: Task Definition. In the cold-start setting, a model has access to K class descriptions Dprior =
7607
{c1, c2, ..., cK} and a stream of t observations Dt = {x1, x2, ..., xt}, where t is small. We denote the percentage of anomalous observations as the contamination ratio r%. An observation x either comes from one of the K normal classes or is anomalous, but we do not have access to the class or anomaly label. The task is to learn a model S to map each training sample x to an anomaly score such that high values indicate anomalous samples.
Application to chatbots. Our practical motivation is identifying out-of-scope queries in a recently deployed chatbot. We observe a stream of queries sent to the chatbot, as well as descriptions of all allowed intents. At time step t + 1, we leverage both Dt and Dprior to classify a given query xt+1 as in-scope (INS) or out-of-scope (OOS).

heading: 3 Method

heading: 3.1 Recap: Zero-Shot Anomaly Detection
text: Zero-shot (ZS) anomaly detection maps each data point x to an anomaly score S(x). Notably, ZS methods do not require past data, instead they are guided by a set of distinct normal class names {c1, c2, ..., cK} provided by the user. A pre-trained feature extractor ϕ maps each of the class names ck, and observations xt to deep embeddings ϕ(ck) and ϕ(xt). It then computes the distance d (often L2 or Cosine) between the embeddings of the example and each of the class names. The final anomaly score is given by the distance to the nearest class:
Szs(x) = min k {d(ϕ(x), ϕ(ck))}Kk=1 (1) High anomaly scores serve as indicators of anomalies. The anomaly score can be converted to a binary label by choosing a threshold α such that y = 0 if S(x) < α and y = 1 if S(x) ≥ α.
Zero-shot anomaly detection can be used for OOS query detection by first specifying a set of
Algorithm 1: ColdFusion Input: Dprior, Dt, p, query x. Output: Anomaly score Sadapt(x). Step 1: Encode class descriptions and
observations: ϕ(Dprior), ϕ(Dt); Step 2: Assign observations to classes
based on nearest class descriptor: a(x) = argmink{d(ϕ(x), ϕ(ck))}Kk=1;
Step 3: Adapt class embeddings: zk = median(ϕ(ck), {ϕ(x)|a(x) = k}); Step 4: Compute anomaly score for x: Sadapt(x) = mink{d(ϕ(x), zk)}Kk=1;
allowed intents. Then a deep encoder extracts the embeddings of the target user query and intent descriptions. Finally, the method labels the user query as OOS if it is far from all allowed intent names.

heading: 3.2 Limitations of Existing Methods
text: In practice, it is impossible to provide perfect class descriptions, and therefore zero-shot anomaly detection often does not achieve sufficient accuracy. On the other hand, if the number of observations is limited, observation-based anomaly detection methods, such as K-nearest neighbors, struggle for three key reasons: i) the observations may not include all in-scope classes; ii) it is hard to estimate the true distribution of normal data from a few samples; iii) the observations may be contaminated by anomalies. Empirically, observation-based methods underperform ZS methods for small t (see Tab. 1 and Fig. 2).

heading: 3.3 Our Method: ColdFusion
text: To bridge the gap between ZS and observationbased methods, we propose ColdFusion (illustrated in Fig. 1), a method for cold-start anomaly detection using domain adaptation. It improves ZS anomaly detection using the t observations in two key stages: i) assigning observations to classes; ii) adapting ZS class embeddings based on the assigned observations.
Assignment. We assign each of the t observations to the nearest class as measured in the feature space ϕ. We denote the class assignment of observation x as a(x). More formally:
a(x) = argmin k
{d(ϕ(x), ϕ(ck))}Kk=1 (2)
We further define Ck, the set of all observations assigned to class k as Ck = {ϕ(x)|a(x) = k}.
Adaptation. We now adapt each class embedding by considering both the initial class description and the assigned observations. Concretely, the adapted code for each class is the median of the set containing the embedding of the class descriptions and the embeddings of all assigned observations:
zk = median({ϕ(ck)} ∪ Ck) (3)
We chose the median and not mean for contamination robustness. Note that this step will not modify the embedding of classes with no observations.
Anomaly scoring. ColdFusion uses the same anomaly scoring as ZS except that the class codes are the adapted {zk}Kk=1 instead of the encoding of the original description i.e., Sadapt(x) = mink{d(ϕ(xt+1), zk)}Kk=1.

heading: 4 Experiments
text: Experimental setting. Our experiments simulate the deployment of an OOS query detection system. We first randomly sort the queries so that each query has a unique time t, modeling a query stream. At each time t, we train a model using the t available observations and the K class names, and evaluate the model on the entire test set. Datasets. We use three evaluation datasets, Banking77-OOS and CLINC-OOS segmented into CLINC-Banking and CLINC-Credit_Cards. Banking77-OOS (Casanueva et al., 2020; Zhang et al., 2021c) consists of 13, 083 customer service
queries, categorized into 77 fine-grained intents within the online banking domain. Among these, 50 intents are in-scope, while the remaining 27 are OOS queries. CLINC-OOS (Larson et al., 2019; Zhang et al., 2021c), derived from the broader CLINC dataset, consists of two domains: "Banking" and "Credit cards", each featuring 10 in-scope and 5 OOS intents. The training sets for each domain include 500 in-scope queries, while the test sets contain 850 queries, with 350 designated as OOS instances. Notably, our setting is unsupervised i.e., observations do not include intent labels for training. Further details are in App. B.1. Feature extractor & class encoding. We explored two feature encoders, namely the GTE model (Li et al., 2023) and MPNET (Song et al., 2020), both pre-trained on a large corpus of text pairs across various domains. We found that directly encoding intent topic names using these encoders did not meet our performance expectations (See Sec. 5). To overcome this challenge, we leverage ChatGPT to generate a query corresponding to each topic and utilize these generated queries as class descriptions instead of the intent topic names. For further details, please refer to App. A. Baselines. We compare ColdFusion (Sec. 3.3) to several baselines. These include the zero-shot model (ZS), detailed in Sec. 3.1, which relies solely on the generated normal class descriptions. Additionally, we consider DN2, an observation-based anomaly detection method proposed by (Reiss et al., 2021). DN2 computes the anomaly score of an observation by its deep 1-nearest neighbor distance versus the previous observations Dt. For implementation details refer to App. B.2. Evaluation metrics. We propose a new metric to evaluate the cold-start setting, which emphasizes high-accuracy shortly after deployment (low t). At each time step t, we evaluate the performance of the anomaly scores model using the Area Under the Receiver Operation Characteristic (AUROC) curve.
We obtain an AUROC score for every time step, and we denote them as {AUC(t)}Tt=1. We summarize this t vs. AUROC curve by the area under it up to
time t. This is denoted as AUC2 t̃ =
∑t t′=1 AUC(t
′) t ,
where t̃ = tT , the fraction of the training set used. The AUC2
t̃ metric provides a concise summary of
the model’s accuracy freshly after deployment.

heading: 4.1 Results
text: We present our results in Tab. 1 and Fig. 2. ColdFusion consistently outperforms all baselines across the evaluated datasets by a large margin. Particularly, we see that DN2 performs poorly, especially with small t, and the zero-shot baseline (ZS) maintains constant performance over time. Conversely, our approach performs well even for low t values, and improves over time. The presence of anomalies in the data stream poses a challenge for DN2, as it solely relies on the observed contaminated stream. This reliance often leads to occasional decreases in performance for DN2, highlighting the vulnerability of methods that exclusively depend on the observed data without considering the underlying anomalies. Furthermore, our method’s robustness to different feature encoders, as evidenced by consistent trends in both the GTE and MPNET models, suggests that it is not reliant on a single feature extractor. Results for different contamination are in App. C.

heading: 5 Ablation Study
text: Class embedding adaptation method. We investigate several variations of the adaptation method, shown in Tab. 2. i) Replacing our assignment and adaptation stages with K-means notably reduces performance, mainly due to its less effective random initialization method vs. our descriptor initialization; ii) Iterating multiple steps of assignment
and adaptation, each time assigning to the adapted center, fails to outperform ColdFusion. The single iteration of ColdFusion is preferred, since multiple iterations increase the computational cost. Additionally, the results in Tab. 2 show that median adaptation is slightly better than using the mean on the evaluated datasets.
Effectiveness of generated queries. In Tab. 3, we examine the impact of a naive ZS detector that simply encodes the intent names, compared to our ZS approach, which uses ChatGPT to generate a query for each intent and then encodes the generated query as the class embedding. The results highlight that naive encoding of intent names alone yields subpar performance, whereas our pre-processing procedure considerably improves results.

heading: 6 Conclusion
text: We introduced the new setting of cold-start anomaly detection, modeling freshly deployed anomaly detection systems. Our proposed solution, ColdFusion, is a method for adapting zeroshot anomaly detection to align with an observation stream. We introduced an evaluation protocol and metrics for comparing future methods.
Limitations
Our proposed method has several limitations. i) Not all deployed anomaly detection systems encounter the generalized cold-start problem and indeed in the case where there are many observations and very few anomalies, it is sometimes better to use observation-driven methods e.g., DN2 (Reiss et al., 2021). However, we believe that it is a common issue, particularly in domains like chatbots; ii) Our approach relies on user-provided guidance for zero-shot detection, which is not always available; iii) We assume a low contamination ratio; if this ratio is significantly higher, the effectiveness of our method may decrease.
Ethics Statement
Cold-start anomaly detection can have several benefits for society, including improving online services security by identifying fraudulent activities, unauthorized access and enhancing chatbot functionality by filtering out irrelevant queries early. However, it may also have some less positive use cases, such as being used for surveillance or profiling individuals without their consent. Our research is not geared towards these less positive use cases.

heading: Acknowledgements
text: This research was partially supported by funding from IBM, the Israeli Science Foundation and the Israeli Council for Higher Education.

heading: A Zero-Shot Anomaly Detection
text: Zero-shot (ZS) anomaly detection assigns an anomaly score S(x) to each data point x without relying on past data. Instead, it is guided by a set of class names {c1, c2, ..., cK} provided by the user. To tackle this challenge, we leverage ChatGPT to generate a user query corresponding to each class topic name. We use these generated queries as class descriptions instead of the intent topic names.
Query Generation: Utilizing ChatGPT-3.5, we generate a user query for each topic to serve as our class descriptions. Here, [DOMAIN] represents the chatbot domain (e.g., "Banking"). We employ the following template: "Generate queries that someone would ask a chatbot in [DOMAIN]. Generate one-sentence queries for each of the following topics: {c1, c2, ..., cK}." This process yields a set of K user queries, denoted by {qk}Kk=1.
A pre-trained feature extractor ϕ maps each generated class name qk and observation x to deep embeddings ϕ(qk) and ϕ(x). Subsequently, we compute the L2 distance between the example embeddings and each generated user query. The final anomaly score is determined by the distance to the nearest class:
Szs(x) = min k {d(ϕ(x), ϕ(ck))}Kk=1 Alg. 2 outlines our zero-shot model.
A comparison between naive class names and generated queries is presented in Tab. 3.

heading: B Experimental Details
text: B.1 Datasets We employ three widely used datasets, Banking77OOS and CLINC-OOS (which is split into CLINCBanking and CLINC-Credit_Cards), to evaluate our anomaly detection approach.
Banking77-OOS. Banking77-OOS (Casanueva et al., 2020; Zhang et al., 2021c) is an annotated intent classification dataset designed for online banking queries. Comprising 13, 083 customer service queries, each query is labeled with one of 77 finegrained intents within the banking domain. The dataset focuses on fine-grained, single-domain intent detection. Of these 77 intents, Banking77OOS incorporates 50 in-scope intents, while the out-of-scope (OOS) queries are constructed based on 27 held-out in-scope intents. The training set consists of 5,095 in-scope user queries, and the test set comprises 3,080 user queries, including 1,080 OOS instances.
Algorithm 2: Zero-Shot Detector Input: Dprior, ϕ, query x. Output: Anomaly score Szs(x). Step 1: Generate user queries using ChatGPT and Dprior: {qk}Kk=1;
Step 2: Encode generated queries: {ϕ(qk)}Kk=1 and input query: ϕ(x); Step 3: Compute anomaly score for x: Szs(x) = mink{dϕ(x), ϕ(qk))Kk=1;
CLINC-OOS. CLINC-OOS (Larson et al., 2019; Zhang et al., 2021c) emanates from the broader CLINC dataset, encompassing 15 intent classes across 10 different domains, with integrated out-of-scope examples. For our evaluation, we focus on two domains: "Banking" and "Credit cards". Each domain is characterized by 5 in-scope and 10 out-of-scope intents. The training set for each domain comprises 500 in-scope user queries, while the test set includes 850 user queries, with 350 designated as out-of-scope instances.
B.2 Implementation Details & Baselines
Our implementation relies on two feature encoders: the GTE model (Li et al., 2023) and MPNET (Song et al., 2020), both pre-trained on a large corpus of text pairs across various domains. We use the HuggingFace library for both models. Specifically, for the GTE model, we employ the "thenlper/gtelarge" model checkpoint, while for MPNET, we use the "sentence-transformers/all-mpnet-base-v2" model checkpoint. It’s noteworthy that all baselines are using the same feature encoders in our comparisons. We use L2 as a distance metric. For DN2 (Reiss et al., 2021), the implementation involves encoding Dt and the target query x with our feature encoder ϕ, followed by computing the 1-nearestneighbor distance to ϕ(Dt). We employ the faiss library for nearest-neighbor distance computations. In our ColdFusion in order to be robust to anomalies, we excluded observations assigned to class k but are further than τ . Formally, we define Ck, as the set of all observations assigned to class k as:
Ck = {ϕ(x)|a(x) = k, d(ϕ(x), ϕ(ck)) ≤ τ}
We set τ by first computing the distances between all samples and their assigned centers, sorting them, and choosing τ as the 90% percentile. An ablation study on this parameter is in App. C.

heading: C More Results & Analysis
text: Contamination Ratios. We extend our analysis by considering additional contamination ratios of r% = 2.5 and r% = 7.5, as shown in Tables 4 and 5, respectively. Additionally, we present visual insights into ColdFusion’s adaptive performance over time through the figures presented in Fig. 3, Fig. 4, Fig. 5, and Fig. 6. Across all contamination ratios, ColdFusion consistently outperforms all baselines by a significant margin, reinforcing our approach’s robustness and effectiveness. These supplementary results further support the stability and reliability of ColdFusion’s performance trends observed in the main analysis.
Effect of τ . Table 6 provides an ablation analysis of different τ parameters as defined in Eq. B.2. We observe that selecting the 50% and 75% percentiles yields suboptimal performance compared to using the 90% and 100% percentiles. These percentiles involve minimal filtering. Interestingly, there is a slight improvement in performance when employing the 90% percentile compared to the 100% percentile.

heading: D Related Works
text: Out-of-scope intent discovery. Out-of-scope (OOS) intent discovery involves clustering new, unknown intents to identify potential development directions and expand the capabilities of dialogue systems. Prior works (Lin et al., 2020; Zhang et al., 2021b; Mou et al., 2022) in this domain have ex-
plored semi-supervised clustering using labeled in-domain data. Methods such as pre-training a BERT encoder with cross-entropy loss (Lin et al., 2020; Zhang et al., 2021b) and utilizing similarity constrained or supervised contrastive losses (Khosla et al., 2020) to learn discriminative features (Mou et al., 2022) aim to transfer intent representations. However, these approaches face challenges related to in-domain overfitting, where representations learned from in-scope data may not generalize well to OOS data. In contrast to this line of work, our approach focuses on detecting OOS intents rather than discovering them. Notably, our setting involves unlabeled in-scope intents, and our model’s prior knowledge is limited to intent names.
Out-of-scope intent classification. OOS intent classification is categorized based on the use of extensive labeled OOS intent samples during training. The first category involves methods that use OOS samples during training, treating OOS intent classification as a (n+1)-class classification task (Zheng et al., 2020; Zhan et al., 2021). In contrast, the second category aims to minimize intra-class variance and maximize inter-class variance to widen the margin between in-scope and OOS intents (Lin and Xu, 2019; Zeng et al., 2021). Some approaches (Zhang et al., 2021a; Xu et al., 2020; Zeng et al., 2021) incorporate Gaussian distribution into the learned intent features to aid OOS detection. Our work stands apart from this line of research as it specifically addresses OOS intents, where in-scope
intents (topics) lack labels, and the model has no information or exposure to any OOS intents.
Classical anomaly detection methods. Detecting anomalies in images has been researched for several decades. The methods follow three main paradigms: i) Reconstruction - this paradigm first attempts to characterize the normal data by a set of basis functions and then attempts to reconstruct a new example using these basis functions, typically under some constraint such as sparsity or weights with a small norm. Samples with high reconstruction errors are atypical of normal data distribution and anomalous. Some notable methods include: principal component analysis (Jolliffe, 2011) and K-nearest neighbors (kNN) (Eskin et al., 2002); ii) Density estimation - another paradigm is to first estimate the density of normal data. A new test sample is denoted as anomalous if its estimated density is low. Parametric density estimation methods include Ensembles of Gaussian Mixture Models (EGMM) (Glodek et al., 2013), and nonparametric methods include kNN (which is also a reconstruction-based method) as well as kernel density estimation (Latecki et al., 2007). Both types of methods have weaknesses: parametric methods are sensitive to parametric assumptions about the nature of the data whereas non-parametric methods suffer from the difficulty of accurately estimating density in high-dimensions; iii) One-class classification (OCC) - this paradigm attempts to fit a parametric classifier to distinguish between normal training data and all other data. The classifier is then used to classify new samples as normal or anomalous. Such methods include one-class support vector machine (OCSVM) (Scholkopf et al., 2000) and support vector data description (SVDD) (Tax and Duin, 2004).
Deep learning for anomaly detection. This line of work is based on the idea of initializing a neural network with pre-trained weights and then obtaining stronger performance by further adaptation of the training data. DeepSVDD (Ruff et al., 2018) suggested to first train an auto-encoder on the normal training data, and then using the encoder as the initial feature extractor. Moreover, since the encoder features are not specifically fitted to anomaly detection, DeepSVDD adapts to the encoder training data. However, this naive training procedure leads to catastrophic collapse. An alternative direction is to use features learned from auxiliary tasks on large-scale external datasets. Transferring pre-trained features for out-of-distribution detec-
tion has been proposed by (Hendrycks et al., 2019). It was recently established (Reiss et al., 2021) that given sufficiently powerful representations, a simple criterion based on the kNN distance to the normal training data achieves strong performance. The best performing methods (Reiss et al., 2021, 2022; Reiss and Hoshen, 2023) combine pre-training on external datasets and a second finetuning stage on the provided normal samples in the training set, but they require many data observations and assume that the observations are not contaminated. To our knowledge, the only work that deals with a similar setting (Jeong et al., 2023) assumes prior knowledge of anomalies, that observations come from a single normal class and that they are not contaminated by anomalies.

heading: Future Work
text: We introduced an evaluation protocol and metrics for comparing future methods. Limitations
Our proposed method has several limitations. i) Not all deployed anomaly detection systems encounter the generalized cold-start problem and indeed in the case where there are many observations and very few anomalies, it is sometimes better to use observation-driven methods e. g. , DN2 (Reiss et al. , 2021). However, we believe that it is a common issue, particularly in domains like chatbots; ii) Our approach relies on user-provided guidance for zero-shot detection, which is not always available; iii) We assume a low contamination ratio; if this ratio is significantly higher, the effectiveness of our method may decrease