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

Sin/Cos concatenation in Positional Embeddings #119

Open
zainsarwar865 opened this issue Aug 26, 2020 · 1 comment
Open

Sin/Cos concatenation in Positional Embeddings #119

zainsarwar865 opened this issue Aug 26, 2020 · 1 comment

Comments

@zainsarwar865
Copy link

zainsarwar865 commented Aug 26, 2020

This is how the positional embeddings matrix is constructed in the code:

sinusoid_inp = torch.ger(pos_len,self.inv_freq)
pos_emb = torch.cat([sinusoid_inp.sin(), sinusoid_inp.cos()],dim=-1)

This basically creates a matrix of [sin | cos] whereas the implementation in other papers including the original Attention is all you need had a positional embedding in which the sin and cos alternated between each other along the embedding dimension. Does this have anything to do with the relative positional embedding?

Thanks!

@serkansulun
Copy link

https://github.com/kimiyoung/transformer-xl/issues/8#issuecomment-455187360

For position embedding, the two columns are equivalent, simply because they are consumed by the matrix multiplication which is permutation-invariant.

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