Closed pdasigi closed 8 years ago
This looks good. It would be even better if there were a test to make sure this will actually train, but feel free to merge without it, once the tests pass, if you want. It's up to you.
Update: Code passes TestMultipleChoiceSimilaritySolver::test_train_does_not_crash
with Keras 1.0.8, but not with 1.1.0. Might be related to this issue: https://github.com/fchollet/keras/issues/2582
Ok, I've looked into the error that you're seeing, and I think I figured out the problem. The issue is that the closure in the Lambda
object has a reference to the solver object, and the solver object has a reference to the Lambda
object through self.model.layers
. So, when you try to copy the config object when saving it to json, you get into an infinite copy loop.
I looked at the keras code, and I don't think there's an easy way to fix this there. This is the code that is ultimately causing the problem, and there's no way around the issue if you want to save the closure correctly. We just have to change our use of Lambda
. Specifically we need to do one of two things:
Lambda
layer in our solvers, because creating closures within solver objects will break the keras config code. Instead, write a simple layer and put it in the layers
module.Lambda
layer, put the function definition outside of a containing class. I was able to fix the problem by doing this. See the changes I made here. You can cherry-pick that commit and add it here, or make similar changes yourself, and it should pass tests.That makes sense. Thanks a lot for looking into it, Matt!
Looks great. Feel free to merge this when you want, after adding the comment I recommended.
If you rebase this against the current master, you'll remove a bunch of (maybe all of) the remaining lint errors.