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

A poll on the Embedding class #121

Open
gitfourteen opened this issue Mar 22, 2024 · 3 comments
Open

A poll on the Embedding class #121

gitfourteen opened this issue Mar 22, 2024 · 3 comments

Comments

@gitfourteen
Copy link

gitfourteen commented Mar 22, 2024

    def __init__(self, d_model, vocab):
        super(Embeddings, self).__init__()
        self.lut = nn.Embedding(vocab, d_model)
        self.d_model = d_model

    def forward(self, x):
        return self.lut(x) * math.sqrt(self.d_model)

Do you know why return the look up table by multiplying a constant d_model?

@kuraga
Copy link

kuraga commented Sep 14, 2024

In our model, we share the same weight matrix between the two embedding layers and the pre-softmax linear transformation, similar to (cite). In the embedding layers, we multiply those weights by $\sqrt{d_{\text{model}}}$.

@gitfourteen
Copy link
Author

gitfourteen commented Sep 15, 2024

In our model, we share the same weight matrix between the two embedding layers and the pre-softmax linear transformation, similar to (cite). In the embedding layers, we multiply those weights by

  dmodel

Thanks, does this paper explain why to multiply the constant d_model mathematically?

@kuraga
Copy link

kuraga commented Sep 21, 2024

Not sure but in my DL lectures said "for numerical stability" :)

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