Few-Shot One-Class Classification via Meta-Learning

1 INTRODUCTION . The anomaly detection ( AD ) task ( Chandola et al. , 2009 ; Aggarwal , 2015 ) consists in differentiating between normal and abnormal data samples . AD applications are common in various domains that involve different data types , including medical diagnosis ( Prastawa et al. , 2004 ) , cybersecurity ( Garcia-Teodoro et al. , 2009 ) and quality control in industrial manufacturing ( Scime & Beuth , 2018 ) . Due to the rarity of anomalies , the data underlying AD problems exhibits high class-imbalance . Therefore , AD problems are usually formulated as one-class classification ( OCC ) problems ( Moya et al. , 1993 ) , where either only a few or no anomalous data samples are available for training the model ( Khan & Madden , 2014 ) . While most of the developed approaches ( Khan & Madden , 2014 ) require a substantial amount of normal data to yield good generalization , in many real-world applications , e.g . in industrial manufacturing , only small datasets are available . Data scarcity can have many reasons : data collection itself might be expensive , e.g . in healthcare , or happens only gradually , such as in a cold-start situation . To enable learning from few examples , various viable meta-learning approaches ( Lake et al. , 2011 ; Ravi & Larochelle , 2016 ; Finn et al. , 2017 ) have been developed . However , they rely on having examples from each of the classification task ’ s classes , which prevents their application to OCC tasks . To the best of our knowledge , the few-shot OCC ( FS-OCC ) problem has only been addressed by Kozerawski & Turk ( 2018 ) in the image domain . Our contribution is threefold : Firstly , we show that classical OCC approaches fail in the few-shot data regime . Secondly , we provide a theoretical analysis showing that classical gradient-based metalearning algorithms do not yield initializations suitable for OCC tasks and that second-order derivatives are needed to optimize for such initializations . Thirdly , we propose one-class model-agnostic meta-learning ( OC-MAML ) , a data-domain-agnostic algorithm that quickly learns FS-OCC tasks , to serve as a first , simple and strong baseline for future research in the understudied FS-OCC problem . OC-MAML builds upon model-agnostic meta-learning ( MAML ) ( Finn et al. , 2017 ) , which is a meta-learning method that explicitly optimizes for few-shot learning and yields a model initialization that enables quick adaptation to a new task using only few of its datapoints . Like MAML , OCMAML yields model parameters that are easily adaptable to unseen tasks . The difference is that the model initialization delivered by OC-MAML is particularly suited for adaptation to OCC tasks and hence requires few examples from only one class of the target task for good adaptation . We provide a theoretical analysis that shows that OC-MAML explicitly optimizes for parameter initializations which yield performance increase on class-balanced test data by taking only a few gradient steps with one-class minibatches . This is done by maximizing the inner product of gradients computed on different minibatches with different class-imbalance rates . While recent meta-learning approaches focused on the few-shot learning problem , i.e . learning to learn with few examples , we extend their use to the OCC problem , i.e . learning to learn with examples from only one class . We empirically validate our theoretical analysis on six datasets from the image and time-series domains , and demonstrate the robustness and maturity of our approach for real-world application by successfully testing it on a real-world dataset of sensor readings recorded during manufacturing of metal workpieces with a CNC milling machine . 2 APPROACH . 2.1 PROBLEM STATEMENT . Our goal is to learn a one-class classification ( OCC ) task using only a few examples from the normal class . In the following , we first discuss the unique challenges of the few-shot one-class classification ( FS-OCC ) problem . Subsequently , we formulate the FS-OCC problem as a meta-learning problem . In order to perform one-class classification , i.e . differentiate between in-class and out-of-class examples , approximating a generalized decision boundary for the normal class is necessary . Learning such a class decision boundary in the few-shot regime can be especially challenging for the following reasons . On the one hand , if the model overfits to the few available datapoints , the class decision boundary would be too restrictive , which would prevent generalization to unseen examples . As a result , some normal samples would be predicted as anomalies . On the other hand , if the model overfits to the majority class , e.g . predicting almost everything as normal , the class decision boundary would overgeneralize , and out-of-class ( anomalous ) examples would not be detected . In our meta-learning problem formulation , we assume access to data from classification tasks T traini sampled from a task distribution p ( T ) related to our target OCC tasks . In the few-shot classification context , N -way K-shot learning tasks are usually used to test the learning procedure , in our case the model initialization , yielded by the meta-learning algorithm . An N -way K-shot classification task includesK examples from each of theN classes that are used for learning this task , after which the trained classifier is tested on a disjoint set of data ( Vinyals et al. , 2016 ) . When the target task is an OCC task , only examples from one class are available for training , which can be viewed as a 1-way K-shot classification task . In order to align with the AD problem , the available examples have to belong to the normal ( majority ) class , which usually has a lower variance than the anomalous ( minority ) class . This problem formulation is a prototype for a practical use case where an application-specific anomaly detector is needed and only few normal class examples are available . 2.2 MODEL-AGNOSTIC META-LEARNING . Model-agnostic meta-learning ( MAML ) ( Finn et al. , 2017 ) is an optimization-based meta-learning algorithm upon which we build in our present work . MAML learns a model initialization that enables quick adaptation to unseen tasks using only few data samples . For that , MAML trains a model explicitly for few-shot learning on tasks Ti coming from the same task distribution p ( T ) as the unseen target task Ttest . In order to assess the model ’ s adaptation ability to unseen tasks , the available tasks are divided into mutually disjoint task sets : one for meta-training Str , one for metavalidation Sval and one for meta-testing Stest . Each task Ti is divided into two disjoint sets of data , each of which is used for a particular MAML operation : Dtr is used for adaptation and Dval is used for validation , i.e . evaluating the adaptation . The adaptation procedure of a model fθ to a particular task Ti consists in taking one ( or more ) gradient descent step ( s ) using few datapoints sampled from Dtr . We also refer to the adaptation updates as inner loop updates . A good measure for the suitability of the initialization parameters θ for few-shot adaptation to a considered task Ti is the loss LvalTi ( fθ′i ) , which is computed on the validation set D val using the task-specific adapted model fθ′i . In order to optimize for few-shot learning , the model parameters θ are updated by minimizing the aforementioned loss across all meta-training tasks . This update , called the outer loop update , can be expressed as : θ ← θ − β∇θ ∑ Ti∼p ( T ) LvalTi ( fθ′i ) , ( 1 ) where β is the learning rate used for the outer loop . In order to avoid meta-overfitting , i.e . overfitting to the meta-training tasks , model selection can be done via conducting validation episodes using tasks from Sval throughout meta-training . At meta-test time , the few-shot adaptation to unseen tasks from Stest is evaluated . We note that , in the case of few-shot classification , K datapoints from each class are sampled from Dtr for the adaptation , during training , validation and testing . 2.3 ONE-CLASS MODEL-AGNOSTIC META-LEARNING . 2.3.1 ALGORITHM . The primary contribution of our work is to show that second-order gradient-based meta-learning is a viable approach to the underexplored few-shot one-class classification ( FS-OCC ) problem . We achieve this by adequately modifying the objective of the adaptation step , i.e . the inner loop updates , of the MAML algorithm . We choose to build upon gradient-based meta-learning algorithms , because these were shown to be universal learning algorithm approximators ( Finn & Levine , 2017 ) , which means that they could approximate a learning algorithm tailored for FS-OCC . As explained in Section 2.2 , MAML optimizes explicitly for few-shot adaptation by creating and using auxiliary tasks that have the same characteristic as the target tasks , in this case tasks that include only few datapoints for training . Analogously , OC-MAML trains explicitly for quick adaptation to OCC tasks by creating OCC auxiliary tasks for meta-training . Concretely , this is done by modifying the class-imbalance rate ( CIR ) of the inner loop data batches to match the one of the test task . The meta-training procedure of OC-MAML is described in Algorithm 1 in Appendix A . As described in Section 1 , OCC problems are binary classification scenarios where only few or no minority class samples are available . In order to address both of theses cases , we introduce a hyperparameter ( c ) which sets the CIR of the batch sampled for the inner updates . Hereby , c gives the percentage of the samples belonging to the minority ( anomalous ) class w.r.t . the total number of samples , e.g . setting c = 0 % means only majority class samples are contained in the data batch . We focus on this latter extreme case , where no anomalous samples are available for learning . The key difference between MAML and OC-MAML is in the sampling operation of the inner loop batch ( operation 5 in Algorithm 1 in Appendix A ) . By reducing the size of the batch used for the adaptation ( via the hyperparameter K ) , MAML trains for few-shot adaptation . OC-MAML extends this approach to train for few-shot one-class adaptation by reducing the CIR of the batch used for adaptation ( via the hyperparameter c ) . In order to evaluate the performance of the adapted model on both classes , we use a class-balanced validation batch B ′ for the outer loop updates . This way , we maximize the performance of the model in recognizing both classes after having seen examples from only one class during adaptation . Using OCC tasks for adaptation during meta-training favors model initializations that enable a quick adaptation to OCC tasks over those that require classbalanced tasks . From a representation learning standpoint , OC-MAML learns representations that are not only broadly suitable for the data underlying p ( T ) , but also particularly suited for OCC tasks . In Section 2.3.2 , we discuss the unique characteristics of the model initializations yielded by OC-MAML and explain why adapting first-order meta-learning algorithms to the OCC scenario does not yield the targeted results . 2.3.2 THEORETICAL ANALYSIS : WHY DOES OC-MAML WORK ? . In this section we give a theoretical explanation of why OC-MAML works and why it is a more suitable approach than MAML for the few-shot one-class classification ( FS-OCC ) problem . To address the latter problem , we aim to find a model parameter initialization , from which adaptation using few data examples from only one class yields a good performance on both classes , i.e . good generalization to the class-balanced task . We additionally demonstrate that adapting first-order metalearning algorithms , e.g . First-Order MAML ( FOMAML ) ( Finn et al. , 2017 ) and Reptile ( Nichol & Schulman , 2018 ) , to the OCC scenario as done in OC-MAML , does not yield initializations with the desired characteristics , as it is the case for OC-MAML . gMAML = g2 − αH2g1 − αH1g2 +O ( α2 ) = g2 − α ∂ ( g1.g2 ) ∂φ1 +O ( α2 ) ( 2 ) By using a Taylor series expansion , Nichol & Schulman ( 2018 ) approximate the gradient used in the MAML update . For simplicity of exposition , in Equation 2 we give their results for the case where only 2 gradient-based updates are performed , i.e . one adaptation update on a minibatch including K datapoints from Dtr and one meta-update on a minibatch including Q datapoints from Dval . We use the same notation used by Nichol & Schulman ( 2018 ) , where gi and Hi denote the gradient and Hessian computed on the ith minibatch at the initial parameter point φ1 , and α gives the learning rate . Here it is assumed that the same learning rate is used for the adaptation and meta-updates . In Equation 2 Nichol & Schulman ( 2018 ) demonstrate that MAML partially optimizes for increasing the inner product of the gradients computed on different minibatches . In fact , when gradients from different minibatches have a positive inner product , taking a gradient step using one of them yields a performance increase on the other ( Nichol & Schulman , 2018 ) . Equation 2 holds also for OC-MAML . However , in OC-MAML the minibatches 1 and 2 have different class-imbalance rates ( CIRs ) , since the first minibatch includes data from only one class and the second minibatch is classbalanced . Hence , it optimizes for increasing the inner product of the gradients computed on different minibatches with different CIRs , while MAML does the same but for different minibatches with the same CIR , namely c = 50 % . Consequently , OC-MAML optimizes for a parameter initialization from which taking one ( or few ) gradient step ( s ) with one-class minibatch ( es ) results in a performance increase on class-balanced data . In contrast , MAML optimizes for a parameter initialization that requires class-balanced minibatches to yield the same effect ( Figure 1 in Appendix A ) . When adapting to OCC tasks , however , only examples from one class are available . We conclude , therefore , that using minibatches with different CIRs for meta-training , as done in OC-MAML , yields parameter initializations that are more suitable for adapting to OCC tasks . A natural question is whether applying our modification of MAML , i.e . using only data from the normal class for adaptation during meta-training , to other gradient-based meta-learning algorithms would yield the same desired effect . We investigate this for First-Order MAML ( FOMAML ) ( Finn et al. , 2017 ) and Reptile ( Nichol & Schulman , 2018 ) . FOMAML is a first-order approximation of MAML , which ignores the second derivative terms . Reptile is also a first-order meta-learning algorithm that learns an initialization that enables fast adaptation to test tasks using only few examples from each class . In the following we demonstrate that adapting the FOMAML and Reptile algorithms to the one-class classification scenario , to which we will refer as OC-FOMAML and OCReptile , does not result in optimizing for an initialization suitable for OCC tasks , as it is the case for OC-MAML . We note that for OC-Reptile , the first ( N −1 ) batches contain examples from only one class and the last ( N th ) batch is class-balanced . The approximated gradients used in the FOMAML and Reptile updates are given by Equations 3 and 4 ( Nichol & Schulman , 2018 ) , respectively . gFOMAML = g2 − αH2g1 +O ( α2 ) ( 3 ) gReptile = g1 + g2 − αH2g1 +O ( α2 ) ( 4 ) We note that these equations hold also for OC-FOMAML and OC-Reptile . By taking the expectation over minibatch sampling Eτ,1,2 for a meta-training task τ and two class-balanced minibatches , Nichol & Schulman ( 2018 ) establish that Eτ,1,2 [ H1g2 ] = Eτ,1,2 [ H2g1 ] . Averaging the two sides of the latter equation results in the following : Eτ,1,2 [ H2g1 ] = 1 2 Eτ,1,2 [ H1g2 +H2g1 ] = 1 2 Eτ,1,2 [ ∂ ( g1.g2 ) ∂φ1 ] ( 5 ) Equation 5 shows that , in expectation , FOMAML and Reptile , like MAML , optimize for increasing the inner product of the gradients computed on different minibatches with the same CIR . However , when the minibatches 1 and 2 have different CIRs , which is the case for OC-FOMAML and OC-Reptile , Eτ,1,2 [ H1g2 ] 6= Eτ,1,2 [ H2g1 ] and therefore Eτ,1,2 [ H2g1 ] 6= 12Eτ,1,2 [ ∂ ( g1.g2 ) ∂φ1 ] . Hence , even though , similarly to OC-MAML , OC-FOMAML and OC-Reptile use minibatches with different CIRs for meta-training , contrarily to OC-MAML , they do not optimize for increasing the inner product of the gradients computed on different minibatches with different CIRs . The second derivative term H1g2 is , thus , necessary to optimize for an initialization from which performance increase on a class-balanced task is yielded by taking few gradient steps using only data from one class .

Summary:  This paper tackles an interesting problem, one-class classification or anomaly detection, using a meta-learning approach. The main contribution is to introduce a parameter such that the inner-loop of the meta-learning algorithm better reflects the imbalance which occurs during meta-testing. Results are shown comparing a few simple baselines to both MAML and the modified variant, on a few datasets such as image-based ones (MNIST, miniImageNet), a synthetic dataset, and a real-world time-series example from CNC milling machines.