{'fraction_non_alphanumeric': 0.03332419089413055, 'fraction_numerical': 0.009654415798134943, 'mean_word_length': 4.809592096876992, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deep Probabilistic Programming Languages: A Qualitative Study

Deep probabilistic programming languages try to combine the advantages of deep learning with those of probabilistic programming languages. If successful, this would be a big step forward in machine learning and programming languages. Unfortunately, as of now, this new crop of languages is hard to use and understand. This paper addresses this problem directly by explaining deep probabilistic programming languages and indirectly by characterizing their current strengths and weaknesses.


INTRODUCTION
A deep probabilistic programming language (PPL) is a language for specifying both deep neural networks and probabilistic models. In other words, a deep PPL draws upon programming languages, Bayesian statistics, and deep learning to ease the development of powerful machine-learning applications.
For decades, scientists have developed probabilistic models in various fields of exploration without the benefit of either dedicated programming languages or deep neural networks [12]. But since these models involve Bayesian inference with often intractable integrals, they sap the productivity of experts and are beyond the reach of non-experts. PPLs address this issue by letting users express a probabilistic model as a program [15]. The program specifies how to generate output data by sampling latent probability distributions. The compiler checks this program for type errors and translates it to a form suitable for an inference procedure, which uses observed output data to fit the latent distributions. Probabilistic models show great promise: they overtly represent uncertainty [6] and they have been demonstrated to enable explainable machine learning even in the important but difficult case of small training data [21,26,30].
Over the last few years, machine learning with deep neural networks (deep learning, DL) has become enormously popular. This is because in several domains, DL solves what was previously a vexing problem [10], namely manual feature engineering. Each layer of a neural network can be viewed as learning increasingly higherlevel features. In other words, the essence of DL is automatic hierarchical representation learning [22]. Hence, DL powered recent breakthrough results in accurate supervised large-data tasks such as image recognition [20] and natural language translation [33]. Today, most DL is based on frameworks that are well-supported, efficient, and expressive, such as TensorFlow [1] and PyTorch [11].
These frameworks provide automatic differentiation (users need not manually calculate gradients for gradient descent), GPU support (to efficiently execute vectorized computations), and Python-based embedded domain-specific languages [18].
Deep PPLs, which have emerged just recently [29][30][31][32], aim to combine the benefits of PPLs and DL. Ideally, programs in deep PPLs would overtly represent uncertainty, yield explainable models, and require only a small amount of training data; be easy to write in a well-designed programming language; and match the breakthrough accuracy and fast training times of DL. Realizing all of these promises would yield tremendous advantages. Unfortunately, this is hard to achieve. Some of the strengths of PPLs and DL are seemingly at odds, such as explainability vs. automated feature engineering, or learning from small data vs. optimizing for large data. Furthermore, the barrier to entry for work in deep PPLs is high, since it requires non-trivial background in fields as diverse as statistics, programming languages, and deep learning. To tackle this problem, this paper characterizes deep PPLs, thus lowering the barrier to entry, providing a programming-languages perspective early when it can make a difference, and shining a light on gaps that the community should try to address. This paper uses the Stan PPL as a representative of the state of the art in regular (not deep) PPLs [9]. Stan is a main-stream, mature, and widely-used PPL: it is maintained by a large group of developers, has a yearly StanCon conference, and has an active forum. Stan is Turing complete and has its own stand-alone syntax and semantics, but provides bindings for several languages including Python.
Most importantly, this paper uses Edward [31] and Pyro [32] as representatives of the state of the art in deep PPLs. Edward is based on TensorFlow and Pyro is based on PyTorch. Edward was first released in mid-2016 and has a single main maintainer, who is focusing on a new version. Pyro is a much newer framework (released late 2017), but seems to be very responsive to community questions. This paper characterizes deep PPLs by explaining them (Sections 2, 3, and 4), comparing them to each other and to regular PPLs and DL frameworks (Section 5), and envisioning next steps (Section 6). Additionally, the paper serves as a comparative tutorial to both Edward and Pyro. To this end, it presents examples of increasing complexity written in both languages, using deliberately uniform terminology and presentation style. By writing this paper, we hope to help the research community contribute to the exciting new field of deep PPLs, and ultimately, combine the strengths of both DL and PPLs.

PROBABILISTIC MODEL EXAMPLE
This section explains PPLs using an example that is probabilistic but not deep. The example, adapted from Section 9.1 of [3], is about learning the bias of a coin. We picked this example because it is simple, lets us introduce basic concepts, and shows how different PPLs represent these concepts. arXiv:1804.06458v1 [cs.AI] 17 Apr 2018 θ x i N Figure 1: Graphical model for biased coin tosses. Circles represent random variables. The white circle for θ indicates that it is latent and the gray circle for x i indicates that it is observed. The arrow represents dependency. The rounded rectangle is a plate, representing N distributions that are IID.
We write x i = 1 if the result of the i th coin toss is head and x i = 0 if it is tail. We assume that individual coin tosses are independent and identically distributed (IID) and that each toss follows a Bernoulli distribution with parameter θ : The latent (i.e., unobserved) variable θ is the bias of the coin. The task is to infer θ given the results of previously observed coin tosses, that is, p(θ | x 1 , x 2 , . . . , x N ). Figure 1 shows the corresponding graphical model. The model is generative: once the distribution of the latent variable has been inferred, one can draw samples to generate data points similar to the observed data.
We now present this simple example in Stan, Edward, and Pyro. In all these languages we follow a Bayesian approach: the programmer first defines a probabilistic model of the problem. Assumptions are encoded with prior distributions over the variables of the model. Then the programmer launches an inference procedure to automatically compute the posterior distributions of the parameters of the model based on observed data. In other words, inference adjusts the prior distribution using the observed data to give a more precise model. Compared to other machine-learning models such as deep neural networks, the result of a probabilistic program is a probability distribution, which allows the programmer to explicitly visualize and manipulate the uncertainty associated with a result. This overt uncertainty is an advantage of PPLs. Furthermore, a probabilistic model has the advantage that it directly describes the corresponding world based on the programmer's knowledge. Such descriptive models are more explainable than deep neural networks, whose representation is big and does not overtly resemble the world they model. Figure 2(a) solves the biased-coin task in Stan, a well-established PPL [9]. This example uses PyStan, the Python interface for Stan. Lines 2-13 contain code in Stan syntax in a multi-line Python string. The data block introduces observed random variables, which are placeholders for concrete data to be provided as input to the inference procedure, whereas the parameters block introduces latent random variables, which will not be provided and must be inferred. Line 4 declares x as a vector of ten discrete random variables, constrained to only take on values from a finite set, in this case, either 0 or 1. Line 7 declares θ as a continuous random variable, which can take on values from an infinite set, in this case, real numbers between 0 and 1. Stan uses the tilde operator (~) for sampling. Line 10 samples θ from a uniform distribution (same probability for all values) between 0 and 1. Since θ is a latent variable, this distribution is merely a prior belief, which inference will replace by a posterior distribution. Line 12 samples the x i from a Bernoulli distribution with parameter θ . Since the x i are observed variables, this sampling is really a check for how well the model corresponds to data provided at inference time. One can think of sampling an observed variable like an assertion in verification [15]. Line 15 specifies the data and Lines 17-18 run the inference using the model and the data. By default, Stan uses a form of Monte-Carlo sampling for inference [9]. Lines 20-22 extract and print the mean and standard deviation of the posterior distribution of θ . Figure 2(b) solves the same task in Edward [31]. Line 2 samples θ from the prior distribution, and Line 3 samples a vector of random variables from a Bernoulli distribution of parameter θ , one for each coin toss. Line 5 specifies the data. Lines 7-8 define a placeholder that will be used by the inference procedure to compute the posterior distribution of θ . The shape and size of the placeholder depends on the inference procedure. Here we use the Hamiltonian Monte-Carlo inference HMC, the posterior distribution is thus computed based on a set of random samples and follows an empirical distribution. The size of the placeholder corresponds to the number of random samples computed during inference. Lines 9-11 launch the inference. The inference takes as parameter the prior:posterior pair theta:qtheta and links the data to the variable x. Lines 13-16 extract and print the mean and standard deviation of the posterior distribution of θ . Figure 2(c) solves the same task in Pyro [32]. Lines 2-7 define the model as a function coin. Lines 3-5 sample θ from the prior distribution, and Lines 6-7 sample a vector of random variable x from a Bernoulli distribution of parameter θ . Pyro stores random variables in a dictionary keyed by the first argument of the function pyro.sample. Lines 9-10 define the data as a dictionary. Line 12 conditions the model using the data by matching the value of the data dictionary with the random variables defined in the model. Lines 13-15 apply inference to this conditioned model, using importance sampling. Compared to Stan and Edward, we first define a conditioned model with the observed data before running the inference instead of passing the data as an argument to the inference. The inference returns a probabilistic model, post, that can be sampled to extract the mean and standard deviation of the posterior distribution of θ in Lines 17-19.
The deep PPLs Edward and Pyro are built on top of two popular deep learning frameworks TensorFlow [1] and PyTorch [11]. They benefit from efficient computations over large datasets, automatic differentiation, and optimizers provided by these frameworks that can be used to efficiently implement inference procedures. As we will see in the next sections, this design choice also reduces the gap between DL and probabilistic models, allowing the programmer to combine the two. On the other hand, this choice leads to piling up abstractions (Edward/TensorFlow/Numpy/Python or Pyro/Py-Torch/Numpy/Python) that can complicate the code. We defer a discussion of these towers of abstraction to Section 5.

Variational Inference
Inference, for Bayesian models, computes the posterior distribution of the latent parameters θ given a set of observations x, that is, p(θ | x). For complex models, computing the exact posterior distribution can be costly or even intractable. Variational inference turns the inference problem into an optimization problem and tends 2 coin_code = """   to be faster and more adapted to large datasets than sampling-based Monte-Carlo methods [4]. Variational infence tries to find the member q * (θ ) of a family Q of simpler distribution over the latent variables that is the closest to the true posterior p(θ | x). The fitness of a candidate is measured using the Kullback-Leibler (KL) divergence from the true posterior, a similarity measure between probability distributions.
It is up to the programmer to choose a family of candidates, or guides, that is sufficiently expressive to capture a close approximation of the true posterior, but simple enough to make the optimization problem tractable.
Both Edward and Pyro support variational inference. Figure 3 shows how to adapt Figure 2 to use it. In Edward (Figure 3(a)), the programmer defines the family of guides by changing the shape of the placeholder used in the inference. Lines 2-4 use a beta distribution with unknown parameters α and β that will be computed during inference. Lines 6-7 do variational inference using the Kullback-Leibler divergence. In Pyro (Figure 3(b)), this is done by defining a guide function. Lines 2-5 also define a beta distribution with parameters α and β. Lines 7-9 do inference using Stochastic Variational Inference, an optimized algorithm for variational inference. Both Edward and Pyro rely on the underlying framework to solve the optimization problem. Probabilistic inference thus closely follows the scheme used for training procedures of DL models.
This section gave a high-level introduction to PPLs and introduced basic concepts (generative models, sampling, prior and posterior, latent and observed, discrete and continuous). Next, we turn our attention to deep learning.

PROBABILISTIC MODELS IN DL
This section explains DL using an example of a deep neural network and shows how to make that probabilistic. The task is multiclass classification: given input features x, e.g., an image of a handwritten digit [23] comprising n x = 28 · 28 pixels, predict a label l, e.g., one of n y = 10 digits. Before we explain how to solve this task using DL, let us clarify some terminology. In cases where DL uses different terminology from PPLs, this paper favors the PPL terminology. So we say inference for what DL calls training; predicting for what DL calls inferencing; and observed variables for what DL calls training data. For instance, the observed variables for inference in the classifier task are the image x and label l.
Among the many neural network architectures suitable for this task, we chose a simple one: a multi-layer perceptron (MLP [28]). We start with the non-probabilistic version. Figure 4(a) shows an MLP with a 2-feature input layer, a 3-feature hidden layer, and a 2-feature output layer; of course, this generalizes to wider (more features) and deeper (more layers) MLPs. From left to right, there is a fully-connected subnet where each input feature x i contributes to each hidden feature h j , multiplied with a weight w ji and offset with a bias b j . The weights and biases are latent variables. Treating the input, biases, and weights as vectors and a matrix lets us cast this subnet in linear algebra xW h + b h , which can run efficiently via vector instructions on CPUs or GPUs. Next, a rectified linear unit ReLU (z) = max(0, z) computes the hidden feature vector h. The ReLU lets the MLP discriminate input spaces that are not linearly separable. The hidden layer exhibits both the advantage and disadvantage of deep learning: automatically learned features that need not be hand-engineered but would require non-trivial reverse engineering to explain in real-world terms. Next, another fullyconnected subnet hW y + b y computes the output layer y. Then, the softmax computes a vector π of scores that add up to one. The higher the value of π l , the more strongly the classifier predicts label l. Using the output of the MLP, the argmax extracts the label l with highest score.
Traditional methods to train such a neural network incrementally update the latent parameters of the network to optimize a loss function via gradient descent [28]. In the case of hand-written digits, the loss function is a distance metrics between observed and predicted labels. The variables and computations are non-probabilistic, in that they use concrete values rather than probability distributions.
Deep PPLs can express Bayesian neural networks with probabilistic weights and biases [5]. One way to visualize this is by replacing rectangles with circles for latent variables in Figure 4(a) to indicate that they hold probability distributions. Figure 4(b) shows the corresponding graphical model, where the latent variable θ denotes all the parameters of the MLP: Bayesian inference starts from prior beliefs about the parameters and learns distributions that fit observed data (such as, images and labels). We can then sample concrete weights and biases to obtain a concrete MLP. In fact, we do not need to stop at a single MLP: we can sample an ensemble of as many MLPs as we like. Then, we can feed a concrete image to all the sampled MLPs to get their predictions, followed by a vote. Figure 5(a) shows the probabilistic MLP example in Edward. Lines 3-4 are placeholders for observed variables (i.e., batches of images x and labels l). Lines 5-9 defines the MLP parameterized by θ , a dictionary containing all the network parameters. Lines 10-14 sample the parameters from the prior distributions. Line 15 defines the output of the network: a categorical distribution over all possible label values parameterized by the output of the MLP. Line 17-23 define the guides for the latent variables, initialized with random numbers. Later, the variational inference will update these during optimization, so they will ultimately hold an approximation of the posterior distribution after inference. Lines 25-29 set up the inference with one prior:posterior pair for each parameter of the network and link the output of the network to the observed data. Figure 5(b) shows the same example in Pyro. Lines 2-11 contain the basic neural network, where torch.nn.Linear wraps the low-level linear algebra. Lines 3-6 declare the structure of the net, that is, the type and dimension of each layer. Lines 7-10 combine the layers to define the network. It is possible to use equivalent high-level TensorFlow APIs for this in Edward as well, but we refrained from doing so to illustrate the transition of the parameters to random variables. Lines 14-20 define the model. Lines 15-18 sample priors for the parameters, associating them with object properties created by torch.nn.Linear (i.e., the weight and bias of each layer). Line 19 lifts the MLP definition from concrete to probabilistic. We thus obtain a MLP where all parameters are treated as random variables. Line 20 conditions the model using a categorical distribution over all possible label values. Lines 26-31 define the guide for the latent variables, initialized with random numbers, just like in the Edward version. Line 33 sets up the inference.
After the inference, Figure 6 shows how to use the posterior distribution of the MLP parameters to classify unknown data. In Edward (Figure 6  'lh.weight': Normal(vr("Wh_m", nh, nx), F.softplus(vr("Wh_s", nh, nx))), 28 'lh.bias': Normal(vr("bh_m", nh), F.softplus(vr("bh_s", nh))), 29 'ly.weight': Normal(vr("Wy_m", ny, nh), F.softplus(vr("Wy_s", ny, nh))), 30 'ly.bias': Normal(vr("by_m", ny), F.softplus(vr("by_s", ny))) }   MLP with each concrete model. Line 7 computes the score of a label as the average of the scores returned by the MLPs. Finally, Line 8 predicts the label with the highest score. In Pyro (Figure 6(b)), the prediction is done similarly but we obtain multiple versions of the MLP by sampling the guide (Line 2-3), not the parameters. This section showed how to use probabilistic variables as building blocks for a DL model. Compared to non-probabilistic DL, this approach has the advantage of reduced overfitting and accurately quantified uncertainty [5]. On the other hand, this approach requires inference techniques, like variational inference, that are more advanced than classic back-propagation. The next section will present the dual approach, showing how to use neural networks as building blocks for a probabilistic model.

DL IN PROBABILISTIC MODELS
This section explains how deep PPLs can use non-probabilistic deep neural networks as components in probabilistic models. The example task is learning a vector-space representation. Such a representation reduces the number of input dimensions to make other machine-learning tasks more manageable by counter-acting the curse of dimensionality [10]. The observed random variable is x, for instance, an image of a hand-written digit with n x = 28 · 28 pixels. The latent random variable is z, the vector-space representation, for instance, with n z = 4 features. Learning a vector-space representation is an unsupervised problem, requiring only images but no labels. While not too useful on its own, such a representation is an essential building block. For instance, it can help in other image generation tasks, e.g., to generate an image for a given writing style [30]. Furthermore, it can help learning with small data, e.g., via a K-nearest neighbors approach in vector space [2].
Each image x depends on the latent representation z in a complex non-linear way (i.e., via a deep neural network). The task is to learn this dependency between x and z. The top half of Figure 7(a) shows the corresponding graphical model. The output of the neural network, named decoder, is a vector µ that parameterizes a Bernoulli distribution over each pixel in the image x. Each pixel is thus associated to a probability of being present in the image. Similarly to Figure 4(b) the parameter θ of the decoder is global (i.e., shared by all data points) and is thus drawn outside the plate. Compared to Section 3 the network here is not probabilistic, hence the square around θ .
The main idea of the VAE [19,27] is to use variational inference to learn the latent representation. As for the examples presented in the previous sections, we need to define a guide for the inference. The guide maps each x to a latent variable z via another neural network. The bottom half of Figure 7(a) shows the graphical model of the guide. The network, named encoder, returns, for each image x, the parameters µ z and σ z of a Gaussian distribution in the latent space. Again the parameter ϕ of the network is global and not probabilistic. Then inference tries to learn good values for parameter θ and ϕ, simultaneously training the decoder and the encoder, according to the data and the prior beliefs on the latent variables (e.g., Gaussian distribution).
After the inference, we can generate a latent representation of an image with the encoder and reconstruct the image with the decoder. The similarity of the two images gives an indication of the success of the inference. The model and the guide together can thus be seen as an autoencoder, hence the term variational autoencoder. The parameter θ is initialized with random noise. Line 13 samples the priors for the latent variable z from a Gaussian distribution. Lines 14-15 define the dependency between x and z, as a Bernoulli distribution parameterized by the output of the decoder. Lines 17-29 define the encoder: a neural network with one hidden layer and two distinct output layers for µ z and σ z . The parameter ϕ is also initialized with random noise. Lines 30-31 define the inference guide for the latent variable, that is, a Gaussian distribution parameterized by the outputs of the encoder. Line 33 sets up the inference matching the prior:posterior pair for the latent variable and linking the data with the output of the decoder. Figure 7(c) shows the VAE example in Pyro. Lines 2-12 define the decoder. Lines 13-19 define the model. Lines 14-16 sample the priors for the latent variable z. Lines 18-19 define the dependency between x and z via the decoder. In contrast to Figure 5(b), the decoder is not probabilistic, so there is no need for lifting the network. Lines 34-37 define the guide as in Edward linking z and x via the decoder defined Lines 21-33. Line 39 sets up the inference.
This example illustrates that we can embed non-probabilistic DL models inside probabilistic programs and learn the parameters of the DL models during inference. Sections 2, 3, and 4 were about explaining deep PPLs with examples. The next section is about comparing deep PPLs with each other and with their potential.

CHARACTERIZATION
This section attempts to answer the following research question: At this point in time, how well do deep PPLs live up to their potential? Deep PPLs combine probabilistic models, deep learning, and programming languages in an effort to combine their advantages. This section explores those advantages grouped by pedigree and uses them to characterize Edward and Pyro.
Before we dive in, some disclaimers are in order. First, both Edward and Pyro are young, not mature projects with years of improvements based on user experiences, and they enable new applications that are still under active research. We should keep this in mind when we criticize them. On the positive side, early criticism can be a positive influence. Second, since getting even a limited number of example programs to support direct side-byside comparisons was non-trivial, we kept our study qualitative. A respectable quantitative study would require more programs and data sets. On the positive side, all of the code shown in this paper actually runs. Third, doing an outside-in study risks missing subtleties that the designers of Edward and Pyro may be more expert in. On the positive side, the outside-in view resembles what new users experience.

Advantages from Probabilistic Models
Probabilistic models support overt uncertainty: they give not just a prediction but also a meaningful probability. This is useful to avoid uncertainty bugs [6], track compounding effects of uncertainty, and even make better exploration decisions in reinforcement learning [5]. Both Edward and Pyro support overt uncertainty well, see e.g. the lines under the comment "# Results" in Figure 2.
Probabilistic models give users a choice of inference procedures: the user has the flexibility to pick and configure different approaches. Deep PPLs support two primary families of inference procedures: those based on Monte-Carlo sampling and those based on variational inference. Edward supports both and furthermore flexible compositions, where different inference procedures are applied to different parts of the model. Pyro supports primarily variational inference and focuses less on Monte-Carlo sampling. In comparison, Stan makes a form of Monte-Carlo sampling the default, focusing on making it easy-to-tune in practice [8].
Probabilistic models can help with small data: even when inference uses only small amount of labeled data, there have been   high-profile cases where probabilistic models still make accurate predictions [21]. Working with small data is useful to avoid the cost of hand-labeling, to improve privacy, to build personalized models, and to do well on underrepresented corners of a big-data task.
The intuition for how probabilistic models help is that they can make up for lacking labeled data for a task by domain knowledge incorporated in the model, by unlabeled data, or by labeled data for other tasks. There are some promising initial successes of using deep probabilistic programming on small data [26,30]; at the same time, this remains an active area of research. Probabilistic models can support explainability: when the components of a probabilistic model correspond directly to concepts of a real-world domain being modeled, predictions can include an explanation in terms of those concepts. Explainability is useful when predictions are consulted for high-stakes decisions, as well as for transparency around bias [7]. Unfortunately, the parameters of a deep neural network are just as opaque with as without probabilistic programming. There is cause for hope though. For instance, Siddharth et al. advocate disentangled representations that help explainability [30]. Overall, the jury is still out on the extent to which deep PPLs can leverage this advantage from PPLs.

Advantages from Deep Learning
Deep learning is automatic hierarchical representation learning [22]: each unit in a deep neural network can be viewed as an automatically learned feature. Learning features automatically is useful to avoid the cost of engineering features by hand. Fortunately, this DL advantage remains true in the context of a deep PPL. In fact, a deep PPL makes the trade-off between automated and hand-crafted features more flexible than most other machine-learning approaches.
Deep learning can accomplish high accuracy: for various tasks, there have been high-profile cases where deep neural networks beat out earlier approaches with years of research behind them. Arguably, the victory of DL at the ImageNet competition in 2012 ushered in the latest craze around DL [20]. Record-breaking accuracy is useful not just for publicity but also to cross thresholds where practical deployments become desirable, for instance, in machine translation [33]. Since a deep PPL can use deep neural networks, in principle, it inherits this advantage from DL [31]. However, even non-probabilistic DL requires tuning, and in our experience with the example programs in this paper, the tuning burden is exacerbated with variational inference.
Deep learning supports fast inference: even for large models and a large data set, the wall-clock time for a batch job to infer posteriors is short. The fast-inference advantage is the result of the back-propagation algorithm [28], novel techniques for parallelization [25] and data representation [17], and massive investments in the efficiency of DL frameworks such as TensorFlow and PyTorch, with vectorization on CPU and GPU. Fast inference is useful for iterating more quickly on ideas, trying more hyperparameter during, and wasting fewer resources. Tran et al. measured the efficiency of the Edward deep PPL, demonstrating that it does benefit from the efficiency advantage of the underlying DL framework [31].

Advantages from Programming Languages
Programming language design is essential for composability: bigger models can be composed from smaller components. Composability is useful for testing, team-work, and reuse. Conceptually, both graphical probabilistic models and deep neural networks compose well. On the other hand, some PPLs impose structure in a way that reduces composability; fortunately, this can be mitigated [16]. Both Edward and Pyro are embedded in Python, and, as our example programs demonstrate, work with Python functions and classes. For instance, users are not limited to declaring all latent variables in one place; instead, they can compose models, such as MLPs, with separately declared latent variables. Edward and Pyro also work with higher-level DL framework modules such as tf.layers.dense or torch.nn.Linear, and Pyro even supports automatically lifting those to make them probabilistic. Edward and Pyro also do not prevent users from composing probabilistic models with non-probabilistic code, but doing so requires care. For instance, when Monte-Carlo sampling runs the same code multiple times, it is up to the programmer to watch out for unwanted side-effects. One area where more work is needed is the extensibility of Edward or Pyro itself [8].
Finally, in addition to composing models, Edward also emphasizes composing inference procedures.
Not all PPLs have the same expressiveness: some are Turing complete, others not [15]. For instance, BUGS is not Turing complete, but has nevertheless been highly successful [13]. The field of deep probabilistic programming is too young to judge which levels of expressiveness are how useful. Edward and Pyro are both Turing complete. However, Edward makes it harder to express while-loops and conditionals than Pyro. Since Edward builds on TensorFlow, the user must use special APIs to incorporate dynamic control constructs into the computational graph. In contrast, since Pyro builds on PyTorch, it can use native Python control constructs, one of the advantages of dynamic DL frameworks [24].
Programming language design affects conciseness: it determines whether a model can be expressed in few lines of code. Conciseness is useful to make models easier to write and, when used in good taste, easier to read. In our code examples, Edward is more concise than Pyro. Pyro arguably trades conciseness for structure, making heavier use of Python classes and functions. Wrapping the model and guide into functions allows compiling them into co-routines, an ingredient for implementing efficient inference procedures [14]. In both Edward and Pyro, conciseness is hampered by the Bayesian requirement for explicit priors and by the variational-inference requirement for explicit guides.
Programming languages can offer watertight abstractions: they can abstract away lower-level concepts and prevent them from leaking out, for instance, using types and constraints [8]. Consider the expression xW [1] + b [1] from Section 3. At face value, this looks like eager arithmetic on concrete scalars, running just once in the forward direction. But actually, it may be lazy (building a computational graph) arithmetic on probability distributions (not concrete values) of tensors (not scalars), running several times (for different Monte-Carlo samples or data batches), possibly in the backward direction (for back-propagation of gradients). Abstractions are useful to reduce the cognitive burden on the programmer, but only if they are watertight. Unfortunately, abstractions in deep PPLs are leaky.
Our code examples directly invoke features from several layers of the technology stack (Edward or Pyro, on TensorFlow or PyTorch, on NumPy, on Python). Furthermore, we found that error messages rarely refer to source code constructs. For instance, names of Python variables are erased from the computational graph, making it hard to debug tensor dimensions, a common cause for mistakes. It does not have to be that way. For instance, DL frameworks are good at hiding the abstraction of back-propagation. More work is required to make deep PPL abstractions more watertight.

CONCLUSION AND OUTLOOK
This paper is a study of two deep PPLs, Edward and Pyro. The study is qualitative and driven by code examples. This paper explains how to solve common tasks, contributing side-by-side comparisons of Edward and Pyro. The potential of deep PPLs is to combine the advantages of probabilistic models, deep learning, and programming languages. In addition to comparing Edward and Pyro to each other, this paper also compares them to that potential. A quantitative study is left to future work. Based on our experience, we confirm that Edward and Pyro combine three advantages out-of-the-box: the overt uncertainty of probabilistic models; the hierarchical representation learning of DL; and the composability of programming languages.
Following are possible next steps in deep PPL research.
• Choice of inference procedures: Especially Pyro should support Monte-Carlo methods at the same level as variational inference. • Small data: While possible in theory, this has yet to be demonstrated on Edward and Pyro, with interesting data sets. • High accuracy: Edward and Pyro need to be improved to simplify the tuning required to improve model accuracy. • Expressiveness: While Turing complete in theory, Edward should adopt recent dynamic TensorFlow features for usability. • Conciseness: Both Edward and Pyro would benefit from reducing the repetitive idioms of priors and guides. • Watertight abstractions: Both Edward and Pyro fall short on this goal, necessitating more careful language design. • Explainability: This is inherently hard with deep PPLs, necessitating more machine-learning innovation.
In summary, deep PPLs show great promises and remain an active field with many research opportunities.