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 the activation function is tanh in BertPooler #782

Closed
xinliweiyuan opened this issue Jul 12, 2019 · 2 comments
Closed

Why the activation function is tanh in BertPooler #782

xinliweiyuan opened this issue Jul 12, 2019 · 2 comments

Comments

@xinliweiyuan
Copy link

xinliweiyuan commented Jul 12, 2019

I found the activation function in the BertPooler layer is tanh, but Bert never mentions that it uses the tanh. It says gelu activation function is applied in the paper.

So why there is a tanh here ? Waiting for some explanation. Thanks.

class BertPooler(nn.Module):
    def __init__(self, config):
        super(BertPooler, self).__init__()
        self.dense = nn.Linear(config.hidden_size, config.hidden_size)
        self.activation = nn.Tanh()

    def forward(self, hidden_states):
        # We "pool" the model by simply taking the hidden state corresponding
        # to the first token.
        first_token_tensor = hidden_states[:, 0]
        pooled_output = self.dense(first_token_tensor)
        pooled_output = self.activation(pooled_output)
        return pooled_output
@thomwolf
Copy link
Member

Because that's what Bert's authors do in the official TF code:
https://github.com/google-research/bert/blob/bee6030e31e42a9394ac567da170a89a98d2062f/modeling.py#L231

@tonyduan
Copy link

tonyduan commented Jun 10, 2020

Just wanted to point out for future reference the motivation has been answered by the original BERT authors in [this GitHub issue].

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

3 participants