tensorflow / tensorflow/probability
wrong loss function in examples for VI reparameterization layers
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
In example for https://www.tensorflow.org/probability/api_docs/python/tfp/layers/DenseReparameterization, it states
import tensorflow as tf
import tensorflow_probability as tfp
model = tf.keras.Sequential([
tfp.layers.DenseReparameterization(512, activation=tf.nn.relu),
tfp.layers.DenseReparameterization(10),
])
logits = model(features)
neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(
labels=labels, logits=logits)
kl = sum(model.losses)
loss = neg_log_likelihood + kl
train_op = tf.train.AdamOptimizer().minimize(loss)
However, the KL loss is already incorporated in the call functions of any child that inherits _DenseVariational
Thus the examples of any layer that inherits _DenseVariational and also DenseVariational should exclude kl in the loss functions. ie.
import tensorflow as tf
import tensorflow_probability as tfp
model = tf.keras.Sequential([
tfp.layers.DenseReparameterization(512, activation=tf.nn.relu),
tfp.layers.DenseReparameterization(10),
])
logits = model(features)
neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(
labels=labels, logits=logits)
loss = neg_log_likelihood
train_op = tf.train.AdamOptimizer().minimize(loss)
Please feel free to correct me if I am wrong.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DenseReparameterization API example at the linked TensorFlow Probability documentation and inspect the referenced dense_variational.py location. Verify whether the layer already adds KL terms to model.losses, then check the affected reparameterization-layer examples and confirm the documented loss matches that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100