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
Intgrads subclassed models #362
Conversation
…into intgrad-multiple-inputs merge rebase
# Conflicts: # alibi/explainers/integrated_gradients.py # alibi/explainers/tests/test_integrated_gradients.py
…er/alibi-1 into gipster-intgrads-subclassed-models
Codecov Report
@@ Coverage Diff @@
## master #362 +/- ##
==========================================
+ Coverage 87.72% 87.74% +0.01%
==========================================
Files 56 56
Lines 7217 7390 +173
==========================================
+ Hits 6331 6484 +153
- Misses 886 906 +20
|
…er/alibi-1 into gipster-intgrads-subclassed-models
…er/alibi-1 into gipster-intgrads-subclassed-models
The model consists of BERT + custom_layers + Dense layers for binary classification. |
@loukasilias have you installed alibi from source since this PR was merged ( |
Thanks. Ok now. However, another error arises now.
The input/output to the BERT model is a sequence of tokens with dimensions: [batch_size, sequence_length, vector_dimensionality]=[batch_size, 512,768]. x_test_sample and predictions have size (10,) I am getting the following error:
What is the mistake now? Thank you. |
@loukasilias is it possible to provide a self-contained script of the code that results in this error as we can then debug it more efficiently? I feel like the issue might be that the output of |
Do you want the full code, i.e model + generator? I pass to the model the Should I pass the |
@loukasilias the input to In general, the input to |
It doesn't work.
I also tried with: I am getting the following error:
|
@loukasilias does your What is the dimension of the output of I'm not sure what's going on in the last error, it appears to be some issue with BERT as it can't recognize the Do you have some self-contained code that you can share so we can test this otherwise I'm not sure we're making much progress. |
Model:
Generator:
Train & Evaluate:
Explain:
Error: |
Thanks for this, I'll set some time aside to investigate. Do you have some examples of the data Btw, it looks like the output of the model is 1-dimensional, does it represent a class probability in 2-class classification? In that case you may treat is the same as a regression case and provide |
Yes the model outputs a probability . |
@loukasilias there are two issues, a minor one is that you've configured the BERT model with keyword arguments whereas it should be configured to take list inputs as detailed here. The second bigger issue is that the BERT model is not a layer in it's own right, we need to dig deeper to find the appropriate layer to be explained. This is exactly the same issue as #377. |
Support for tensorflow and keras models with no explicit inputs (subclassed models).
In the present code base, tensor inputs are converted to lists at explain time in order to handle models with multiple inputs. If a model has a single input, the tensor input will be converted to a list with one element.
List input are handled well by models with an explicit input layer (functional and sequential models). When no explicit input layer is present (in subclassed models), the input must be in the format expected by the the first layer.
In order to support subclassed models, in this pull request
_calculate_attributions_list_input
and_calculate_attributions_tensor_input
for list inputs and tensor inputs, respectively.