explosion / thinc

🔮 A refreshing functional take on deep learning, compatible with your favorite libraries
https://thinc.ai
MIT License
2.82k stars 275 forks source link

Documentation of Model.from_disk #751

Open frobnitzem opened 2 years ago

frobnitzem commented 2 years ago

When I tried literally running

Model().from_disk('saved_model.bin')

I as referenced by the documentation, I got an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() missing 2 required positional arguments: 'name' and 'forward'

So, the documentation needs be updated to note what kind of model instance has to be used for reading from disk. Can I use a generic Model("unknown", lambda x: None) or do I need a look-alike model to the one I'm reading?

Zatteliet commented 1 year ago

I'm standing before the same issue. I got the results I wanted (pending error analysis) by loading the model from the same config that I used when training, and calling from_disk on that.

config = Config().from_disk("config.cfg")
config = registry.resolve(config)
model = config["model"].from_disk("model")

So I get the feeling from_disk only reads the trained weights of the model, but not the model architecture? I also hope this can be clarified in the documentation.

honnibal commented 1 month ago

Yes the .from_disk() method only reads binary weights. We don't want to invoke code during deserialisation, so you have to set up the model how you expect it to be on the other side. You can use the registry to help with this.