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

One question #1

Open
BX-xb opened this issue Dec 23, 2020 · 6 comments
Open

One question #1

BX-xb opened this issue Dec 23, 2020 · 6 comments

Comments

@BX-xb
Copy link

BX-xb commented Dec 23, 2020

Hi, thank you for your code! I want to ask a question,what is the "latent_space_dimensions"? I did not find this variable in the paper.

@gpascualg
Copy link
Owner

Hello,

It's been a while since I did this, so I don't have the details that clear. In the paper they extracted $\theta^1_d$ from the latent space, but they don't define its dimensionality. The parameter latent_space_dimensions control exactly that, the shape of this variable. It's also the dimension of the "embedding", the very last layer before the logits.

See this line here:
https://github.com/gpascualg/CrossGrad/blob/master/crossgrad.py#L21
The output of the latent space is [batch, latent_space_dimensions]

Likwise, it is used again in the domain transformation:
https://github.com/gpascualg/CrossGrad/blob/master/crossgrad.py#L28

I chose to make the domain and label classifiers both work with the same dimensionality via this parameter, so that when concatenating (features = tf.concat((features, latent), axis=-1) in the .ipynb inside label_fn) the final size if [batch, latent_space_dimensions * 2].

Either case, that is was my choice, I don't recall the paper specifically mentioning dimensions. I hope this clears a bit the param.

@BX-xb
Copy link
Author

BX-xb commented Dec 23, 2020 via email

@gpascualg
Copy link
Owner

I'm not using TF 1.x anymore (switched to 2.x), so I don't know the exact steps, but it would be something along the lines of using these outputs here:
https://github.com/gpascualg/CrossGrad/blob/master/crossgrad.py#L75

The variable d1 has the predicted classes according to the domain classifier, while l1 has the predicted classes according to the labels classifier. You can compare either of them with labels and obtain the classification accuracy on that batch, ie, tf.reduce_sum(tf.cast(tf.equal(d1, labels), tf.float32)) / tf.cast(tf.shape(labels)[0], tf.float32)

I don't understand what you mean by the domain number is 2, but the code should be generic enough to admit any/all combinations of input shapes, outputs and number of classes.

@BX-xb
Copy link
Author

BX-xb commented Dec 24, 2020

I am confused of the relationship between d1 and d2 , which is the predicted classes according to the domain classifier, can you explain it a little bit more clearly?

@BX-xb
Copy link
Author

BX-xb commented Dec 24, 2020

'd1': d1,

And when I test the new domain samples, the result of d1 must be wrong, why return d1?

@gpascualg
Copy link
Owner

I'm sorry but it's been too long since I read that paper and implemented the code. If I'm not wrong, which I might be, d1 is the original forward pass with the input data, while d2 is the forward pass with the modified input data taking into account the gradient on d1.

As for the return, I return all the data I deem relevant for inspection. Returning it allows you to manually retrieve the values, summarize them, plot, or whatever you deem necessary. There is no real implication in retuning it.

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

No branches or pull requests

2 participants