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

How to change the code to work for multi-label classification? #138

Open
allomy opened this issue Nov 15, 2021 · 5 comments
Open

How to change the code to work for multi-label classification? #138

allomy opened this issue Nov 15, 2021 · 5 comments

Comments

@allomy
Copy link

allomy commented Nov 15, 2021

I'm trying to use code2vec for multi-label classification, that one sample belongs to several labels, could you give some suggestions what to do with the model?

Thank you in advance for your help!

@urialon
Copy link
Collaborator

urialon commented Nov 15, 2021

Hi @allomy ,
Thank you for your interest in code2vec!

I think that you can loss here:
https://github.com/tech-srl/code2vec/blob/master/tensorflow_model.py#L228
from the standard cross entropy to sigmoid cross entropy: https://www.tensorflow.org/api_docs/python/tf/compat/v1/nn/sigmoid_cross_entropy_with_logits

But you will also need to change the pipeline to support reading multi-labeled examples. Follow the variable target_index here: https://github.com/tech-srl/code2vec/blob/master/path_context_reader.py
and modify it to get a list of targets for every example.

Best,
Uri

@allomy
Copy link
Author

allomy commented Nov 17, 2021

Hi @urialon , thank you for your quick response. I'll try it soon.

@allomy
Copy link
Author

allomy commented Dec 3, 2021

Hi @urialon , sorry for the delay response that I have tried to modify the code related to target_index, but was lost in the code... Could you give more information about modifying it to get a list of targets for every sample? Thank you in advance for your help.

@urialon
Copy link
Collaborator

urialon commented Dec 6, 2021

Hi @allomy ,
Actually it might be easiest for you to use https://code2seq.org/ .
It predicts a sequence of labels and not multi-label, but it may either be a good approximation, or easier to adapt for multi-label (just change the loss computation, not the entire data reading pipeline).

Best,
Uri

@allomy
Copy link
Author

allomy commented Dec 7, 2021

Thank you @urialon , I will take a look at code2seq.

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