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

Need Help Regarding TabNetEncoder output and TabNetPretraining #446

Closed
Hazqeel09 opened this issue Dec 18, 2022 · 4 comments
Closed

Need Help Regarding TabNetEncoder output and TabNetPretraining #446

Hazqeel09 opened this issue Dec 18, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Hazqeel09
Copy link

Hye, Optimox. As you answered previously, I can use TabNetEncoder to produce custom sizes of embedding. Upon testing the layer, I realised it produced three outputs, I dont know which one is more important.
image

The paper that I tried to copy also used unsupervised training. TabNetPretraining layer also produced three different outputs. I checked the outputs' meaning on GitHub but I also doesnt know which one is important and how to use that to pass to TabNetEncoder.

The paper that I'm trying to duplicate is here (https://ieeexplore.ieee.org/document/9658729). Basically, the methods that I need to duplicate from the paper are:
image

  • Unsupervised learning using TabNet
  • Encode the value using TabNet
  • Get feature importance

I already managed the transformer part, but I'm still stuck at the TabNet part.

Lastly, what is the difference between forward and forward mask?

Thank you.

@Optimox
Copy link
Collaborator

Optimox commented Dec 19, 2022

Hello,

The encoder outputs two things, the different steps outputs and an auxiliary value useful for computting the loss

return steps_output, M_loss

You can see here how the auxiliary value for the loss is used :

loss = loss - self.lambda_sparse * M_loss

The forward_mask simply outputs the mask instead of the loss auxiliary so that it can be used for inference to get feature importances: see the explain method here

def explain(self, X, normalize=False):

What you can do:

  • simply use TabNetPretrainer to pretrain your encoder, use the standard library
  • extract the tabnet encoder weight by accessing the encoder clf.network.tabnet.encoder, create the encoder inside your pipeline and load the weights.
  • access the feature importance the same way the library do (you'll have to go inside the source code and copy paste some parts)
  • train your end to end pipeline with your BERT model

@Optimox Optimox added the help wanted Extra attention is needed label Dec 19, 2022
@Hazqeel09
Copy link
Author

image

I think I managed to get the model to learn and provide output but can you help to check if I'm doing it correctly?
Thank you

@Optimox
Copy link
Collaborator

Optimox commented Jan 11, 2023

It does not make sense to load a state dict at each forward step, the first two lines should probably be inside the init method.

I don't think it's a good idea to reshape the output of tabnet's encoder to a 8x8 image. What kind of model is your NetRelu ?

You should probably use flattened representations of both model and concatenate them before passing them to a simple Linear head.

@Hazqeel09
Copy link
Author

I see your point, will move the code to be inside init method.

I reshape the output because the architecture I'm trying to copy reshape tabnet output to 1x8x8 and bert sentence embedding to 12x8x8

image
This is my NetRelu that also imitates the paper

@Optimox Optimox closed this as completed Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants