From 11977415095b25ffe575d7cb6b1e740b50b335b0 Mon Sep 17 00:00:00 2001 From: hankcs Date: Sun, 1 Dec 2024 19:36:41 -0800 Subject: [PATCH] Fix loading issue of fine-tuned NER models --- hanlp/components/taggers/transformers/transformer_tagger.py | 2 +- hanlp/version.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hanlp/components/taggers/transformers/transformer_tagger.py b/hanlp/components/taggers/transformers/transformer_tagger.py index 188bd66c0..c94301e81 100644 --- a/hanlp/components/taggers/transformers/transformer_tagger.py +++ b/hanlp/components/taggers/transformers/transformer_tagger.py @@ -151,7 +151,7 @@ def build_model(self, training=True, extra_embeddings: Embedding = None, finetun self.config.get('secondary_encoder', None), extra_embeddings=extra_embeddings.module(self.vocabs) if extra_embeddings else None, ) - if finetune: + if finetune and self.model: model_state = model.state_dict() load_state = self.model.state_dict() safe_state = filter_state_dict_safely(model_state, load_state) diff --git a/hanlp/version.py b/hanlp/version.py index 25dd2fef3..59d5dbece 100644 --- a/hanlp/version.py +++ b/hanlp/version.py @@ -2,7 +2,7 @@ # Author: hankcs # Date: 2019-12-28 19:26 -__version__ = '2.1.0-beta.62' +__version__ = '2.1.0-beta.63' """HanLP version""" diff --git a/setup.py b/setup.py index e999ead12..426336f94 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ 'transformers>=4.1.1', 'sentencepiece>=0.1.91', # Essential for tokenization_bert_japanese 'torch>=1.6.0', - 'hanlp-common>=0.0.20', + 'hanlp-common>=0.0.21', 'hanlp-trie>=0.0.4', 'hanlp-downloader', *TOKENIZERS,