Comments (6)
Hey, I was able to load tensorflow checkpoints for both the pytorch-transformers v1.0.0 and the bertviz packaged version by editing modeling_bert.py as follows:
At line 105, change pointer = model
to
if len(name) == 1:
if type(model).__name__ == "BertForSequenceClassification":
pointer = model.classifier
else:
continue
else:
pointer = model
Unfortunately, I got stuck here, see attached image. The "Layer" dialog box has no options in it, and there's no visualization nor error, just ...blank.
EDITED/SOLVED:
I was running the notebook from outside the bertviz directory by adding bertviz to the PYTHONPATH and following instructions from there. I can fix my issue by running the notebook in the directory directly, although I frankly don't know why-
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
print(__location__)
shows the correct path regardless of where the notebook is executing from. Anyway, my issue was resolved. I hope this helps someone.
from bertviz.
Hi,
Thanks for reporting this. A couple of things:
- Did you try "num_labels" instead of "num_label"?
- There are a couple of related issues on pytorch_transformers: huggingface/transformers#676 and huggingface/transformers#580
If you're getting this error in BertForSequenceClassification, and you can't find a solution in the issues above, you might consider opening an issue with pytorch_transformers (https://github.com/huggingface/pytorch-transformers) as they would probably be in a better position to help.
from bertviz.
Thanks for reply.
I had tried both things "num_labels" and "num_label", getting the same error.
I have referred to huggingface/pytorch-transformers#676, but unable to resolve this.
from bertviz.
Thanks for sharing. BTW, the latest version of BertViz allows you to load a model directly using the transformers library, so this shouldn't be an issue going forward.
from bertviz.
@jessevig
I fine-tuned bert for a classification task. (following https://github.com/google-research/bert)
I mean to convert the tensorflow checkpoints to pytorch so that i can load the model into BertForSequenceClassification for visualization.
I used the following script
Initialise a configuration according to your model
config = BertConfig.from_pretrained('bert-base-uncased')
config.num_labels=4
You will need to load a BertForSequenceClassification model
model = BertForSequenceClassification(config)
tf_checkpoint_path = init_checkpoint
Load weights from tf checkpoint
load_tf_weights_in_bert(model, config, tf_checkpoint_path)
pytorch_dump_path = "./pytorch_bert_output"
Save pytorch-model
print("Save PyTorch model to {}".format(pytorch_dump_path))
torch.save(model.state_dict(), pytorch_dump_path)
I am getting the following error
BertForSequenceClassification object has no attribute 'bias'
Please help me out.
Thanks
from bertviz.
Hello, I try to visualize fine-tuned BERT model with BertModel and similar error occurs: "AttributeError: 'BertModel' object has no attribute 'bias"
This error occurs in file: "...Lib\site-packages\transformers\modeling_bert.py" line 104 and you can disable related lines in source codes.
Let me know if any questions.
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?
- cannot import name 'Mapping' from 'collections' HOT 6
- 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 1
- 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.