pytorch / captum

Model interpretability and understanding for PyTorch
https://captum.ai
BSD 3-Clause "New" or "Revised" License
4.92k stars 497 forks source link

IMDB_TorchText_Interpret tutorial uses deprecated pytorch library version #1019

Open antoinecomp opened 2 years ago

antoinecomp commented 2 years ago

I think the PyTorch version used in the IMDB_TorchText_Interpret tutorial is deprecated. Indeed, the tutorial uses a small subset of test data from IMDB dataset using torchtext:

TEXT = torchtext.data.Field(lower=True, tokenize='spacy')

then it uses .pad_token, as well as a method like .vocab.stoi. However all of these disappeared in pytorch 0.9.0. But even when downloading the former I got the following error on Google Colab:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
[<ipython-input-2-2fdfbc0d174c>](https://localhost:8080/#) in <module>
----> 1 import torchtext
      2 TEXT = torchtext.data.Field(lower=True, tokenize='spacy')

3 frames
[/usr/lib/python3.7/ctypes/__init__.py](https://localhost:8080/#) in __init__(self, name, mode, handle, use_errno, use_last_error)
    362 
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:
    366             self._handle = handle

OSError: /usr/local/lib/python3.7/dist-packages/torchtext/_torchtext.so: undefined symbol: _ZNK3c104Type14isSubtypeOfExtESt10shared_ptrIS0_EPSo
NarineK commented 2 years ago

Hi @antoinecomp, thank you for bringing it up. Yes, we need to update the versions. Do you mean pytorch or torchtext version ?

antoinecomp commented 2 years ago

Hi @NarineK ! torchtext sorry !

lkurlandski commented 2 years ago

Yes I'm having difficulty here as well. Can't get this notebook to run on my machine, perhaps due to slightly different versions of torchtext, pytorch, etc. even though I tried to ensure that the setup was done correctly. Would hugely appreciate an update to the notebook and more detailed documentation on the third party software used!

Claus1 commented 1 year ago

captum 0.5.0 spacy 3.4.3 torch 1.13.0+cu117 torchtext 0.14.0

model = torch.load('models/imdb-model-cnn-large.pt')

/home/george/.local/lib/python3.10/site-packages/torch/serialization.py:868: SourceChangeWarning: source code of class 'torch.nn.modules.sparse.Embedding' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/george/.local/lib/python3.10/site-packages/torch/serialization.py:868: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) ...

rbelew commented 1 month ago

two years and still an issue!

captum 0.7.0
torch 2.3.0
torchtext 0.18.0
spacy 3.7.6

i'd like to be able to replicate the results in this tutorial, but can't figure out how to get the vocabulary associated with the pre-trained CNN's embedding?

interpret_sentence() makes critical use of the legacy TEXT.vocab.stoi() and Label.vocab.itos() dropped by torchtext version >= 0.9?