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

Improving embedding #5

Open
EmmaRenauld opened this issue Jan 14, 2020 · 2 comments
Open

Improving embedding #5

EmmaRenauld opened this issue Jan 14, 2020 · 2 comments

Comments

@EmmaRenauld
Copy link

Hi,

Thanks for the code. It gives me a base for mine.
I just tested the following implementation for the position embedding in custom/layers. It works faster so I offer you my solution. The difference in results due to numerical approx is < e^-12.

    pos_emb = np.zeros((max_seq, embedding_dim))
    for index in range(0, d_emb,2):
        pos_emb[:, index] = np.array([m.sin(pos/10000**(index/embedding_dim))
                                      for pos in range(max_seq)])
        pos_emb[:, index+1] = np.array([m.cos(pos/10000**(index/embedding_dim))
                                       for pos in range(max_seq)])
    return pos_emb
@serkansulun
Copy link

Does this directly replace the sinusoid function?

@serkansulun
Copy link

Looks like the answer is yes, but it doesn't matter much since it's only run one time, before training begins.

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