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
BertForSequenceClassification.from_pretrained #22
Comments
Are you importing the versions of BertTokenizer/BertForSequenceClassification that are in bertviz.pytorch_transformers_attn? This is a forked version of the transformers library specifically for bertviz. |
Have you found a solution? I have a different error when trying to load a BERT fine tuned classification model to analyze via bertviz:
The error is:
The tokenizer seems to no know what BERT's CLS tokens are... Any ideas? Thank you. |
Hmm, that's an odd one. When I look at the version of BertTokenizer on github, it inherits from tokenization_utils.PretrainedTransformer, which has a cls_token method. Is it possible that somehow the code in either tokenization_bert or tokenization_utils (both in pytorch_transformers_attn library) are out of date? Or somehow being imported from a different path? BTW, I'm working on a change that will decouple bertviz from the transformers library, so this would likely resolve these sorts of issues. I hope to finish it in the next week or two. Thanks. |
Ah yes, I found the problem. Thanks! Everything is beautiful at your end, the paths were incorrect. Thanks again for this tool. |
Thanks for letting me know. BTW, BertViz is now decoupled from transformers for the head and model views, so there shouldn't be a risk of these issues in the future. |
That was fast! Hopefully transformers will stay stable and nothing will break in the future. They tend to keep changing how things work. I now can visualize my tuned classification model, but interpreting it is hard in my case. It seems that all the attention heads generally attend equally to all words, across all layers. The pattern is always the same as this: Is there a simple way to inspect the actual attention scores? If not, I'll probably just modify it so that the numbers appear as well. Again, many many thanks for this. |
Hmm, this is a problem that has happened with other people who loaded fine-tuned models on the previous version of BertViz, e.g., #12 . They were able to resolve this issue but the cause was never clear. I would recommend trying the new version of bertviz in this case. Let me know if any of these solutions work for you. |
Thanks. Ok, I'm trying to take the code in #12 and update it to the most recent bertviz version. Here's what I got so far (notice the UnicodeDecodeError error when saving the tuned model):
Error:
|
Thanks for following up. A couple of thoughts:
|
Hi Rui, I neglected to mention that as part of that change, I removed the functionality to filter the attention, because it was harder to implement when using transformers directly. I do plan to add the functionality back soon, but I don't have an exact timeline unfortunately. |
I see. I found that view quite intuitive (especially when examining longer strings). I'll be on the lookout for it's return. Cheers! |
Hi, I've created a new branch which has the Attention dropdown: https://github.com/jessevig/bertviz/tree/sentence_pair_filter . See head_view_bert.ipynb. Please give it a try! |
Fantastic. This works nicely. |
Good to hear! BTW, it's in master now too. |
我也是这个问题 请问是哪个路径的问题? |
Hi, Thank you for this great work.
can I use this code to plot my model(I am useing BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)
model_type = 'bert'
model_version = 'bert-base-uncased'
do_lower_case = True
model = model #(this my model)
#tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
tokenizer = BertTokenizer.from_pretrained(model_version, do_lower_case=do_lower_case)
sentence_a = sentences[0]
sentence_b = sentences[1]
call_html()
show(model, model_type, tokenizer, sentence_a, sentence_b)
I changed only the model with my model, and the sentences and I got this error??!!please help or share any blog that explain how to plot my model
AttributeError: 'BertTokenizer' object has no attribute 'cls_token'
Thank you in advance
The text was updated successfully, but these errors were encountered: