mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Small fixes to as_example (#4957)
* label in span not writable anymore
* Revert "label in span not writable anymore"
This reverts commit ab442338c8
.
* fixing yield - remove redundant list
This commit is contained in:
parent
71b93f33bb
commit
cabd60fa1e
|
@ -534,7 +534,9 @@ class Language(object):
|
|||
if not hasattr(proc, "rehearse"):
|
||||
continue
|
||||
grads = {}
|
||||
proc.rehearse(examples, sgd=get_grads, losses=losses, **config.get(name, {}))
|
||||
proc.rehearse(
|
||||
examples, sgd=get_grads, losses=losses, **config.get(name, {})
|
||||
)
|
||||
for key, (W, dW) in grads.items():
|
||||
sgd(W, dW, key=key)
|
||||
return losses
|
||||
|
@ -590,10 +592,7 @@ class Language(object):
|
|||
kwargs = component_cfg.get(name, {})
|
||||
kwargs.update(cfg)
|
||||
proc.begin_training(
|
||||
get_examples,
|
||||
pipeline=self.pipeline,
|
||||
sgd=self._optimizer,
|
||||
**kwargs
|
||||
get_examples, pipeline=self.pipeline, sgd=self._optimizer, **kwargs
|
||||
)
|
||||
self._link_components()
|
||||
return self._optimizer
|
||||
|
@ -701,7 +700,7 @@ class Language(object):
|
|||
cleanup=False,
|
||||
component_cfg=None,
|
||||
n_process=1,
|
||||
as_example=False
|
||||
as_example=False,
|
||||
):
|
||||
"""Process texts as a stream, and yield `Doc` objects in order.
|
||||
|
||||
|
@ -737,7 +736,7 @@ class Language(object):
|
|||
disable=disable,
|
||||
n_process=n_process,
|
||||
component_cfg=component_cfg,
|
||||
as_example=False # TODO: shouldn't this be as_example=as_example ?
|
||||
as_example=as_example,
|
||||
)
|
||||
for doc, context in zip(docs, contexts):
|
||||
yield (doc, context)
|
||||
|
|
|
@ -108,11 +108,9 @@ class Pipe(object):
|
|||
self.set_annotations(docs, predictions)
|
||||
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
@ -329,11 +327,9 @@ class Tensorizer(Pipe):
|
|||
self.set_annotations(docs, tensors)
|
||||
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
@ -464,11 +460,9 @@ class Tagger(Pipe):
|
|||
self.set_annotations(docs, tag_ids)
|
||||
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
@ -1256,11 +1250,9 @@ class TextCategorizer(Pipe):
|
|||
self.set_annotations(docs, scores, tensors=tensors)
|
||||
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
@ -1616,11 +1608,9 @@ class EntityLinker(Pipe):
|
|||
self.set_annotations(docs, kb_ids, tensors=tensors)
|
||||
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
@ -1834,11 +1824,9 @@ class Sentencizer(Pipe):
|
|||
else:
|
||||
self.set_annotations(docs, predictions)
|
||||
if as_example:
|
||||
annotated_examples = []
|
||||
for ex, doc in zip(examples, docs):
|
||||
ex.doc = doc
|
||||
annotated_examples.append(ex)
|
||||
yield from annotated_examples
|
||||
yield ex
|
||||
else:
|
||||
yield from docs
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user