Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于WoBERT+模型无法加载 #9

Open
WENGSYX opened this issue Mar 23, 2021 · 1 comment
Open

关于WoBERT+模型无法加载 #9

WENGSYX opened this issue Mar 23, 2021 · 1 comment

Comments

@WENGSYX
Copy link

WENGSYX commented Mar 23, 2021

config_path = 'WoBERT/bert_config.json'
checkpoint_path = 'WoBERT/bert_model.ckpt'
dict_path = 'WoBERT/vocab.txt'
bert = bert4keras.models.build_transformer_model(
config_path=config_path,
checkpoint_path=checkpoint_path,
with_pool=True,
hierarchical_position=True,
return_keras_model=False,
)
当想加载WoBERT+模型,却会报错Key bert/pooler/dense/kernel not found in checkpoint,能帮帮我吗
Traceback (most recent call last):
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py", line 70, in get_tensor
self, compat.as_bytes(tensor_str))
RuntimeError: Key bert/pooler/dense/kernel not found in checkpoint
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 6, in
return_keras_model=False,
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\bert4keras\models.py", line 2338, in build_transformer_model
transformer.load_weights_from_checkpoint(checkpoint_path)
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\bert4keras\models.py", line 297, in load_weights_from_checkpoint
raise e
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\bert4keras\models.py", line 291, in load_weights_from_checkpoint
values.append(self.load_variable(checkpoint, v))
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\bert4keras\models.py", line 691, in load_variable
variable = super(BERT, self).load_variable(checkpoint, name)
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\bert4keras\models.py", line 262, in load_variable
return tf.train.load_variable(checkpoint, name)
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\tensorflow\python\training\checkpoint_utils.py", line 85, in load_variable
return reader.get_tensor(name)
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py", line 74, in get_tensor
error_translator(e)
File "C:\Users\14301\miniconda3\envs\gluon\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py", line 35, in error_translator
raise errors_impl.NotFoundError(None, None, error_message)
tensorflow.python.framework.errors_impl.NotFoundError: Key bert/pooler/dense/kernel not found in checkpoint
不过当转换为pytorch版时,却能够正常加载使用。

@bojone
Copy link

bojone commented Apr 8, 2021

因为WoBERT没有NSP引入,因而没有pooler那部分的权重。

有两个选择:1、模仿这里直接取出cls用;2、如果是最新版本的bert4keras,可以在build_transformer_model时传入参数ignore_invalid_weights=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants