pytorch-bert-crf-ner icon indicating copy to clipboard operation
pytorch-bert-crf-ner copied to clipboard

model state_dict key missing 문제

Open hjlee9182 opened this issue 3 years ago • 1 comments

구글 드라이브에 있는 ./experiments/base_model_with_crf/best-epoch-16-step-1500-acc-0.993.bin ./experiments/base_model_with_crf_val/best-epoch-12-step-1000-acc-0.960.bin 파일을 가지고 model load 하여 python inference.py를 실행하였을때

둘다 아래 에러가 발생합니다. 해결방법이 어떻게 될까요??

image

hjlee9182 avatar Aug 17 '22 10:08 hjlee9182

net.py 에서

TorchCRF 라이브러리를 load 하지 마시고,

torchcrf 라이브러리를 install 받으시고 다음의 코드를 수정하시면 정상 작동 합니다.


class KobertCRF(nn.Module):
    """ KoBERT with CRF """
    def __init__(self, config, num_classes, vocab=None) -> None:
        super(KobertCRF, self).__init__()

        if vocab is None:
            self.bert, self.vocab = get_pytorch_kobert_model()
        else:
            self.bert = BertModel(config=BertConfig.from_dict(bert_config))
            self.vocab = vocab

        self.dropout = nn.Dropout(config.dropout)
        self.position_wise_ff = nn.Linear(config.hidden_size, num_classes)
        self.crf = CRF(num_tags=num_classes, batch_first=True)


Hans-digit avatar Aug 26 '22 05:08 Hans-digit