kpe / bert-for-tf2

A Keras TensorFlow 2.0 implementation of BERT, ALBERT and adapter-BERT.
https://github.com/kpe/bert-for-tf2
MIT License
803 stars 193 forks source link

Implement Pooler layer in BertModelLayer #82

Open mrinaald opened 3 years ago

mrinaald commented 3 years ago

Implement the Pooler layer from the BERT model architecture, which creates a pooled feature vector using the first token from the output sequence. In many of the online blogs and examples, they mention to take the pooled output from BERT directly and add dense layers (or other layers) on this pooled output.

With this change, the pooler layer weights available in the downloaded checkpoint files of various models can also be loaded into the BertModelLayer object.

To get the pooler layer output, we need to initialize the BertModelLayer as follows: bert_params.return_pooler_output = True l_bert = bert.BertModelLayer.from_params(bert_params, name="bert")

Ahmedn1 commented 3 years ago

Would someone merge this branch, please?