Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vq_vae.py #1928

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/generative/vq_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ def get_code_indices(self, flattened_inputs):
**A note on straight-through estimation**:

This line of code does the straight-through estimation part: `quantized = x +
tf.stop_gradient(quantized - x)`. During backpropagation, `(quantized - x)` won't be
tf.stop_gradient(quantized - x)`. The straight-through estimator affects the
forward computation and backpropagation differently.

During forward computation the x values cancel out and the nearest embedding `quantized`
is passed to the decoder.

During backpropagation, the `tf.stop_gradient` operator prevents the contribution
of its inputs from being taken into account. As a result, `(quantized - x)` won't be
included in the computation graph and the gradients obtained for `quantized`
will be copied for `inputs`. Thanks to [this video](https://youtu.be/VZFVUrYcig0?t=1393)
for helping me understand this technique.
Expand Down
Loading