tensorflow / tensorflow/probability

`TypeSpec` issue using `JointDistribution` with `DistributionLambda` layer

Open
#1,570 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I'm getting an error trying to build a Keras model (using either the sequential or functional API) using a DistributionLambda output layer with a lambda function that returns JointDistribution as the make_distribution_fn.

The error is: ValueError: KerasTensor only supports TypeSpecs that have a shape field; got TensorTupleSpec, which does not have a shape..

TFP version 0.16.0
TF version 2.8.0

Here is test case (which was originally in tensorflow_probability/python/layers/distribution_layer_test.py but removed with a810afe).

x = tf.keras.Input(shape=())
y = tfp.layers.VariableLayer(shape=[2, 4, 3], dtype=tf.float32)(x)
y = tf.keras.layers.Dense(5, use_bias=False)(y)
y = tfp.layers.DistributionLambda(
    lambda t: tfd.JointDistributionSequential([  # pylint: disable=g-long-lambda
        tfd.Gamma(t[..., 0], t[..., 1]),
        tfd.Normal(t[..., 2], 1),
        lambda m, s: tfd.Normal(loc=m, scale=s),
    ]),
)(y)
m = tf.keras.Model(x, y)

I haven't been able to work out why the test was removed, but was wondering if there might be a new approach to accommodate the same end.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced model in the issue and the former test in tensorflow_probability/python/layers/distribution_layer_test.py. Review commit a810afe to understand why that test was removed, then run the case with TensorFlow 2.8.0 and TensorFlow Probability 0.16.0. Done means a Keras model using DistributionLambda with JointDistribution can be built without the TypeSpec error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.