How can I use captum for custom deep learning model that includes structure data and text data?
Recently, I have been focusing on fake news detection. The data includes users characteristics (structure data) and text data. I'm trying to build a hybrid model to detect fake news. More specifically, I use BERT for embedding the text data and then combined with user characteristic data? So, how can I leverage captum for visualizing the feature importance of both structure data and text data? Furthermore, how can I identify the contributions of words in the combined model?
Hi @Dongzhanghit ,
yes it is possible to attribute your model's prediction to both sources of input features. Note that the .attribute() method typically accepts an input specified as a tensor or a tuple of tensors. Hopefully this helps you feed the input your model expects when using Captum's .attribute() methods.
If you only want to quantify which of the two sources have more influence on the attributions, you can aggregate the compute attributions.
If you want to map interpret the attributions computed for your text embedding, you can use Captum features dedicated to make text embedding interpretable, as explained in this tutorial.
Hope this help
@bilalsal hey.. have a question on similar lines. how do you recommend dealing with categorical and continous features part of the model input? For example, if input into the nn model is [cat_feature, continous_feature]. Inside the model, there is an embedding layer that gets the embedding for the cat_feature, concats with the continous feature and thats the final input. Would you recommend separating the embedding and the model, getting the embedding of the categorical feature separately and input to the model in ig.attribute is just the continoous features?
Or is there a way to make it work without doing this separately? I took a look a the configure_interpretable_embedding_layer example here, but it seems to fit if input is only a categorical feature and not a mix
Hi @sid-sundrani,
apologies for my delayed response.
A practical solution is to use Layer Attribution, i.e., attributing your output to an internal layer, instead of going all the way back to the input. if you select the embedding layer that concatenates both types of features, you will get the desired attributions. The attribution values for the parts coming from the categorical attribute will give you a clue about how important this attribute is for the specific prediction you are attributing. You can sum up the values (e.g. using L1 or L2 norms) if you desire to have a single number that quantifies this importance.
Hope this helps, happy holidays from the Captum team!
1