NTMC-Community / MatchZoo

Facilitating the design, comparison and sharing of deep text matching models.
Apache License 2.0
3.83k stars 899 forks source link

Bug in save model #726

Closed faneshion closed 5 years ago

faneshion commented 5 years ago

Bug exists when saving the model with the following setting:

model.params['optimizer'] = keras.optimizers.Adam(lr=0.001)

The callback is :

evaluate = mz.callbacks.EvaluateAllMetrics(model, x=test_x, y=test_y, batch_size=len(test_x), model_save_path='./.tmpdir/')
uduse commented 5 years ago

params keys should only be basic data types (string, int), not keras optimizer instances. However, I know how to make this work (by calling keras seriailization helpers). Do you think it's really needed?

wuchen95 commented 5 years ago

params keys should only be basic data types (string, int), not keras optimizer instances. However, I know how to make this work (by calling keras seriailization helpers). Do you think it's really needed?

Hi, I found this when I tried to use specific learning rate to train my model. Or could you give a better way to specify a customized learning rate with the optimizer while using matchzoo?

uduse commented 5 years ago

@presimple If you want a quick solution:

  1. add an additional parameter learning_rate in model.params and modify model.build so it takes that parameter into account
  2. add an additional parameter learning_rate in model.params and add additional logic to read that parameter and compile a loaded model.

A better solution, but takes longer: Matchzoo handles optimizer serialization differently.

Ultimately it's keras's fault. Maybe they will fix that eventually.

uduse commented 5 years ago

@presimple found a much better workaround in #735

uduse commented 5 years ago

I hope things are working well for you now. I’ll go ahead and close this issue, but I’m happy to continue further discussion whenever needed.