TensorFlow Probability is a library for statistical computation and probabilistic modeling built on top of TensorFlow.

Its building blocks include a vast range of distributions and invertible transformations (bijectors), probabilistic layers that may be used in keras models, and tools for probabilistic reasoning including variational inference and Markov Chain Monte Carlo.


To install tfprobability from github, do


TensorFlow Probability depends on TensorFlow, and in the same way, tfprobability depends on a working installation of the R packages tensorflow and keras. To get the most up-to-date versions of these packages, install them from github as well:


As to the Python backend, if you do


you will automatically get the current stable version of TensorFlow Probability together with TensorFlow. Correspondingly, if you need nightly builds,

install_tensorflow(version = "nightly")

will get you the nightly build of TensorFlow as well as TensorFlow Probability.


High-level application of tfprobability to tasks like

  • probabilistic (multi-level) modeling with MCMC and/or variational inference,
  • uncertainty estimation for neural networks,
  • time series modeling with state space models, or
  • density estimation with autoregressive flows

are described in the vignettes/articles and/or featured on the TensorFlow for R blog.

This introductory text illustrates the lower-level building blocks: distributions, bijectors, and probabilistic keras layers.


Distributions are objects with methods to compute summary statistics, (log) probability, and (optionally) quantities like entropy and KL divergence.


Bijectors are invertible transformations that allow to derive data likelihood under the transformed distribution from that under the base distribution. For an in-detail explanation, see Getting into the flow: Bijectors in TensorFlow Probability on the TensorFlow for R blog.

Keras layers

tfprobality wraps distributions in Keras layers so we can use them seemlessly in a neural network, and work with tensors as targets as usual. For example, we can use layer_kl_divergence_add_loss to have the network take care of the KL loss automatically, and train a variational autoencoder with just negative log likelihood only, like this: