layer and attention are empty.
See original GitHub issueI’m using colab but it doesn’t work. Help.
%%javascript require.config({ paths: { d3: ‘//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min’, jquery: ‘//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min’, } });
def` show_head_view(model, tokenizer, sentence_a, sentence_b=None):
inputs = tokenizer.encode_plus(sentence_a, sentence_b, return_tensors='pt',
add_special_tokens=True)
input_ids = inputs['input_ids']
if sentence_b:
token_type_ids = inputs['token_type_ids']
attention = model(input_ids, token_type_ids=token_type_ids)[-1]
sentence_b_start = token_type_ids[0].tolist().index(1)
else:
attention = model(input_ids)[-1]
sentence_b_start = None
input_id_list = input_ids[0].tolist() # Batch index 0
tokens = tokenizer.convert_ids_to_tokens(input_id_list)
head_view(attention, tokens, sentence_b_start)
model_version = ‘bert-base-uncased’ do_lower_case = True
model = BertModel.from_pretrained(model_version, output_attentions=True) tokenizer = BertTokenizer.from_pretrained(model_version, do_lower_case=do_lower_case)
sentence_a = “the cat sat on the mat” sentence_b = “the cat lay on the rug”
show_head_view(model, tokenizer, sentence_a, sentence_b)
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
transformer, linear layer after attention - Cross Validated
The linear layer processes each element in the sequence independently, there is no interaction between them.
Read more >12. Attention Layers - deep learning for molecules & materials
Attention layers are deep learning layers that evoke the idea of attention. You can read more about attention in deep learning in Luong...
Read more >[D] - Why do Attention layers work so well? Don't weights in ...
So an attention layer has a Q, K, and V vector My understanding is the goal is to say for a given query...
Read more >Attention is all you need: understanding with example
A Multi-Head Attention Layer can be considered a stack of parallel ... Now, as we have are clear with the motto, let's jump...
Read more >Adding a Custom Attention Layer to a Recurrent Neural ...
In Keras, it is easy to create a custom layer that implements attention by subclassing the Layer class. The Keras guide lists clear...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much. As you mentioned, I succeeded using Jupter Notebook.
Hi, Did you solve this problem already? I just resolved this If you clone this to your local and use the Jupter Notebook by Anaconda and run this code. It will be fine. Hope that helps you