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

Feature/ali #597

Merged
merged 11 commits into from
Apr 15, 2017
Merged

Feature/ali #597

merged 11 commits into from
Apr 15, 2017

Conversation

AlexLewandowski
Copy link
Contributor

Following the pull request from last week, I added an example for ali.py. The MNIST reconstructions are not perfect, but I haven't fiddled with the hyperparameters very much.

@dustinvtran
Copy link
Member

Nice work! Quick comment from a glimpse (will add more details later): since you're only calling parent methods for update and initialize, you could probably remove those implementations from ALI.

Copy link
Member

@dustinvtran dustinvtran left a comment

Choose a reason for hiding this comment

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

The code looks great; comments below.

``ALI`` matches a mapping from data to latent variables and a
mapping from latent variables to data through a joint
discriminator. The encoder approximates the posterior p(z|x)
when the network is stochastic.
Copy link
Member

Choose a reason for hiding this comment

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

Actually this is untrue. The terminology "Adversarially learned inference" is a misnomer because the distribution p( z | x) in GANs is degenerate. More accurately would be to say

Using a joint discriminator, ``ALI`` learns a mapping from noise to data 
as well as an inverse mapping from data to noise. The inference network 
is the inverse mapping.

We discuss this misconception in my paper on deep implicit models (see the noise vs latent variables part of section 2.1).

I personally prefer the other paper which calls it "adversarial feature learning"/BiGANs; to me this description is more accurate. So I'd be for BiGANInference, but if you feel strongly about ALI, that's okay too.



class ALI(GANInference):
"""Adversarially Learned Inference (Dumoulin et al., 2016) or
Copy link
Member

Choose a reason for hiding this comment

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

Both were published at ICLR 2017, so you can update the citation with ... et al., 2017.

>>> with tf.variable_scope("Gen"):
>>> xf = gen_data(z_ph)
>>> zf = gen_latent(x_ph)
>>> inference = ed.ALI({xf: x_data, zf: z_samples}, discriminator)
Copy link
Member

Choose a reason for hiding this comment

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

To match the interface of other inference methods, what about

ed.ALI(latent_vars, data, discriminative_network)  # signature
ed.ALI({zf: qz}, {xf: x_data}, discriminator)  # example

Here the model's noise zf is binded to the inference network output qz, and the model's generated output xf is binded to data x_data.

@dustinvtran
Copy link
Member

@AlexLewandowski Great work on the updates. Is this waiting on anything? Happy to merge.

@AlexLewandowski
Copy link
Contributor Author

Yeah, you can merge. I'm working on a project so if I have any other ideas, I'll push them this way.

Copy link
Member

@dustinvtran dustinvtran left a comment

Choose a reason for hiding this comment

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

Minor comments below. From the Travis error, it looks like you need to resolve some PEP 8 conflicts too. Thanks again!

>>> with tf.variable_scope("Gen"):
>>> xf = gen_data(z_ph)
>>> zf = gen_latent(x_ph)
>>> inference = ed.BiGANInference({latent_vars: qz}, {xf: x_data}, discriminator)
Copy link
Member

@dustinvtran dustinvtran Apr 14, 2017

Choose a reason for hiding this comment

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

Should this line be {z_ph: zf} and {xf: x_ph}?


def build_loss_and_gradients(self, var_list):

x_true = list(six.itervalues(self.data))[0]
Copy link
Member

Choose a reason for hiding this comment

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

With a dictionary, self.data doesn't guarantee the first key-value pair is x and the second is z. I think you can keep the self.latent_vars / self.data attributes stored separately, doing something like this for __init__:

    if not callable(discriminator):
      raise TypeError("discriminator must be a callable function.")

    self.discriminator = discriminator
    # call grandparent's method; avoid parent (GANInference)
    super(GANInference, self).__init__(latent_vars, data)

In addition, for consistency with other inferences, the zs should be ordered as z_true: z_fake, i.e., the prior latent variable is binded to the output of the inference network. With the above you can do

    z_true = list(six.iterkeys(self.latent_vars))[0]
    z_fake = list(six.itervalues(self.latent_vars))[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's my mistake, I didn't realize that the order was different. I made the changes, hopefully this is more consistent.

@dustinvtran dustinvtran merged commit 270d399 into blei-lab:feature/ali Apr 15, 2017
dustinvtran pushed a commit that referenced this pull request Apr 15, 2017
* Create ali.py in proper branch

* Added example for ali.py

* Made example/ali.py more inline with example/gan.py

* Mistake in hyperparameter placement following last commit

* Update and rename ali.py to bigan_inference.py

* Update __init__.py

* Update __init__.py

* updated and renamed example/ali.py to example/bigan_example.py

* updated and renamed example/ali.py to example/bigan_example.py

* change bigan_example.py and bigan_inference.py to adhere to PEP8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants