(bert_model, text_encoder, path)
return model
Load fine-tuned bert model given text encoder and checkpoint path.
Load fine-tuned bert model given text encoder and checkpoint path.
Load fine - tuned bert model given text encoder and checkpoint path .
def load_fine_tuned_model(bert_model, text_encoder, path):
    """Load fine-tuned bert model given text encoder and checkpoint path."""
    bert_text_encoder = BertLikeSentencePieceTextEncoder(text_encoder)

    model = BertForMaskedLM.from_pretrained(bert_model)
    model.bert_text_encoder = bert_text_encoder
    model.bert.embeddings.word_embeddings = nn.Embedding(
        bert_text_encoder.vocab_size, model.bert.embeddings.word_embeddings.weight.shape[1])
    model.config.vocab_size = bert_text_encoder.vocab_size
    model.cls = BertOnlyMLMHead(
        model.config, model.bert.embeddings.word_embeddings.weight)

    model.load_state_dict(torch.load(path))

    return model
def load_fine_tuned_model ( bert_model , text_encoder , path ) : bert_text_encoder = BertLikeSentencePieceTextEncoder ( text_encoder ) model = BertForMaskedLM . from_pretrained ( bert_model ) model . bert_text_encoder = bert_text_encoder model . bert . embeddings . word_embeddings = nn . Embedding ( bert_text_encoder . vocab_size , model . bert . embeddings . word_embeddings . weight . shape [ 1 ] ) model . config . vocab_size = bert_text_encoder . vocab_size model . cls = BertOnlyMLMHead ( model . config , model . bert . embeddings . word_embeddings . weight ) model . load_state_dict ( torch . load ( path ) ) return model