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

运行ner报错 No such layer: Transformer-12-FeedForward-Norm #72

Closed
yaleimeng opened this issue Feb 20, 2020 · 11 comments
Closed

运行ner报错 No such layer: Transformer-12-FeedForward-Norm #72

yaleimeng opened this issue Feb 20, 2020 · 11 comments

Comments

@yaleimeng
Copy link

运行示例task_sequence_labeling_ner_crf.py(数据是按注释下载解压的)时,报错:
, line 114, in
output = model.get_layer(output_layer).output
File "××××/site-packages/keras/engine/network.py", line 365, in get_layer
raise ValueError('No such layer: ' + name)
ValueError: No such layer: Transformer-12-FeedForward-Norm
试了普通roberta模型和追一科技自己的small模型都有这个问题。

@bojone
Copy link
Owner

bojone commented Feb 20, 2020

最新的example需要最新的bert4keras配套,既然你直接在github上看最新的example,应当

pip install git+https://www.github.com/bojone/bert4keras.git

安装最新版的bert4keras

@yaleimeng
Copy link
Author

首先感谢苏神回复!
我卸载了pip直接安装的版本,重新 pip install git-这个,运行示例仍然同样报错。
然后我干脆用这里下载后解压的最新文件替换了site-packages/下面的文件,但还是同样报错。
不明白是哪里的问题。

@bojone
Copy link
Owner

bojone commented Feb 20, 2020

手动观察你安装的bert4keras的目录下的bert.py文件,第135行,看看是不是如github所示:
https://github.com/bojone/bert4keras/blob/master/bert4keras/bert.py#L135

github上的最新版,配合最新的example,我都测试过,不会有这种名字匹配错误的。

@cronousbaby
Copy link

苏神,他可能使用了您那个bert +crf 的ner的例子 但是预训练采用的是albert,如果在这个例子里面切换成albert 除了把model='albert' 还需要做其他的设置吗

@bojone
Copy link
Owner

bojone commented Feb 20, 2020

albert的话要改~

下面这两行

output_layer = 'Transformer-%s-FeedForward-Norm' % bert_layers
output = model.get_layer(output_layer).output

改为

output_layer = 'Transformer-1-FeedForward-Norm'
output = model.get_layer(output_layer).get_output_at(bert_layers - 1)

这属于keras知识啦。

@bojone
Copy link
Owner

bojone commented Feb 20, 2020

我在两个脚本那里注释了一下了。

@cronousbaby
Copy link

谢谢苏神,我测试一下

@cronousbaby
Copy link

苏神 albert 中的bert_layers是不是也得修改下呢 如果使用small_google这个

@bojone
Copy link
Owner

bojone commented Feb 20, 2020

苏神 albert 中的bert_layers是不是也得修改下呢 如果使用small_google这个

那这个你自己根据实际情况修改呀,我哪知道你用的albert有多少层。。。

@yaleimeng
Copy link
Author

yaleimeng commented Feb 20, 2020

感谢大家回复,我的问题确实是模型config跟bert不太一样导致的。
其实在pip git+使用新版本之后问题应该是已经解决,但我只试了这一个特殊的模型,没及时发现。早上想起来应该换一个再试试,果然是正常的。
正常情况下确实不会遇到这个问题。

@ywm-up
Copy link

ywm-up commented Aug 12, 2021

苏神,他可能使用了您那个bert +crf 的ner的例子 但是预训练采用的是albert,如果在这个例子里面切换成albert 除了把model='albert' 还需要做其他的设置吗

我刚也是用错bert版本了,报的一样的错,后来换了支持权重里面的roberta就好了,感谢大佬的提示换bert版本

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

4 participants