Use labels in tagger
@@ -266,7 +266,7 @@ class Tagger(Pipe):
raise ValueError("nan value when computing loss")
return float(loss), d_scores
- def initialize(self, get_examples, *, nlp=None):
+ def initialize(self, get_examples, *, nlp=None, labels=None):
"""Initialize the pipe for training, using a representative set
of data examples.
@@ -277,8 +277,10 @@ class Tagger(Pipe):
DOCS: https://nightly.spacy.io/api/tagger#initialize
"""
self._ensure_examples(get_examples)
- doc_sample = []
- label_sample = []
+ if labels is not None:
+ for tag in labels:
+ self.add_label(tag)
+ else:
tags = set()
for example in get_examples():
for token in example.y:
@@ -286,6 +288,8 @@ class Tagger(Pipe):
tags.add(token.tag_)
for tag in sorted(tags):
self.add_label(tag)
+ doc_sample = []
+ label_sample = []
for example in islice(get_examples(), 10):
doc_sample.append(example.x)
gold_tags = example.get_aligned("TAG", as_string=True)
