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

Question: why is relative positional encoding computed with length M vs. L+M in the paper ? #132

Open
gdoras opened this issue Mar 18, 2021 · 0 comments

Comments

@gdoras
Copy link

gdoras commented Mar 18, 2021

The positional encoding in the code is:

pos_seq = tf.range(klen - 1, -1, -1.0)
inv_freq = 1 / (10000 ** (tf.range(0, d_model, 2.0) / d_model))
pos_emb = positional_embedding(pos_seq, inv_freq)

Then used to build the r_head_k tensor and finally used in the BD term:

BD = tf.einsum('ibnd,jnd->ijbn', rr_head_q, r_head_k)
BD = rel_shift(BD)

In the paper, the left-shift is done on a Lx(M+L) (i.e. [qlen, qlen+klen]) matrix, but here it is on a LxM if I'm not mistaken. The upper right relative positional encoding are thus erroneous, no ?

I understand that this is not a problem as these ones are masked afterwards, but if we were not using the mask, the pos_seq should be computed with klen + qlen, and then truncated after left-shift before adding to term AC ?

Or did I miss something ?

@gdoras gdoras changed the title Question: why is relative positional encoded computed with length M vs. L+M in the paper ? Question: why is relative positional encoding computed with length M vs. L+M in the paper ? Mar 18, 2021
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

1 participant