Neuron_view Asafaya pretrained model
hinnaweali opened this issue · 9 comments
Hi @hinnaweali , this seems to work, though please check the output. Please let me know if it works for you.
Note that you would need to run it with the exact order of imports shown (there are two versions of BertModel that I'm using here).
from transformers import BertModel, BertTokenizer
model = BertModel.from_pretrained('asafaya/bert-base-arabic', output_attentions=True)
model.save_pretrained('./model_neuron_view_test/')
from bertviz.transformers_neuron_view import BertModel
model = BertModel.from_pretrained('./model_neuron_view_test', output_attentions=True)
tokenizer = BertTokenizer.from_pretrained('asafaya/bert-base-arabic')
from bertviz.neuron_view import show
sentence_a = sentence_b = "هذا اختبار"
show(model, 'bert', tokenizer, sentence_a, sentence_b, display_mode='dark', layer=2, head=0)
Hello Jesse,
I'd want to thank you for your helpful response.
Another issue arises, this time involving javascript visualization.
For example, using the show function with any head value yields no visual results. It is only possible to view a map with a layer value assigned. In addition, Also, the visualization map's drop-down list only allows me to choose a layer/head of 0.
best,
Ali
Hmm, I see @hinnaweali . Could you paste in your code and I can try to run it just as you have it?
It is the same code you sent. I only changed the sentences plus the layer and head values.
from transformers import BertModel, BertTokenizer
model = BertModel.from_pretrained('asafaya/bert-base-arabic', output_attentions=True)
model.save_pretrained('./model_neuron_view_test/')
from bertviz.bertviz.transformers_neuron_view import BertModel
model = BertModel.from_pretrained('./model_neuron_view_test', output_attentions=True)
tokenizer = BertTokenizer.from_pretrained('asafaya/bert-base-arabic')
from bertviz.bertviz.neuron_view import show
sentence_a = "طريقة إستعمال قطرة الانف للإطفال"
sentence_b = " اذا كانت قطر للتنظيف استعمل عند الحاجة قبل الرضعات و قبل النوم"
show(model, 'bert', tokenizer, sentence_a, sentence_b, display_mode='light', layer = 11, head = 6)
Hi @hinnaweali this is what I get:
What browser are you running on? Also, are you using vanilla jupyter notebook?
It seems that I should use Jupyter Lab instead! I ran your code in both Microsoft Edge and Google Chrome.
Thank you very much.
I used to run the script in both browsers using Bert Multilingual cased model and I did not get any visualization problem.
Hello Jesse,
Please accept my apologies for the delayed response.
The issue has been resolved by upgrading the transformer version of the Jupyter notebook from 4.4.2 to 4.9.1, using both Google Chrome and Microsoft Edge.
Regards,
<style> </style>Visualization Type | Browser | Transformer version | Status | Kernel |
---|---|---|---|---|
neuron view | Edge | 4.9.1 | done successfuly | Jupyter Notebook |
head view | Edge | 4.9.1 | done successfuly | Jupyter Notebook |
Model view | Edge | 4.9.1 | done successfuly | Jupyter Notebook |
neuron view | Chrome | 4.9.1 | done successfuly | Jupyter Notebook |
head view | Chrome | 4.9.1 | done successfuly | Jupyter Notebook |
Model view | Chrome | 4.9.1 | done successfuly | Jupyter Notebook |
Great! Thanks for the update.