kermitt2 / delft

a Deep Learning Framework for Text https://delft.readthedocs.io/
Apache License 2.0
388 stars 64 forks source link

Custom model #26

Open miguelwon opened 5 years ago

miguelwon commented 5 years ago

I just found this library which seems really nice! Thanks for make it available. One quick question: is there a simple way to use delft with a custom model? I want to try a keras model and use delft because of the already implemented disk space efficient pipeline and the use of elmo.

kermitt2 commented 5 years ago

Thank you for you interest @miguelwon !

You can implement your own keras model in the files delft/sequenceLabelling/models.py for tagging tasks and delft/textClassification/models.py for text classification respectively, taking advantage of the existing pipeline.

For the Sequence Labelling, a new model is via a class (see the existing ones in models.py), and it should work directly by specifying the parameter architecture when creating a model (or --architecture ARCHITECTURE in the command line). You have to ensure that the input to the model is consistent with the existing input which is generated via Keras DataGenerator.

For text classification, a new model is done via a function as visible with the existing ones. Default parameters of the model has defined in a python dictionary object.

de-code commented 5 years ago

As a library it would really be good to be able to use a custom model without changing the existing code. What do you think about registering a model via name. Or maybe pass a factory in.

In case it's of any use, I hacked my way in: https://github.com/elifesciences/sciencebeam-trainer-delft/pull/13