Detecting Out-of-Distribution Inputs to Deep Generative Models Using Typicality

1 INTRODUCTION . Recent work ( Nalisnick et al. , 2019 ; Choi et al. , 2019 ; Shafaei et al. , 2018 ) showed that a variety of deep generative models fail to distinguish training from out-of-distribution ( OOD ) data according to the model likelihood . This phenomenon occurs not only when the data sets are similar but also when they have dramatically different underlying semantics . For instance , Glow ( Kingma & Dhariwal , 2018 ) , a state-of-the-art normalizing flow , trained on CIFAR-10 will assign a higher likelihood to SVHN than to its CIFAR-10 training data ( Nalisnick et al. , 2019 ; Choi et al. , 2019 ) . This result is surprising since CIFAR-10 contains images of frogs , horses , ships , trucks , etc . and SVHN contains house numbers . A human would be very unlikely to confuse the two sets . These findings are also troubling from an algorithmic standpoint since higher OOD likelihoods break previously proposed methods for classifier validation ( Bishop , 1994 ) and anomaly detection ( Pimentel et al. , 2014 ) . We conjecture that these high OOD likelihoods are evidence of the phenomenon of typicality.1 Due to concentration of measure , a generative model will draw samples from its typical set ( Cover & Thomas , 2012 ) , a subset of the model ’ s full support . However , the typical set may not necessarily intersect with regions of high probability density . For example , consider a d-dimensional isotropic Gaussian . Its highest density region is at its mode ( the mean ) but the typical set resides at a distance of √ d from the mode ( Vershynin , 2018 ) . Thus a point near the mode will have high likelihood while being extremely unlikely to be sampled from the model . We believe that deep generative models exhibit a similar phenomenon since , to return to the CIFAR-10 vs SVHN example , Nalisnick et al . ( 2019 ) showed that sampling from the model trained on CIFAR-10 never generates SVHN-looking images despite SVHN having higher likelihood . Based on this insight , we propose that OOD detection should be done by checking if an input resides in the model ’ s typical set , not just in a region of high density . Unfortunately it is impossible to analytically derive the regions of typicality for the vast majority of deep generative models . To define a widely applicable and scalable OOD-detection algorithm , we formulate Shannon ( 1948 ) ’ s entropy-based definition of typicality into a statistical hypothesis test . To ensure that the test is robust 1Choi et al . ( 2019 ) also consider typicality as an explanation but ultimately deem it not to be a crucial factor . Nalisnick et al . ( 2019 ) implicitly mention typicality in their discussion of the transformed representations ’ proximity to the mean and explicitly in a comment on Open Review : https : //openreview.net/ forum ? id=H1xwNhCcYm & noteId=HkgLWfveT7 even in the low-data regime , we employ a bootstrap procedure ( Efron & Tibshirani , 1994 ) to set the OOD-decision threshold . In the experiments , we demonstrate that our detection procedure succeeds in many of the challenging cases presented by Nalisnick et al . ( 2019 ) . In addition to these successes , we also discuss failure modes that reveal drastic variability in OOD detection for the same data set pairs under different generative models . We highlight these cases to inspire future work . 2 BACKGROUND : TYPICAL SETS . The typical set of a probability distribution is the set whose elements have an information content sufficiently close to that of the expected information ( Shannon , 1948 ) . A formal definition follows . Definition 2.1 ( , N ) -Typical Set ( Cover & Thomas , 2012 ) For a distribution p ( x ) with support x ∈ X , the ( , N ) -typical set AN [ p ( x ) ] ∈ XN is comprised of all N -length sequences that satisfy H [ p ( x ) ] − ≤ 1 N − log p ( x1 , . . . , xN ) ≤ H [ p ( x ) ] + where H [ p ( x ) ] = ∫ X p ( x ) [ − log p ( x ) ] dx and ∈ R + is a small constant . When the joint density in Definition 2.1 factorizes , we can write : H [ p ( x ) ] − ≤ 1 N N∑ n=1 − log p ( xn ) ≤ H [ p ( x ) ] + . ( 1 ) This is the definition we will use from here forward as we assume both training data and samples from our generative model are identically and independently distributed ( i.i.d. ) . In this factorized form , the middle quantity can be interpreted as an N -sample empirical entropy : 1/N ∑N n=1 − log p ( xn ) = ĤN [ p ( x ) ] . The asymptotic equipartition property ( AEP ) ( Cover & Thomas , 2012 ) states that this estimate will converge to the true entropy as N →∞ . To build intuition , let p ( x ) = N ( 0 , σ2I ) and consider its ( , 1 ) -typical set . Plugging in the relevant quantities to Equation 1 and simplifying , we have x ∈ A1 [ N ( 0 , σ2I ) ] if 12 |d − ||x − µ|| 2 2/σ 2| ≤ where d denotes dimensionality . See Appendix A.1 for a complete derivation . The inequality will hold for any choice of if ||x− µ||2 = σ √ d. In turn , we can geometrically interpret A1 [ N ( 0 , σ2I ) ] as an annulus centered at µ with radius σ √ d and whose width is a function of ( and σ ) . This is a well-known concentration of measure result often referred to as the Gaussian Annulus Theorem ( Vershynin , 2018 ) . Figure 1 ( a ) illustrates a Gaussian centered on the all gray image ( pixel value 128 ) . We show that samples from this model never resemble the all gray image , despite it having the highest probability density , because they are drawn from the annulus . In Figure 1 ( b ) we visualize the interplay between density and volume that gives rise to the typical set . The connection between typicality and concentration of measure can be stated formally as : Theorem 2.1 Probability of the Typical Set ( Cover & Thomas , 2012 ) For N sufficiently large , the typical set has probability P ( AN [ p ( x ) ] ) > 1− . This result speaks to the central role of typical sets in compression : AN is an efficient representation of XN as it is sampled under p ( x ) .2 Returning to the Gaussian example , we could ‘ compress ’ Rd under N ( 0 , σ2I ) to just the σ √ d-radius annulus.3 3 A TYPICALITY TEST FOR OOD INPUTS . We next describe our core contribution : a reformulation of Definition 2.1 into a scalable goodnessof-fit test to determine if a batch of test data was likely drawn from a given deep generative model . 3.1 SETTING OF INTEREST : GOODNESS-OF-FIT TESTING FOR DEEP GENERATIVE MODELS . Assume we have a generative model p ( x ; θ ) —with θ denoting the parameters—that was trained on a data set X = { x1 , . . . , xN } . Take x to be high-dimensional ( d > 500 ) and N to be sufficiently large ( N > 25 , 000 ) so as to enable training a high-capacity neural-network parametrized model—a so-called ‘ deep generative model ’ ( DGM ) . Furthermore , we assume that p ( x ; θ ) has a likelihood that can be evaluated either directly or closely approximated via Monte Carlo sampling . Examples of DGMs that meet these specifications include normalizing flows ( Tabak & Turner , 2013 ) such as Glow ( Kingma & Dhariwal , 2018 ) , latent variable models such as variational autoencoders ( VAEs ) ( Kingma & Welling , 2014 ; Rezende et al. , 2014 ) , and auto-regressive models such as PixelCNN ( van den Oord et al. , 2016 ) . We do not consider implicit generative models ( Mohamed & Lakshminarayanan , 2016 ) ( such as GANs ( Goodfellow et al. , 2014 ) ) due to their likelihood being difficult to even approximate . The primary focus of this paper is in performing a goodness-of-fit ( GoF ) test ( D ’ Agostino , 1986 ; Huber-Carol et al. , 2012 ) for p ( x ; θ ) . Specifically , given an M -sized batch of test observations X̃ = { x̃1 , . . . , x̃M } ( M ≥ 1 ) , we desire to determine if X̃ was sampled ( i.i.d . ) from pθ or from some other distribution q 6= pθ . We assume no knowledge of q , thus making our desired GoF test omnibus ( Eubank & LaRiccia , 1992 ) . The vast majority of GoF tests operate via the model ’ s cumulative distribution function ( CDF ) and/or being able to compute an empirical distribution function ( EDF ) ( Cramér , 1928 ; Massey Jr , 1951 ; Anderson & Darling , 1954 ; Stephens , 1974 ) . However , the CDFs of DGMs are not available analytically , and numerical approximations are hopelessly slow due to the curse of dimensionality . Likewise , EDFs lose statistical strength exponentially as dimensionality grows ( Wasserman , 2006 ) . Our goal is to formulate a scalable test that does not rely on strong parametric assumptions ( e.g . Chen & Xia ( 2019 ) ) and has better computational properties than kernel-based alternatives ( e.g . Liu et al . ( 2016 ) ) . 3.2 A HYPOTHESIS TEST FOR TYPICALITY . Returning to the results of Nalisnick et al . ( 2019 ) and Choi et al . ( 2019 ) , the high-dimensionality of natural images ( d = 3072 for CIFAR and SVHN ) alone is enough to suspect the influence of phenomena akin to the Gaussian Annulus Theorem . Yet there are stronger parallels still : Nalisnick et al . ( 2019 ) showed that the all-black image has the highest density of any tested input to their FashionMNIST DGM , but this model is never observed to generate all-black images . Thus we are inspired to critique DGMs not via density but via typical set membership : if X̃ ∈ AM [ p ( x ; θ ) ] then X̃ ∼ p ( x ; θ ) , otherwise X̃ 6∼ p ( x ; θ ) . ( 2 ) The intuition is that if X̃ is indeed sampled from pθ , then with high probability it must reside in the typical set ( Theorem 2.1 ) . To determine if X̃ ∈ AM [ p ( x ; θ ) ] , we can plug X̃ into Equation 1 as a 2While AN is not the smallest high-probability set ( Polonik , 1997 ) and therefore not the most efficient compression , its size is of the same order ( Cover & Thomas , 2012 ) . 3The reader may have noticed Theorem 2.1 requires ‘ N sufficiently large ’ but in the Gaussian example we assumed N = 1 . For high-dimensional factorized likelihoods , log p ( x ) = ∑d j=1 log p ( xj ) , and thus we can interpret Definition 2.1 as acting dimension-wise instead of across observations . length M sequence and check if the -bound holds : if ∣∣∣∣∣ 1M M∑ m=1 − log p ( x̃m ; θ ) −H [ p ( x ; θ ) ] ∣∣∣∣∣ = ̂ ≤ then X̃ ∈ AM [ p ( x ; θ ) ] , ( 3 ) where ̂ denotes the test statistic . We provide a sanity check for Equation 3 in Subfigure 1 ( c ) , showing ̂ calculated for the high-dimensional Gaussian example described in Section 2 . We see that ̂ achieves its minimum value exactly at √ d-distance from 128 . In Appendix A.2 we show that our test is consistent unless the alternative ’ s typical set is a subset of pθ ’ s : AM [ q ( x ) ] ⊆ AM [ p ( x ; θ ) ] . This limitation is reasonable and expected given our fundamental assumption in Equation 2 . Since the size of the typical set is upper bounded as a function of entropy—log |AM [ p ( x ; θ ) ] | ≤M ( H [ p ( x ; θ ) ] + ) ( Cover & Thomas , 2012 ) —the model entropy determines the probability of type-II error : higher entropy implies a larger typical set , a larger set implies more chance of AM [ q ] ⊆ AM [ pθ ] , and a higher degree of intersection leads to a better chance of incorrectly failing to reject H0 : x̃ ∼ pθ . Yet it is not uncommon to sacrifice consistency for generality when testing GoF ( e.g . Chi-square vs Kolmogorov-Smirnov tests ( Haberman , 1988 ) ) .

Summary: This paper is concerned with how to determine whether a set of data points are from a given distribution. It uses the so-called typical set to transform the problem to determining whether the data points lie in the typical set of the given distribution. It proposes a statistical test using the empirical distribution of model likelihoods to determine whether inputs lie in the typical set if the considered model.