Sorry if this is more a spacy question than prodigy..
i am trying to add a custom textcat model to the pipeline and save / load the resulting pipeline.
Using the spacy example/train_textcat.py and the original textcat model as a basis, i changed lines 38+ in train_textcat.py from
textcat = nlp.create_pipe('textcat')
nlp.add_pipe(textcat, last=True)
to
textcat = MyTextCategorizer(nlp.vocab)
nlp.add_pipe(textcat, last=True)
with MyTextCategorizer for now being:
class MyTextCategorizer(TextCategorizer):
def __init__(self, vocab, model=True, **cfg):
super(MyTextCategorizer, self).__init__(vocab, model=model, **cfg)
@classmethod
def Model(cls, nr_class=1, width=64, **cfg):
pretrained_dims = cfg.get('pretrained_dims', 0)
print pretrained_dims
with Model.define_operators({'>>': chain, '+': add, '|': concatenate,
'**': clone}):
model = (
SpacyVectors
>> flatten_add_lengths
>> with_getitem(0, Affine(width, pretrained_dims))
>> ParametricAttention(width)
>> Pooling(sum_pool)
>> Residual(ReLu(width, width)) ** 2
>> zero_init(Affine(nr_class, width, drop_factor=0.0))
>> logistic
)
return model
I run the training with the en_core_web_lg as a base model.
The code classifies an example sentence with the newly trained model all right.
However, after saving the pipeline and loading it in again, i get this error:
Saved model to model
Loading from model
Traceback (most recent call last):
File "spacy_textcat/train.py", line 213, in
plac.call(main)
File "/usr/local/lib/python2.7/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "/usr/local/lib/python2.7/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "spacy_textcat/train.py", line 127, in main
nlp2 = spacy.load(output_dir)
File "/usr/local/lib/python2.7/site-packages/spacy/init.py", line 19, in load
return util.load_model(name, **overrides)
File "/usr/local/lib/python2.7/site-packages/spacy/util.py", line 117, in load_model
return load_model_from_path(name, **overrides)
File "/usr/local/lib/python2.7/site-packages/spacy/util.py", line 157, in load_model_from_path
return nlp.from_disk(model_path)
File "/usr/local/lib/python2.7/site-packages/spacy/language.py", line 629, in from_disk
util.from_disk(path, deserializers, exclude)
File "/usr/local/lib/python2.7/site-packages/spacy/util.py", line 520, in from_disk
reader(path / key)
File "/usr/local/lib/python2.7/site-packages/spacy/language.py", line 625, in
deserializers[name] = lambda p, proc=proc: proc.from_disk(p, vocab=False)
File "pipeline.pyx", line 211, in spacy.pipeline.Pipe.from_disk
File "/usr/local/lib/python2.7/site-packages/spacy/util.py", line 520, in from_disk
reader(path / key)
File "pipeline.pyx", line 204, in spacy.pipeline.Pipe.from_disk.load_model
File "/usr/local/lib/python2.7/site-packages/thinc/neural/_classes/model.py", line 351, in from_bytes
dest = getattr(layer, name)
AttributeError: 'FeedForward' object has no attribute 'Q'
Am i doing something wrong ?