leuchine / multi-domain-sentiment

Code for the paper Learning Domain-specific Representations for Multi-Domain Sentiment Classification
30 stars 12 forks source link

Only binary classification + word vectors #1

Open SteffenEger opened 6 years ago

SteffenEger commented 6 years ago

Hi,

Thanks for making this available. Two suggestions for better usability

1) I think you should point out in the readme that vectors.gz should be available in the main directory. 2) The code so far only seems to work with binary labels "0" and "1" (that would be good to have in the readme as well). It should be easy to generalize to multi-class classification, right? Where should the necessary changes be in the code?

Thanks!

leuchine commented 6 years ago

Hi Steffen:

Thank you very much for your two suggestions. :) Sorry for the late reply.

I have updated the README to reflect suggestion 1.

For suggestion 2, I do not have a multi-class dataset at hand. I use cross entropy as the loss function (tf.nn.sparse_softmax_cross_entropy_with_logits), so that it should be easy to generalise to multi-class case. I do not come up with specific changes to make. Please let me know if you encounter any problem when using it to multi-class dataset. I will try to solve it with you. Thanks!

Best Regards, Qi

SteffenEger commented 6 years ago

Hi Qi,

thank you.

Yes, multi-class didn't work because it appears to only allow two classes. (I think you can check this by simply renaming some labels to "||| 2" besides "||| 0" and "||| 1" in your data)

Maybe tf.nn.sparse_softmax_cross_entropy_with_logits is only for two classes? Or you declared somewhere that there should be only two classes?

Best, Steffen

leuchine commented 6 years ago

Hi Steffen:

The sparse_softmax_cross_entropy_with_logits can work with multi-class case. I found a problem in my code (I hardcode binary class (i.e. 2) when generating the logits for sparse_softmax_cross_entropy_with_logits).

I add a function "count_labels", which counts number of labels in the dataset dynamically. The problem should be solved. Please try again and let me know if there is any problem. Thanks!

Best Regards, Qi

SteffenEger commented 6 years ago

I assume it works when one sets

c=4 softmax_w = tf.get_variable("softmax_w", [4*config.hidden_size, c]) softmax_b = tf.get_variable("softmax_b", [c])

At least, that's what makes it run. Do you agree? If so, could you mention it in the readme? I think that's what users would like to know.

Another thing: is there an option to run the same model in "baseline" mode, i.e., the domain-agnostic models?

You know such things are really helpful when one wants to use this code (--> your citations) :)

SteffenEger commented 6 years ago

Apologies, I hadn't seen your 2nd reply :)

leuchine commented 6 years ago

Hi Steffen:

Thank you very much for your advice. I have a domain-agnostic version (multi_view.py) with repeated code as the domain-aware version. I don't have the chance to clean it yet. :) Please have a look if it is helpful. Thanks!

Best Regards, Qi

SteffenEger commented 6 years ago

Hi Qi,

appears to work somewhat better now ;) As soon as one changes one variable, it breaks though. It set maxlen to 300 and it broke.

ValueError: Cannot feed value of shape (300, 10) for Tensor 'shared_model_2/inputs:0', which has shape '(100, 10)'

A bit of trial and error brings up a running solution in Config(): num_steps = maxlen # was 100

I'm not sure if that is intended to be. Also, I would guess that as soon as other things are changed, it will break again :smile:

Best, Steffen

leuchine commented 6 years ago

Hi Steffen:

I modified the code from other's code. It is a historical problem. Just set num_steps = maxlen will solve the problem. Sorry for the confusion caused. Thanks!

Best Regards, Qi