question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

layer and attention are empty.

See original GitHub issue

I’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)

capture

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gogokrecommented, Feb 10, 2020

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

Thank you very much. As you mentioned, I succeeded using Jupter Notebook.

1reaction
WenTingTsengcommented, Feb 10, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found