Comments (6)
Just as a note, this happens with Python 3.10 as well. From what I can see, this has to do with urllib3 and requests, which seem to contain the offending code. (Meaning, the imports should be from collections.abc
and not collections
.) Everything does work on Python 3.9. Making sure all dependencies are up-to-date in the BertViz chain should take care of this.
from bertviz.
Hi @jeffnyman and @paulaceccon, thanks for the issue and apologies for the late reply. I can't seem to replicate the error with python 3.10 or 3.11. How did you install BertViz? Thanks!
from bertviz.
How did you install BertViz?
In my case, I'm using Poetry, so I did:
poetry add bertviz
It definitely installs without a problem and I can use it. But when using the BertModel, it looks like requests and urllib3 were referenced specifically as using the older import for collections. So I wasn't sure if this was related to the versions that BertViz was using.
I did try adding both directly:
poetry add urllib3
poetry add requests
But that still seemed to show the issue.
I'll create an entirely new environment and see if I can replicate. I'll include the stack trace as well.
from bertviz.
@jessevig I can definitely recreate on a fully new environment, on either Windows or Mac. Here is the script I'm running on Python 3.10.11 and Python 3.11.4:
from transformers import AutoTokenizer
from bertviz.transformers_neuron_view import BertModel
from bertviz.neuron_view import show
model_checkpoint = "bert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = BertModel.from_pretrained(model_checkpoint)
text = "a crane flew over the serene lake"
show(model, "bert", tokenizer, text, display_mode="light", layer=0, head=8)
Here is the stack trace:
Traceback (most recent call last):
File "E:\learning.Repository\ai-blog\zample.py", line 2, in <module>
from bertviz.transformers_neuron_view import BertModel
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\bertviz\transformers_neuron_view\__init__.py", line 2, in <module>
from .tokenization_bert import BertTokenizer, BasicTokenizer, WordpieceTokenizer
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\bertviz\transformers_neuron_view\tokenization_bert.py", line 25, in <module>
from .tokenization_utils import PreTrainedTokenizer
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\bertviz\transformers_neuron_view\tokenization_utils.py", line 25, in <module>
from .file_utils import cached_path
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\bertviz\transformers_neuron_view\file_utils.py", line 19, in <module>
import boto3
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\boto3\__init__.py", line 16, in <module>
from boto3.session import Session
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\boto3\session.py", line 17, in <module>
import botocore.session
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\session.py", line 26, in <module>
import botocore.configloader
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\configloader.py", line 19, in <module>
from botocore.compat import six
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\exceptions.py", line 15, in <module>
from botocore.vendored.requests.exceptions import ConnectionError
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\__init__.py", line 58, in <module>
from . import utils
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\compat.py", line 7, in <module>
from .packages import chardet
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\packages\__init__.py", line 3, in <module>
from . import urllib3
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\packages\urllib3\__init__.py", line 10, in <module>
from .connectionpool import (
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\packages\urllib3\response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "E:\learning.Repository\ai-blog\.venv\lib\site-packages\botocore\vendored\requests\packages\urllib3\_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (E:\appDev\pyenv\.pyenv\pyenv-win\versions\3.10.11\lib\collections\__init__.py)
In looking at this, I now see it looks to be vendored versions of the dependencies that botocore
is using. This was discussed in 1865 apparently and was said to be handled by 1922. If I'm reading all this correctly.
If you drop down to Python 3.9, everything is fine.
from bertviz.
Thanks so much for the detailed analysis @jeffnyman! I will take a look at this.
from bertviz.
I manually added botocore to be the newest version (1.34.6) and it fixed the problem. The problem is in that botocore brings its own dependencies with it in the "vendored" subdirectory.
from bertviz.
Related Issues (20)
- Is there a simple way to use this code to visualize ViT, DeiT architecture? HOT 1
- How to visualize attention if the sizes of input and output sequence are different? ValueError. HOT 1
- How to use language models such as LLaMA / Alpaca / Vicuna with BertViz? HOT 1
- Will bertviz work for vision transformer?
- Text truncation
- Takes too much time to run the model_view() visualization
- library installed but not found
- Using [MASK] in a sentence.
- neuron view errors
- Selecting multiple tokens at once.
- Visualize EncoderDecoderModel with tied encoder and decoder
- Any plan on upadating the code for LLaMA models? HOT 11
- Is there any way to "pin" the attention view for a single token? HOT 2
- Request for adding the transformers_neuron_view for LLAMA series models HOT 1
- How to visualize the generated tokens?
- Neuron view
- Bug when visualizing T5 models with generate HOT 2
- Issue visualizing layer attention
- Any Alternative for Vision transformers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bertviz.