Title: SAMPLING GENERATIVE NETWORKS

Abstract: We introduce several techniques for sampling and visualizing the latent spaces of generative models. Replacing linear interpolation with spherical linear interpolation prevents diverging from a model's prior distribution and produces sharper samples. J-Diagrams and MINE grids are introduced as visualizations of manifolds created by analogies and nearest neighbors. We demonstrate two new techniques for deriving attribute vectors: bias-corrected vectors with data replication and synthetic vectors with data augmentation. Binary classification using attribute vectors is presented as a technique supporting quantitative analysis of the latent space. Most techniques are intended to be independent of model type and examples are shown on both Variational Autoencoders and Generative Adversarial Networks.

1. INTRODUCTION:

Generative models are a popular approach to unsupervised machine learning. Generative neural network models are trained to produce data samples that resemble the training set. Because the number of model parameters is significantly smaller than the training data, the models are forced to discover efficient data representations. These models are sampled from a set of latent variables in a high dimensional space, here called a latent space. Latent space can be sampled to generate observable data values. Learned latent representations often also allow semantic operations with vector space arithmetic (Figure 1 ).

Figure 1 : Schematic of the latent space of a generative model. In the general case, a generative model includes an encoder to map from the feature space (here images of faces) into a high dimensional latent space. Vector space arithmetic can be used in the latent space to perform semantic operations. The model also includes a decoder to map from the latent space back into the feature space, where the semantic operations can be observed. If the latent space transformation is the identity function we refer to the encoding and decoding as a reconstruction of the input through the model.

Generative models are often applied to datasets of images. Two popular generative models for image data are the Variational Autoencoder (VAE, Kingma & Welling, 2014) and the Generative Adversarial Network (GAN, Goodfellow et al., 2014) . VAEs use the framework of probabilistic graphical models with an objective of maximizing a lower bound on the likelihood of the data. GANs instead formalize the training process as a competition between a generative network and a separate discriminative network. Though these two frameworks are very different, both construct high dimensional latent spaces that can be sampled to generate images resembling training set data. Moreover, these latent spaces are generally highly structured and can enable complex operations on the generated images by simple vector space arithmetic in the latent space (Larsen et al., 2016) .

Generative models are beginning to find their way out of academia and into creative applications. In this paper we present techniques for improving the visual quality of generative models that are generally independent of the model itself. These include spherical linear interpolation, visualizing analogies with J-diagrams, and generating local manifolds with MINE grids. These techniques can be combined generate low dimensional embeddings of images close to the trained manifold. These can be used for visualization and creating realistic interpolations across latent space. Also by standardizing these operations independent of model type, the latent space of different generative models are more directly comparable with each other, exposing the strengths and weaknesses of various approaches.

Additionally, two new techniques for building latent space attribute vectors are introduced. On labeled datasets with correlated labels, data replication can be used to create bias-corrected vectors. Synthetic attributes vectors also can be derived via data augmentation on unlabeled data. Quantitative analysis of attribute vectors can be performed by using them as the basis for attribute binary classifiers.

2. SAMPLING TECHNIQUES:

Generative models are often evaluated by examining samples from the latent space. Techniques frequently used are random sampling and linear interpolation. But often these can result in sampling the latent space from locations very far outside the manifold of probable locations.

Our work has followed two useful principles when sampling the latent space of a generative model. The first is to avoid sampling from locations that are highly unlikely given the prior of the model. This technique is very well established -including being used in the original VAE paper which adjusted sampling through the inverse CDF of the Gaussian to accommodate the Gaussian prior (Kingma & Welling, 2014) . The second principle is to recognize that the dimensionality of the latent space is often artificially high and may contains dead zones that are not on the manifold learned during training. This has been demonstrated for VAE models (Makhzani et al., 2016) and implies that simply matching the model's prior will not always be sufficient to yield samples that appear to have been drawn from the training set.

2.1. INTERPOLATION:

Interpolation is used to traverse between two known locations in latent space. Research on generative models often uses interpolation as a way of demonstrating that a generative model has not simply memorized the training examples (eg: Radford et al., 2015, §6.1) . In creative applications interpolations can be used to provide smooth transitions between two decoded images.

Frequently linear interpolation is used, which is easily understood and implemented. But this is often inappropriate as the latent spaces of most generative models are high dimensional (> 50 dimensions) with a Gaussian or uniform prior. In such a space, linear interpolation traverses locations that are extremely unlikely given the prior. As a concrete example, consider a 100 dimensional space with the Gaussian prior µ=0, σ=1. Here all random vectors will generally a length very close to 10 (standard deviation < 1). However, linearly interpolating between any two will usually result in a "tent-pole" effect as the magnitude of the vector decreases from roughly 10 to 7 at the midpoint, which is over 4 standard deviations away from the expected length.

Our proposed solution is to use spherical linear interpolation slerp instead of linear interpolation. We use a formula introduced by (Shoemake 85) in the context of great arc inbetweening for rotation animations:

This treats the interpolation as a great circle path on an n-dimensional hypersphere (with elevation changes). This technique has shown promising results on both VAE and GAN generative models and with both uniform and Gaussian priors (Figure 2 ). 

2.2. ANALOGY:

Analogy has been shown to capture regularities in continuous space models. In the latent space of some linguistic models "King -Man + Woman" results in a vector very close to "Queen" (Mikolov et al., 2013) . This technique has also been used in the context of deep generative models to solve visual analogies (Reed et al., 2015) .

Analogies are usually written in the form::

A : B :: C :? Such a formation answers the question "What is the result of applying the transformation A:B to C?" In a vector space the solution generally proposed is to solve the analogy using vector math:

(B -A) = (? -C) ? = C + B -A

Note that an interesting property of this solution is an implied symmetry:

A : C :: B :?

Because the same terms can be rearranged:

(C -A) = (? -B) ? = B + C -A

Generative models that include an encoder for computing latent vectors given new samples allow for visual analogies. We have devised a visual representation for depicting analogies of visual generative networks called a "J-Diagram". The J-Diagram uses interpolation across two dimensions two expose the manifold of the analogy. It also makes the symmetric nature of the analogy clear (Figure 3 ).

The J-Diagram also serves as a reference visualization across different model settings because it is deterministically generated from images which can be held constant. This makes it a useful tool for comparing results across epochs during training, after adjusting hyperparameters, or even across completely different model types (Figure 4 ). 

2.3. MANIFOLD TRAVERSAL:

Generative models can produce a latent space that is not tightly packed, and the dimensionality of the latent space is often set artificially high. As a result, the manifold of trained examples is can be a subset of the latent space after training, resulting in dead zones in the expected prior.

If the model includes an encoder, one simple way to stay on the manifold is by only using out of sample encodings (ie: any data not used in training) in the latent space. This is a useful diagnostic, but is overly restrictive in a creative application context since it prevents the model from suggesting new and novel samples from the model. However, we can recover this ability by also including the results of operations on these encoded samples that stay close to the manifold, such as interpolation, extrapolation, and analogy generation.

Ideally, there would be a mechanism to discover this manifold within the latent space. In generative models with an encoder and ample out-of-sample data, we can instead precompute locations on the manifold with sufficient density, and later query for nearby points in the latent space from this known set. This offers a navigation mechanism based on hopping to nearest neighbors across a large database of encoded samples. When combined with interpolation, we call this visualization a Manifold Interpolated Neighbor Embedding (MINE). A MINE grid is useful to visualize local patches of the latent space (Figure 5 ). 

3. ATTRIBUTE VECTORS:

Many generative models result in a latent space that is highly structured, even on purely unsupervised datasets (Radford et al., 2015) . When combined with labeled data, attribute vectors can be computed using simple arithmetic. For example, a vector can be computed which represents the smile attribute, which by shorthand we call a smile vector. Following (Larsen et al., 2016) , the smile vector can be computed by simply subtracting the mean vector for images without the smile attribute from the mean vector for images with the smile attribute. This smile vector can then be applied to in a positive or negative direction to manipulate this visual attribute on samples taken from latent space (Figure 6 ). The approach of building attribute vectors from means of labeled data has been noted to suffer from correlated labels (Larsen et al., 2016) . While many correlations would be expected from ground truths (eg: heavy makeup and wearing lipstick) we discovered others that appear to be from sampling bias. For example, male and smiling attributes have unexpected negative correlations because women in the CelebA dataset are much more likely to be smiling than men. (Table 1 ).

Male Not Male Total Smiling 17% 31% 48% Not Smiling 25% 27% 52% Total 42% 58%

Table 1 : Breakdown of CelebA smile versus male attributes. In the total population the smile attribute is almost balanced (48% smile). But separating the data further shows that those with the male attribute smile only 42% of the time while those without it smile 58% of the time.

Figure 7 : Initial attempts to build a smile vector suffered from sampling bias. The effect was that removing smiles from reconstructions (left) also added male attributes (center). By using replication to balance the data across both attributes before computing the attribute vectors, the gender bias was removed (right). (model: VAE from Lamb 16 on CelebA)

In an online service we setup to automatically add and remove smiles from images1 , we discovered this gender bias was visually evident in the results. Our solution was to use replication on the training data such that the dataset was balanced across attributes. This was effective because ultimately the vectors are simply summed together when computing the attribute vector (Figure 7 ).

This balancing technique can also be applied to attributes correlated due to ground truths. Decoupling attributes allows individual effects to be applied separately. As an example, the two attributes smiling and mouth open are highly correlated in the CelebA training set (Table 2 ). This is not surprising, as physically most people photographed smiling would also have their mouth open. However by forcing these attributes to be balanced, we can construct two decoupled attribute vectors. This allows for more flexibility in applying each attribute separately to varying degrees (Figure 8 ).

Open Mouth Not Open Mouth Total Smiling 36% 12% 48% Not Smiling 12% 40% 52% Total 48% 52% 

3.2. SYNTHETIC ATTRIBUTES:

It has been noted that samples drawn from VAE based models is that they tend to be blurry (Goodfellow et al., 2014; Larsen et al., 2015) . A possible solution to this would be to discover an attribute vector for "unblur", and then apply this as a constant offset to latent vectors before decoding. CelebA includes a blur label for each image, and so a blur attribute vector was computed and then extrapolated in the negative direction. This was found to noticeably reduce blur, but also resulted in a number of unwanted artifacts such as increased image brightness.

We concluded this to be the result of human bias in labeling. Labelers appear more likely to label darker images as blurry, so this unblur vector was found to suffer from attribute correlation that also "lightened" the reconstruction. This bias could not be easily corrected because CelebA does not include a brightness label for rebalancing the data.

For the blurring attribute, an algorithmic solution is available. We take a large set of images from the training set and process them through a Gaussian blur filter (figure 9 ). Then we run both the original image set and the blurred image set through the encoder and subtract the means of each set to compute a new attribute vector for blur. We call this a synthetic attribute vector because this label is derived from algorithmic data augmentation of the training set. This technique removes the labeler bias, is straightforward to implement, and resulted in samples closely resembling the reconstructions with less noticeable blur (figure 10 ). Applying an offset in latent space based on the CelebA blur attribute (third row) does reduce noticeable blur from the reconstructions, but introduces visual artifacts including brightening due to attribute correlation. Applying an attribute vector instead computed from synthetic blur (bottom) yields images noticeably deblurred from the reconstructions and without unrelated artifacts.

3.3. QUANTITATIVE ANALYSIS WITH CLASSICICATION:

The results of applying attribute vectors visually to images are often quite striking. But it would be useful to be able to evaluate the relative efficacy of various attribute vectors to each other or across different models and hyperparamaters. Attribute vectors have potential to be widely applicable outside of images in domain specific latent spaces, and this provides additional challenges for quantifying their performance. For example, recent work has shown the ability to use latent space model as a continuous representation of molecules (Gómez 16); though it is straightforward to generate vectors for attributes such as solubility in these spaces, the evaluation of these operations to existing molecules would appear to require specific domain knowledge.

We have found that very effective classifiers can be built in latent space using the dot product of an encoded vector with a computed attribute vector (figure 11A, 11B classifiers provide a quantitative basis to evaluate attribute vectors on a related surrogate task -their ability to be the basis for a simple linear classifier. This task is one of the most established paradigms in machine learning and provides a set of established tools such as ROC curves for offering new insights into the behavior of the attribute vectors across different hyperparameters or different models (figure 11C ). 

4. FUTURE WORK:

Software to support most techniques presented in this paper is included in a python software library that can be used with various generative models2 . We hope to continue to improve the library so that the techniques are applicable across a broad range of generative models. Attribute vector based classifiers also offer a promising way to evaluate the suitability of attribute vectors in domains outside of images.

We are investigating constructing a specially constructed prior on the latent space such that interpolations could be linear. This would simplify many of the latent space operations and might enable new types of operations.

Given sufficient test data, the extent to which an encoded dataset deviates from the expected prior should be quantifiable. Developing such a metric would be useful in understanding the structure of the different latent spaces including probability that random samples fall outside of the expected manifold of encoded data.

:

https://twitter.com/smilevector

https://github.com/dribnet/plat

Figures and Tables:

Figure 2: DCGAN (Radford 15) interpolation pairs with identical endpoints and uniform prior. In each pair, the top series is linear interpolation and the bottom is spherical. Note the weak generations produced by linear interpolation at the center, which are not present in spherical interpolation.

Figure 3: J-Diagram. The three corner images are inputs to the system, with the top left being the "source" (A) and the other two being "analogy targets" (B and C). Adjacent to each is the reconstruction resulting from running the image through both the encoder and decoder of the model. The bottom right image shows the result of applying the analogy operation (B + C) -A. All other images are interpolations using the slerp operator. (model: VAE from Lamb 16 on CelebA)

(a) Nearest Neighbors are found and embedded into a two dimensional grid. (b) Reconstructions are spread with interpolation to expose areas between them.

Figure 5: Example of local VAE manifold built using the 30k CelebA validation and test images as a dataset of out of sample features. The resulting MINE grid represents a small contiguous manifold of the larger latent space. (model: VAE from Lamb 16 on CelebA)

Figure 6: Traversals along the smile vector. (model: GAN from Dumoulin 16 on CelebA)

Figure 8: Decoupling attribute vectors for smiling (x-axis) and mouth open (y-axis) allows for more flexible latent space transformations. Input shown at left with reconstruction adjacent. (model: VAE from Lamb 16 on CelebA)

Figure 9: Zoomed detail from training images (top) and computed blurred images (bottom) were both encoded in order to determine a non-biased blur attribute vector.

Figure 10: Zoomed detail of images from the validation set (top) are reconstructed (second row).Applying an offset in latent space based on the CelebA blur attribute (third row) does reduce noticeable blur from the reconstructions, but introduces visual artifacts including brightening due to attribute correlation. Applying an attribute vector instead computed from synthetic blur (bottom) yields images noticeably deblurred from the reconstructions and without unrelated artifacts.

Figure 11: Example of using an attribute vector for classification. A smile vector is first constructed in latent space from labeled training data. By taking the dot product of this smile vector with the encoded representation of any face, a scalar smile score is generated (a). This score can be the basis for a binary classifier. The histogram shows the distribution of positive (green) and negative (red) scores on the CelebA validation set (b). The ROC curve for a smile vector based binary classifier is also shown (c).

CelebA smile versus open mouth attributes shows a strong symmetric correlation (greater than 3 to 1).

Table content: <table/>

). We have named this technique for building classifiers on latent spaces AtDot, and models trained on unsupervised data have been shown to produce strong results on CelebA across most attributes (table 3). Importantly, these binary Average Classification Accuracy on the CelebA dataset. Models for both VAE AtDot and GAN AtDot use unsupervised training with attribute vectors computed on the training set data after model training was completed. VAE AtDot from Lamb 16 with discriminative regularization disabled and GAN AtVec from Dumoulin 16. Other results are [1] Kumar 08, [2] Zhang 14, [3] Li 13, and [4] LeCun 94 as reported in Ehrlich 16.

Table content: <table><tr><td colspan="9">Approach / Attribute [1] [2] W [2] L [3] ANet [4] LNet [4] Full VAE AtDot GAN AtDot</td></tr><tr><td>5 O.C. Shadow</td><td>85</td><td>82</td><td>88</td><td>86</td><td>88</td><td>91</td><td>88</td><td>89</td></tr><tr><td>Arched Eyebrow</td><td>76</td><td>73</td><td>78</td><td>75</td><td>74</td><td>79</td><td>75</td><td>75</td></tr><tr><td>Attractive</td><td>78</td><td>77</td><td>81</td><td>79</td><td>77</td><td>81</td><td>71</td><td>69</td></tr><tr><td>Bags Under Eye</td><td>76</td><td>71</td><td>79</td><td>77</td><td>73</td><td>79</td><td>80</td><td>79</td></tr><tr><td>Bald</td><td>89</td><td>92</td><td>96</td><td>92</td><td>95</td><td>98</td><td>98</td><td>98</td></tr><tr><td>Bangs</td><td>88</td><td>89</td><td>92</td><td>94</td><td>92</td><td>95</td><td>90</td><td>90</td></tr><tr><td>Big Lips</td><td>64</td><td>61</td><td>67</td><td>63</td><td>66</td><td>68</td><td>85</td><td>76</td></tr><tr><td>Big Nose</td><td>74</td><td>70</td><td>75</td><td>74</td><td>75</td><td>78</td><td>77</td><td>77</td></tr><tr><td>Black Hair</td><td>70</td><td>74</td><td>85</td><td>77</td><td>84</td><td>88</td><td>83</td><td>81</td></tr><tr><td>Blond Hair</td><td>80</td><td>81</td><td>93</td><td>86</td><td>91</td><td>95</td><td>87</td><td>90</td></tr><tr><td>Blurry</td><td>81</td><td>77</td><td>86</td><td>83</td><td>80</td><td>84</td><td>95</td><td>95</td></tr><tr><td>Brown Hair</td><td>60</td><td>69</td><td>77</td><td>74</td><td>78</td><td>80</td><td>76</td><td>81</td></tr><tr><td>Bushy Eyebrow</td><td>80</td><td>76</td><td>86</td><td>80</td><td>85</td><td>90</td><td>87</td><td>86</td></tr><tr><td>Chubby</td><td>86</td><td>82</td><td>86</td><td>86</td><td>86</td><td>91</td><td>94</td><td>94</td></tr><tr><td>Double Chin</td><td>88</td><td>85</td><td>88</td><td>90</td><td>88</td><td>92</td><td>95</td><td>95</td></tr><tr><td>Eyeglasses</td><td>98</td><td>94</td><td>98</td><td>96</td><td>96</td><td>99</td><td>95</td><td>94</td></tr><tr><td>Goatee</td><td>93</td><td>86</td><td>93</td><td>92</td><td>92</td><td>95</td><td>93</td><td>94</td></tr><tr><td>Gray Hair</td><td>90</td><td>88</td><td>94</td><td>93</td><td>93</td><td>97</td><td>95</td><td>96</td></tr><tr><td>Heavy Makeup</td><td>85</td><td>84</td><td>90</td><td>87</td><td>85</td><td>90</td><td>76</td><td>75</td></tr><tr><td>High Cheekbone</td><td>84</td><td>80</td><td>86</td><td>85</td><td>84</td><td>87</td><td>81</td><td>68</td></tr><tr><td>Male</td><td>91</td><td>93</td><td>97</td><td>95</td><td>94</td><td>98</td><td>81</td><td>80</td></tr><tr><td>Mouth Open</td><td>87</td><td>82</td><td>93</td><td>85</td><td>86</td><td>92</td><td>78</td><td>67</td></tr><tr><td>Mustache</td><td>91</td><td>83</td><td>93</td><td>87</td><td>91</td><td>95</td><td>95</td><td>96</td></tr><tr><td>Narrow Eyes</td><td>82</td><td>79</td><td>84</td><td>83</td><td>77</td><td>81</td><td>93</td><td>89</td></tr><tr><td>No Beard</td><td>90</td><td>87</td><td>93</td><td>91</td><td>92</td><td>95</td><td>85</td><td>84</td></tr><tr><td>Oval Face</td><td>64</td><td>62</td><td>65</td><td>65</td><td>63</td><td>66</td><td>72</td><td>71</td></tr><tr><td>Pale Skin</td><td>83</td><td>84</td><td>91</td><td>89</td><td>87</td><td>91</td><td>96</td><td>96</td></tr><tr><td>Pointy Nose</td><td>68</td><td>65</td><td>71</td><td>67</td><td>70</td><td>72</td><td>72</td><td>72</td></tr><tr><td>Recede Hair</td><td>76</td><td>82</td><td>85</td><td>84</td><td>85</td><td>89</td><td>93</td><td>92</td></tr><tr><td>Rosy Cheeks</td><td>84</td><td>81</td><td>87</td><td>85</td><td>87</td><td>90</td><td>93</td><td>93</td></tr><tr><td>Sideburns</td><td>94</td><td>90</td><td>93</td><td>94</td><td>91</td><td>96</td><td>94</td><td>94</td></tr><tr><td>Smiling</td><td>89</td><td>89</td><td>92</td><td>92</td><td>88</td><td>92</td><td>87</td><td>68</td></tr><tr><td>Straight Hair</td><td>63</td><td>67</td><td>69</td><td>70</td><td>69</td><td>73</td><td>80</td><td>79</td></tr><tr><td>Wavy Hair</td><td>73</td><td>76</td><td>77</td><td>79</td><td>75</td><td>80</td><td>75</td><td>75</td></tr><tr><td>Earring</td><td>73</td><td>72</td><td>78</td><td>77</td><td>78</td><td>82</td><td>81</td><td>81</td></tr><tr><td>Hat</td><td>89</td><td>91</td><td>96</td><td>93</td><td>96</td><td>99</td><td>96</td><td>97</td></tr><tr><td>Lipstick</td><td>89</td><td>88</td><td>93</td><td>91</td><td>90</td><td>93</td><td>79</td><td>77</td></tr><tr><td>Necklace</td><td>68</td><td>67</td><td>67</td><td>70</td><td>68</td><td>71</td><td>88</td><td>88</td></tr><tr><td>Necktie</td><td>86</td><td>88</td><td>91</td><td>90</td><td>86</td><td>93</td><td>93</td><td>92</td></tr><tr><td>Young</td><td>80</td><td>77</td><td>84</td><td>81</td><td>83</td><td>87</td><td>78</td><td>81</td></tr><tr><td>Average</td><td>81</td><td>79</td><td>85</td><td>83</td><td>83</td><td>87</td><td>86</td><td>84</td></tr></table>

Peer review (iclr2017):
This paper proposed a set of different things under the name of *sampling generative models*, focusing on analyzing the learned latent space and synthesizing desirable output images with certain properties for GANs. This paper does not have one single clear message or idea, but rather proposed a set of techniques that seem to produce visually good looking results. While this paper has some interesting ideas, it also has a number of problems. The spherical interpolation idea is interesting, but after a second thought this does not make much sense. The proposed slerp interpolation equation (page 2) implicitly assumes that the two points q1 and q2 lie on the same sphere, in which case the parameter theta is the angle corresponding to the great arc connecting the two points on the sphere. However, the latent space of a GAN, no matter trained with a uniform distribution or a Gaussian distribution, is not a distribution on a sphere, and many points have different distances to the origin. The author*s justification for this comes from the well known fact that in high dimensional space, even with a uniform distribution most points lie on a thin shell in the unit cube. This is true because in high-dimensional space, the outer shell takes up most of the volume in space, and the inner part takes only a very small fraction of the space, in terms of volume. This does not mean the density of data in the outer shell is greater than the inner part, though. In a uniform distribution, the data density should be equal everywhere, a point on the outer shell is not more likely than a point in the inner part. Under a Gaussian model, the data density is on the other hand higher in the center and much lower on the out side. If we have a good model of data, then sampling the most likely points from the model should give us plausible looking samples. In this sense, spherical interpolation should do no better than the normally used linear interpolation. From the questions and answers it seems that the author does not recognize this distinction. The results shown in this paper seem to indicate that spherical interpolation is better visually, but it is rather hard to make any concrete conclusions from three pairs of examples. If this is really the case then there must be something else wrong about our understanding of the learned model. Aside from these, the J-diagram and the nearest neighbor latent space traversal both seems to be good ways to explore the latent space of a learned model. The attribute vector section on transforming images to new ones with desired attributes is also interesting, and it provides a few new ways to make the GAN latent space more interpretable. Overall I feel most of the techniques proposed in this paper are nice visualization tools. The contributions however, are mostly on the design of the visualizations, and not much on the technical and model side. The spherical interpolation provides the only mathematical equation in the paper, yet the correctness of the technique is arguable. For the visualization tools, there are also no quantitative evaluation, maybe these results are more art than science.