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

Vector Quantization Layer Prototype #52

Merged
merged 21 commits into from
Sep 21, 2018
Merged

Vector Quantization Layer Prototype #52

merged 21 commits into from
Sep 21, 2018

Conversation

Simsso
Copy link
Owner

@Simsso Simsso commented Sep 18, 2018

This PR contains a vector quantization (VQ) prototype that was developed and tested in four Jupyter notebooks.

The code is not production-ready and only there for the sake of experimenting (it is located in /experiments). The well-tested and functionally extended version can now be developed based on this prototype (#51). Merging of this PR resolves #25.

The work can be found here (please review the four files + README.md):

@Simsso Simsso added code Software is relevant or involved research Scientific items labels Sep 18, 2018
@Simsso Simsso added this to the 12. Working Group Meeting milestone Sep 18, 2018
@Simsso Simsso self-assigned this Sep 18, 2018
@Simsso Simsso changed the title VQ Layer Prototype Vector Quantization Layer Prototype Sep 18, 2018
@Simsso Simsso requested review from a user and FlorianPfisterer September 19, 2018 16:09
@Simsso Simsso mentioned this pull request Sep 19, 2018
7 tasks
@Simsso
Copy link
Owner Author

Simsso commented Sep 20, 2018

Great notebook, @FlorianPfisterer.
Here is my review on the vq_layer function definition.

  • Why do you need a transpose operations in this line of code?
    scores = tf.reduce_sum(tf.square(tf.expand_dims(x, 2) - tf.transpose(embed_space)), axis=1)
    Update: okay, got it. You can save the transpose when expanding on axis=1.
  • You are adding a stop_gradient over here; I forgot that.
    vq_loss = tf.reduce_mean(tf.norm(tf.stop_gradient(x) - chosen_embeddings, ord='euclidean'))
  • This loss term is similar to the VQ-VAE paper:
    commit_loss = BETA * tf.reduce_mean(tf.norm(x - tf.stop_gradient(chosen_embeddings), ord='euclidean'))
    It's a very good idea to add it, even though I'm not sure whether we're going to train our conv layers. But the production VQ layer version should have it!

@FlorianPfisterer
Copy link
Collaborator

FlorianPfisterer commented Sep 20, 2018

This loss term is similar to the VQ-VAE paper

Well, that's because my experiments where based on the paper 😆. We're not going to train the conv layers, but it still adds a gradient flow that might be relevant for another VQ-layer further upstream.

Copy link
Collaborator

@FlorianPfisterer FlorianPfisterer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor things, mostly questions. Really great experiments, I especially love the plots where one can see how the embeddings move!

" access_count = tf.reduce_sum(one_hot_access, axis=[0, 1], name='access_count')\n",
"\n",
" # closest embedding update loss (alpha-loss)\n",
" nearest_loss = tf.reduce_mean(alpha * tf.norm(y - x, lookup_ord, axis=2), axis=[0, 1])\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you noted yourself, add the tf.stop_gradient() here for y.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather for x, I'd say. Can you triple-check, please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by alpha-loss you're referring to the second term in the following loss function (from the paper), then yes:
image

experiments/vq-layer/002-projection-evaluation.ipynb Outdated Show resolved Hide resolved
@Simsso Simsso added the work-item Tasks label Sep 21, 2018
@Simsso Simsso merged commit 0d1bbb2 into master Sep 21, 2018
@Simsso Simsso deleted the vq-prototype branch September 21, 2018 08:49
@Simsso Simsso removed the work-item Tasks label Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Software is relevant or involved research Scientific items
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vector Quantization Prototype
2 participants