Natural Language Inference: Fine-Tuning BERT

Hello, Thanks for the nice work!
I want to fine-tune BERT on the unlabeled newspaper text data. Then I will use the fine-tune BERT model with BERT embedding of First, the question is can do this. ? Second, how to fine-tune BERT. I can use this link for fine tuning I don’t understand how to change this part

class BERTClassifier(nn.Block):
    def __init__(self, bert):
        super(BERTClassifier, self).__init__()
        self.encoder = bert.encoder
        self.hidden = bert.hidden
        self.output = nn.Dense(3)

def forward(self, inputs):
    tokens_X, segments_X, valid_lens_x = inputs
    encoded_X = self.encoder(tokens_X, segments_X, valid_lens_x)
    return self.output(self.hidden(encoded_X[:, 0, :]))

How to save the fine-tune Model to use it for bert embedding. ?

For the bert embedding in your provided link, I think you probably can refer to the gluonnlp doc.

For educational purposes (to keep code simple), in D2L we pre-trained BERT for whole-word tokens (not wordpiece tokens) that is available for downloading. You may follow this section’s code to see how to load it. Actually the performance is quite close to original bert on several downstream tasks. So, if you want to use BERT embedding for whole-word tokens, feel free to modify this section’s code to load them and fine-tune it. For saving models, please refer to or the official documentation of your framework.