Compare commits

...

6 Commits

Author SHA1 Message Date
Matthew Honnibal 927dcdafcd Update tok2vec 2020-08-28 18:28:28 +02:00
Matthew Honnibal 047f3ba10c Try to be aware of listeners in begin_training 2020-08-28 16:16:03 +02:00
Matthew Honnibal 1b8d2ed14f Try to fix listener 2020-08-28 16:08:00 +02:00
Matthew Honnibal ef9888c1f7 Merge branch 'develop' of https://github.com/explosion/spaCy into tmp/fix-tagger-begin-train 2020-08-28 15:58:18 +02:00
Matthew Honnibal 472eb28716 Fix 2020-08-28 15:13:48 +02:00
Matthew Honnibal 237cfa2053 Update tagger.begin_training 2020-08-28 15:05:01 +02:00
2 changed files with 25 additions and 3 deletions
+17 -2
View File
@@ -287,9 +287,24 @@ class Tagger(Pipe):
self.add_label(tag)
self.set_output(len(self.labels))
if self.labels:
self.model.initialize(X=doc_sample)
label_sample = [
self.model.ops.alloc2f(len(doc), len(self.labels))
for doc in doc_sample
]
for y in label_sample:
y[:, 0] = 1.0
else:
self.model.initialize()
label_sample = None
if pipeline is not None:
for name, component in pipeline:
if component is self:
break
if hasattr(component, "pipe"):
doc_sample = list(component.pipe(doc_sample, batch_size=8))
else:
doc_sample = [component(doc) for doc in doc_sample]
self.model.initialize(X=doc_sample, Y=label_sample)
if sgd is None:
sgd = self.create_optimizer()
return sgd
+8 -1
View File
@@ -291,8 +291,15 @@ class Tok2VecListener(Model):
def forward(model: Tok2VecListener, inputs, is_train: bool):
"""Supply the outputs from the upstream Tok2Vec component."""
if is_train:
model.verify_inputs(inputs)
return model._outputs, model._backprop
else:
return [doc.tensor for doc in inputs], lambda dX: []
width = model.get_dim("nO")
if model._outputs is None:
outputs = [model.ops.alloc2f(len(doc), width) for doc in inputs]
else:
outputs = model._outputs
model._outputs = None
return outputs, lambda dX: []