farizrahman4u / seq2seq

Sequence to Sequence Learning with Keras
GNU General Public License v2.0
3.17k stars 845 forks source link

Added hidden_dim to config so LSTMDecoderCell can save properly #197

Open johntzwei opened 7 years ago

johntzwei commented 7 years ago

Hi,

I wasn't able to save the Seq2Seq model, and I wrote this small bit to try to fix it. I hope this is useful!

Let me know if there is anything else I can do!

ChristopherLu commented 7 years ago

Hi, Can this modification make the load_model() work? For now, I can only use the model.load_weights() method.

johntzwei commented 7 years ago

Yes, its been a while, but I think this should allow for saving and loading with keras.model.load_model(). Is this what you mean?

ChristopherLu commented 7 years ago

@johntzwei Hi, it saves properly, but when I try model = load_model(model_path, custom_objects={'_OptionalInputPlaceHolder': _OptionalInputPlaceHolder, 'LSTMDecoderCell': LSTMDecoderCell, 'RecurrentSequential': RecurrentSequential, 'AttentionDecoderCell': AttentionDecoderCell}), it gives me error messages as follows: File "build/bdist.linux-x86_64/egg/seq2seq/cells.py", line 63, in init AttributeError: 'AttentionDecoderCell' object has no attribute 'output_dim'

Edit: it can use model_load for Seq2Seq() but not successful for AttentionSeq2Seq(). Could you help to modify the corresponding AttentionSeq2Seq files?

dbklim commented 5 years ago

@ChristopherLu hello, you would better add to AttentionDecoderCell of "build/bdist.linux-x86_64/egg/seq2seq/cells.py" method get_config():

def get_config(self):
    config = {
        'hidden_dim' : self.hidden_dim,
        'output_dim' : self.output_dim
    }
    base_config = super(AttentionDecoderCell, self).get_config()
    config.update(base_config)
    return config

It worked for me :)