Skip to content
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

Why is src_len+1 in Transformer demo? #66

Open
Yuanbo2021 opened this issue Apr 7, 2021 · 1 comment
Open

Why is src_len+1 in Transformer demo? #66

Yuanbo2021 opened this issue Apr 7, 2021 · 1 comment

Comments

@Yuanbo2021
Copy link

self.pos_emb = nn.Embedding.from_pretrained(get_sinusoid_encoding_table(src_len+1, d_model),freeze=True)

The position encoding table should be (max_len, d_model), why add 1?

@HC-2016
Copy link

HC-2016 commented Jun 8, 2021

I have the same question about the "src_len + 1"/"tgt_len + 1" and self.pos_emb(torch.LongTensor([[1,2,3,4,0]] / self.pos_emb(torch.LongTensor([[5,1,2,3,4]].

In class Encoder:
self.pos_emb = nn.Embedding.from_pretrained(get_sinusoid_encoding_table(src_len+1, d_model), freeze=True)
enc_outputs = self.src_emb(enc_inputs) + self.pos_emb(torch.LongTensor([[1,2,3,4,0]]))

In class Decoder:
self.pos_emb = nn.Embedding.from_pretrained(get_sinusoid_encoding_table(tgt_len+1, d_model),freeze=True)
dec_outputs = self.tgt_emb(dec_inputs) + self.pos_emb(torch.LongTensor([[5,1,2,3,4]])) # [batch_size, tgt_len, d_model]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants