Closed hezhefly closed 4 years ago
matchzoo losses do not support sample_weight
.
matchzoo losses do not support
sample_weight
.
是啊,那目前为止是不支持keras2.3.0了,是吧?
这和 keras2.3.0 有什么关系吗?
这和 keras2.3.0 有什么关系吗?
keras升级到2.3.0会报错
same error tensorflow==1.14.0 keras==2.3.0
@hezhefly @abelx Please provide a short snippet of code to reproduce the error, so I can investigate.
@hezhefly May I know which loss function u're using? How can we reproduce the error?
Compile a ranking model using keras 2.3, and you will get this error.
import matchzoo as mz
model = mz.models.DSSM()
model.params["task"] = mz.tasks.Ranking(mz.losses.RankHingeLoss())
model.guess_and_fill_missing_params()
model.build()
model.compile()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-6bbe396c20b1> in <module>
3 model.guess_and_fill_missing_params()
4 model.build()
----> 5 model.compile()
~/.anaconda3/envs/python37/lib/python3.7/site-packages/matchzoo/engine/base_model.py in compile(self)
218 """
219 self._backend.compile(optimizer=self._params['optimizer'],
--> 220 loss=self._params['task'].loss)
221
222 def fit(
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs)
73 if _SYMBOLIC_SCOPE.value:
74 with get_graph().as_default():
---> 75 return func(*args, **kwargs)
76 else:
77 return func(*args, **kwargs)
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs)
227 # loss_weight_2 * output_2_loss_fn(...) +
228 # layer losses.
--> 229 self.total_loss = self._prepare_total_loss(masks)
230
231 # Functions for train, test and predict will
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/engine/training.py in _prepare_total_loss(self, masks)
690
691 output_loss = loss_fn(
--> 692 y_true, y_pred, sample_weight=sample_weight)
693
694 if len(self.outputs) > 1:
TypeError: __call__() got an unexpected keyword argument 'sample_weight'
keras 2.3 forced all the losses to have sample_weight
param: check
https://github.com/keras-team/keras/blob/1cf5218edb23e575a827ca4d849f1d52d21b4bb0/keras/engine/training.py#L692
or this commit
https://github.com/keras-team/keras/commit/910e1247b452f29c0297ec6e3bf52b28b24fefcf
or API changes:
https://github.com/keras-team/keras/releases
Also, from 2.3, keras.backend.tf
also becomes invalid. If you replace the DSSM
in the above with KNRM
, you will get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-1315debcec8a> in <module>
3 model.params["task"] = mz.tasks.Ranking(mz.losses.RankHingeLoss())
4 model.guess_and_fill_missing_params()
----> 5 model.build()
6 model.compile()
~/.anaconda3/envs/python37/lib/python3.7/site-packages/matchzoo/models/knrm.py in build(self)
68 sigma = self._params['exact_sigma']
69 mu = 1.0
---> 70 mm_exp = self._kernel_layer(mu, sigma)(mm)
71 mm_doc_sum = keras.layers.Lambda(
72 lambda x: K.tf.reduce_sum(x, 2))(mm_exp)
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs)
73 if _SYMBOLIC_SCOPE.value:
74 with get_graph().as_default():
---> 75 return func(*args, **kwargs)
76 else:
77 return func(*args, **kwargs)
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs)
487 # Actually call the layer,
488 # collecting output(s), mask(s), and shape(s).
--> 489 output = self.call(inputs, **kwargs)
490 output_mask = self.compute_mask(inputs, previous_mask)
491
~/.anaconda3/envs/python37/lib/python3.7/site-packages/keras/layers/core.py in call(self, inputs)
298
299 def call(self, inputs):
--> 300 return self.activation(inputs)
301
302 def get_config(self):
~/.anaconda3/envs/python37/lib/python3.7/site-packages/matchzoo/models/knrm.py in kernel(x)
91
92 def kernel(x):
---> 93 return K.tf.exp(-0.5 * (x - mu) * (x - mu) / sigma / sigma)
94
95 return keras.layers.Activation(kernel)
AttributeError: module 'keras.backend' has no attribute 'tf'
@matthew-z The same question! AttributeError: module 'keras.backend' has no attribute 'tf' Have you solved it? Thank you, I look forward to your reply.
Please upgrade MatchZoo. The latest version has supported Keras 2.3
On Thu, Oct 24, 2019 at 8:12 PM as15538191859 notifications@github.com wrote:
@matthew-z https://github.com/matthew-z The same question! AttributeError: module 'keras.backend' has no attribute 'tf' Have you solved it? Thank you, I look forward to your reply.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NTMC-Community/MatchZoo/issues/789?email_source=notifications&email_token=ABLZV5ZG2V3QS5BDJII43H3QQGGLTA5CNFSM4IZHGIQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECEZUOA#issuecomment-545888824, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLZV56E5YYOVXZ4OGYGIVDQQGGLTANCNFSM4IZHGIQQ .
First of all, thank you for your reply! Secondly, my MatchZoo's version is 2.1.0
------------------ 原始邮件 ------------------ 发件人: "Z ZH"notifications@github.com; 发送时间: 2019年10月24日(星期四) 晚上8:14 收件人: "NTMC-Community/MatchZoo"MatchZoo@noreply.github.com; 抄送: "红楼小梦"1319466165@qq.com;"Comment"comment@noreply.github.com; 主题: Re: [NTMC-Community/MatchZoo] Tensorflow2.0目前是否全面支持? (#789)
Please upgrade MatchZoo. The latest version has supported Keras 2.3
On Thu, Oct 24, 2019 at 8:12 PM as15538191859 notifications@github.com wrote:
@matthew-z https://github.com/matthew-z The same question! AttributeError: module 'keras.backend' has no attribute 'tf' Have you solved it? Thank you, I look forward to your reply.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NTMC-Community/MatchZoo/issues/789?email_source=notifications&email_token=ABLZV5ZG2V3QS5BDJII43H3QQGGLTA5CNFSM4IZHGIQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECEZUOA#issuecomment-545888824, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLZV56E5YYOVXZ4OGYGIVDQQGGLTANCNFSM4IZHGIQQ .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
current version is 2.2.0
都放弃了,我把matchzoo从我的工程项目中单独抽离出来,打包在docker里运行了
Thank you for your reply. Why can't I upgrade to 2.2.0, and the latest version is 2.1.0. Can you tell me how you operate? Thank you again!
------------------ 原始邮件 ------------------ 发件人: "Z ZH"notifications@github.com; 发送时间: 2019年10月24日(星期四) 晚上8:25 收件人: "NTMC-Community/MatchZoo"MatchZoo@noreply.github.com; 抄送: "你一定会成为你想的那个人"1319466165@qq.com;"Comment"comment@noreply.github.com; 主题: Re: [NTMC-Community/MatchZoo] Tensorflow2.0目前是否全面支持? (#789)
current version is 2.2.0
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Guess we forgot to upload to pypi after 2.2 realse..
Sorry for the inconvenience.. we'll do it now.
font{
line-height: 1.6;
}
ul,ol{
padding-left: 20px;
list-style-position: inside;
}
Thank you for doing it! I wanna to know what you are going to do.
1319466165
1319466165@qq.com
签名由
网易邮箱大师
定制
在2019年10月24日 21:00,Wang Bo<notifications@github.com> 写道:
Sorry for the inconvenience.. I'll do it now.
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.
matchzoo 2.2 is on pypi, please:
pip install matchzoo --upgrade
如题,我目前的运行环境使用是tf2.0版本,keras是为2.3.0。 但无法执行 报错信息如下: