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

House Price Interpretation Tutorial notebook fails #1012

Closed
jimthompson5802 opened this issue Aug 14, 2022 · 2 comments
Closed

House Price Interpretation Tutorial notebook fails #1012

jimthompson5802 opened this issue Aug 14, 2022 · 2 comments
Assignees

Comments

@jimthompson5802
Copy link

🐛 Bug

Running the tutorial Interpret regression models using Boston House Prices Dataset results in an IndexError in the last cell

To Reproduce

Steps to reproduce the behavior:

  1. This colab notebook demonstrates the error.
  2. pip install captum in the notebook
  3. uploaded into the notebook container the pre-trained model.
IndexError                                Traceback (most recent call last)
<ipython-input-19-fd2cf6250225> in <module>()
      1 plt.figure(figsize=(15, 8))
      2 
----> 3 x_axis_data = np.arange(lc_attr_test.shape[1])
      4 
      5 y_axis_lc_attr_test = lc_attr_test.mean(0).detach().numpy()

IndexError: tuple index out of range
SEARCH STACK OVERFLOW
<Figure size 1080x576 with 0 Axes>

Expected behavior

Error free run of the tutorial notebook.

Environment

Google's colab notebook


 - Captum / PyTorch Version (0.5.0 / 1.12.1+cu113):
 - OS (e.g., Linux):
 - How you installed Captum / PyTorch (`conda`, `pip`, source): pip install captum
 - Build command you used (if compiling from source): N/A
 - Python version: 3.7.13
 - CUDA/cuDNN version: N/A
 - GPU models and configuration: colab GPU
 - Any other relevant information:  Error occurs with or without use of GPU

## Additional context

None.
@dbish dbish self-assigned this Aug 19, 2022
@dbish
Copy link
Contributor

dbish commented Aug 19, 2022

Found the issue. There's a line that must have been edited/added at some point that assumes more then one tensor is being returned from lc.attribute, but there's only one (since only one tensor is passed in):

lc_attr_test = lc.attribute(X_test, n_steps=100, attribute_to_layer_input=True)

# shape: test_examples x size_hidden
lc_attr_test = lc_attr_test[0]

The second line here of setting lc_attr_test to the 0th index, then sets it to the tensor index instead of the first tensor, which in turn in the next cell means that "lc_attr_test.shape[1]" throws an exception. Fix is to just take out the reassigning of "lc_attr_test = lc_attr_test[0]". I'll submit a PR fixing this.

@jimthompson5802
Copy link
Author

@dbish Thank you for the guidance.

facebook-github-bot pushed a commit that referenced this issue Aug 23, 2022
Summary:
Described in issue: [1012](#1012)

**Background**
There's a line that must have been edited/added at some point that assumes more then one tensor is being returned from lc.attribute, but there's only one (since only one tensor is passed in):

lc_attr_test = lc.attribute(X_test, n_steps=100, attribute_to_layer_input=True)

# shape: test_examples x size_hidden
lc_attr_test = lc_attr_test[0]
The second line here of setting lc_attr_test to the 0th index, then sets it to the tensor index instead of the first tensor, which in turn in the next cell means that "lc_attr_test.shape[1]" throws an exception.

**Changes**
Fix is to just take out the reassigning of "lc_attr_test = lc_attr_test[0]".

**Testing**
Tested running the notebook before the change (which showed the error described) and after, which produced the plot which was originally shown in the static tutorial page and matches expectations now (see attachment)
<img width="1257" alt="Screen Shot 2022-08-18 at 9 59 25 PM" src="https://user-images.githubusercontent.com/1166295/185547685-8ca05307-19cd-4496-9f9a-7b0cf92f96c2.png">
.

Pull Request resolved: #1014

Reviewed By: vivekmig

Differential Revision: D38927725

Pulled By: dbish

fbshipit-source-id: bda2c0a98638ea1b0f5dc15f8c249985fc890cf7
@dbish dbish closed this as completed Aug 24, 2022
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