IndicoDataSolutions / Passage

A little library for text analysis with RNNs.
MIT License
530 stars 134 forks source link

Save/load trained model #1

Closed kjancsi closed 9 years ago

kjancsi commented 9 years ago

Hi, is there any way to save/load trained models? Thanks.

jyt109 commented 9 years ago

check out pickle. https://docs.python.org/2/library/pickle.html

kjancsi commented 9 years ago

Thanks. I tried pickle'ing the model object in tutorial.py after it has been trained, but that did not work.

Newmu commented 9 years ago

Looking into this, on the same device (cpu or gpu) pickle/joblib should work but almost certainly won't across devices. We are planning an explicit save interface to take care of all the edge cases to make sure this just works.

Slater-Victoroff commented 9 years ago

@kjancsi Just wanted to give a status update from the sidelines. Looks like Alec has figured out what the issue is, and is just working on a couple slightly painful implementation details here.

@Newmu Something this week?

Newmu commented 9 years ago

Load and save functions are now added to passage.utils. Example usage in readme.

Let me know if you have any issues - supports cross device, so you can train on a GPU and predict on a CPU and vice-versa.

kjancsi commented 9 years ago

Thanks for implementing this feature. I've noticed an issue when using OneHot input representation.

Traceback (most recent call last):
  File "....py", line 98, in <module>
    model = load('save_test.pkl') # How to load
  File "/.../Passage/passage/utils.py", line 44, in load
    model['config']['layers'] = [getattr(layers, layer['layer'])(**layer['config']) for layer in model['config']['layers']]
TypeError: __init__() got an unexpected keyword argument 'weights'
Newmu commented 9 years ago

Thanks! Weights is used to set parameters when loading a model and forgot the onehot layer doesn't have any! Quick fix pushed.

kjancsi commented 9 years ago

Thanks, it works now.