在创建用于文本分类的二进制分类模型时出错
代码:
model = create_model()
model.compile(optimize=tf.keras.optimizers.Adam(learning_rate=2e-5),
loss=tf.keras.losses.BinaryCrossentropy(),
metrics=[tf.keras.metrics.BinaryAccuracy()])
model.summary()
错误:
TypeError Traceback (most recent call last)
<ipython-input-58-cdba04f466b1> in <module>()
2 model.compile(optimize=tf.keras.optimizers.Adam(learning_rate=2e-5),
3 loss=tf.keras.losses.BinaryCrossentropy(),
----> 4 metrics=[tf.keras.metrics.BinaryAccuracy()])
5 model.summary()
1 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in _validate_compile(self, optimizer, metrics, **kwargs)
2981 invalid_kwargs = set(kwargs) - {'sample_weight_mode'}
2982 if invalid_kwargs:
-> 2983 raise TypeError('Invalid keyword argument(s) in `compile()`: '
2984 f'{(invalid_kwargs,)}. Valid keyword arguments include '
2985 '"cloning", "experimental_run_tf_function", "distribute",'
TypeError: Invalid keyword argument(s) in `compile()`: ({'optimize'},). Valid keyword arguments include "cloning", "experimental_run_tf_function", "distribute", "target_tensors", or "sample_weight_mode".
有人可以看一下吗? 在这里构建用于微调BERT的模型用于文本分类
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够使用示例代码复制上述问题,如下所示
:
固定代码:
typeError明确指南,这是由于错别字所致,请您可以更改
“优化
”为<代码>优化器如下所示,有关更多详细信息,请找到参考。
I was able to replicate above issue using sample code as shown below
Output:
Fixed code:
Above TypeError clearly guide and it is due to typo, please can you change
optimize
tooptimizer
as shown belowFor more details please find the gist for reference.