jessevig/bertviz

show error

westwet opened this issue · 36 comments

when I ran the demo, model_view didn't works for me.

image

Hi @westwet, thanks for reporting that. Which version of BertViz are you using? If it's not the latest version (1.4.0), could you try pip install bertviz==1.4.0 first? Many thanks.

@jessevig Thanks for your reply, I try to install bertviz == 1.4.0,but it still error
image

Hi @westwet, thanks for reporting that. Which version of BertViz are you using? If it's not the latest version (1.4.0), could you try pip install bertviz==1.4.0 first? Many thanks.

still these errors
image
image

Okay, thanks for trying that out, sorry it didn't work. Can I ask: (1) What browser are you using? (Chrome, Firefox, etc.) and (2) How are you running the notebook? Is it vanilla jupyter notebook (e.g. from command line jupyter notebook?

Okay, thanks for trying that out, sorry it didn't work. Can I ask: (1) What browser are you using? (Chrome, Firefox, etc.) and (2) How are you running the notebook? Is it vanilla jupyter notebook (e.g. from command line jupyter notebook?

Thanks for your asking.I use Microsoft Edge to run the notebook.
Yes I use jupyternotebook

I noticed that #93 has the same problem, but every method including show,model_view doesn't work for me

Okay, thanks for getting back. Could you try running this step right before in the notebook (including all characters)?:

%%javascript
require.config({
  paths: {
      d3: '//cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min',
      jquery: '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min',
  }
});

I noticed that #93 has the same problem, but every method including show,model_view doesn't work for me

Yes, they had the same issue though it seemed to resolve with latest BertViz version.

Okay, thanks for getting back. Could you try running this step right before in the notebook (including all characters)?:

%%javascript
require.config({
  paths: {
      d3: '//cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min',
      jquery: '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min',
  }
});

Okay, thanks for your replying, actually I tested this method, it didn't work for me
image
image

Hmm, thanks for checking. Could you try one last thing if you would be so kind? This method below will save an HTML file with the visualization. You should be able to view it in your browser. Please just set the path to one that's appropriate for your system :

from transformers import AutoTokenizer, AutoModel, utils
from bertviz import model_view

utils.logging.set_verbosity_error()  # Suppress standard warnings
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased", output_attentions=True)

inputs = tokenizer.encode("The cat sat on the mat", return_tensors='pt')
outputs = model(inputs)
attention = outputs[-1]  # Output includes attention weights when output_attentions=True
tokens = tokenizer.convert_ids_to_tokens(inputs[0]) 

html_model_view = model_view(attention, tokens, html_action='return')

with open("PATH_TO_YOUR_FILE/model_view.html", 'w') as file:
    file.write(html_model_view.data)

It may not be the ideal solution, but it will very much help with debugging :)

Hmm, thanks for checking. Could you try one last thing if you would be so kind? This method below will save an HTML file with the visualization. You should be able to view it in your browser. Please just set the path to one that's appropriate for your system :

from transformers import AutoTokenizer, AutoModel, utils
from bertviz import model_view

utils.logging.set_verbosity_error()  # Suppress standard warnings
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased", output_attentions=True)

inputs = tokenizer.encode("The cat sat on the mat", return_tensors='pt')
outputs = model(inputs)
attention = outputs[-1]  # Output includes attention weights when output_attentions=True
tokens = tokenizer.convert_ids_to_tokens(inputs[0]) 

html_model_view = model_view(attention, tokens, html_action='return')

with open("PATH_TO_YOUR_FILE/model_view.html", 'w') as file:
    file.write(html_model_view.data)

I am so sorry, I got nothing in my model_view.html. It is whole blank space
image
image

Hmm, thanks for trying that out. Can you render this page?: https://jessevig.com/model_view.html

I ran the same code on my system and put the saved html at that link.

Hmm, thanks for trying that out. Can you render this page?: https://jessevig.com/model_view.html

Amazing!! I can't render your page either

Okay, this is very helpful, thank you! I was able to render it in an Edge emulator:

image

I hate to suggest "clear the cache", but I wonder if this isn't playing nice with the current state of your browser for some reason. One option would be to try it in a different browser like Firefox if that's not too difficult.

I hate to suggest "clear the cache", but I wonder if this isn't playing nice with the current state of your browser for some reason. One option would be to try it in a different browser like Firefox if that's not too difficult.

Thanks for your suggestion,I try to use Google to open jupyter notebook now

I hate to suggest "clear the cache", but I wonder if this isn't playing nice with the current state of your browser for some reason. One option would be to try it in a different browser like Firefox if that's not too difficult.

emmm,I used Google to run my code, but still blank space

Thanks. To clarify: what do you mean by "use Google"? Is this in a different browser, e.g. Chrome?

I hate to suggest "clear the cache", but I wonder if this isn't playing nice with the current state of your browser for some reason. One option would be to try it in a different browser like Firefox if that's not too difficult.

emmm,I used Google to run my code, but still blank space

I wonder if I am missing some dependency packages.

In this new browser, are you able to view https://jessevig.com/model_view.html ?

In this new browser, are you able to view https://jessevig.com/model_view.html ?

No I am not, it is still a blank page.

So both Microsoft Edge and Google Chrome give a blank page? Hmmm. Are you running on Windows?

Yes , my OS is Windows

When I choose head_view, it is shown below.
image

it is shown below

I also use FireFox to render your page, but it is still a blank page.

These two web pages refused my access request.

Okay! This is the root cause then. I'm not sure why this is happening, it may be an issue with your firewall. I googled cloudflare refused access and there seemed to be some relevant results. If you have the exact error, would you mind googling it along with cloudflare and see if it offers any good solutions?

https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js

Thank you very much. I'll find out how to solve this problem, and I'll let you know as soon as I get the relevant conclusion.

Great, thank you!

Great, thank you!

Sorry for late reply, the code worked for me when I changed my WIFI, thank you so much!! You are really kind man :)

Good to know, thanks for getting back! One feature I'd like to add is better error handling so that these kinds of issues are easier to debug.

Good to know, thanks for getting back! One feature I'd like to add is better error handling so that these kinds of issues are easier to debug.

Thank you so much, like the network problems I encountered, many people will encounter them. Error handing function is very helpful and valuable.