mirror of https://github.com/explosion/spaCy.git
Use labels in tagger
This commit is contained in:
parent
ca72608059
commit
99bff78617
|
@ -266,7 +266,7 @@ class Tagger(Pipe):
|
||||||
raise ValueError("nan value when computing loss")
|
raise ValueError("nan value when computing loss")
|
||||||
return float(loss), d_scores
|
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
|
"""Initialize the pipe for training, using a representative set
|
||||||
of data examples.
|
of data examples.
|
||||||
|
|
||||||
|
@ -277,8 +277,10 @@ class Tagger(Pipe):
|
||||||
DOCS: https://nightly.spacy.io/api/tagger#initialize
|
DOCS: https://nightly.spacy.io/api/tagger#initialize
|
||||||
"""
|
"""
|
||||||
self._ensure_examples(get_examples)
|
self._ensure_examples(get_examples)
|
||||||
doc_sample = []
|
if labels is not None:
|
||||||
label_sample = []
|
for tag in labels:
|
||||||
|
self.add_label(tag)
|
||||||
|
else:
|
||||||
tags = set()
|
tags = set()
|
||||||
for example in get_examples():
|
for example in get_examples():
|
||||||
for token in example.y:
|
for token in example.y:
|
||||||
|
@ -286,6 +288,8 @@ class Tagger(Pipe):
|
||||||
tags.add(token.tag_)
|
tags.add(token.tag_)
|
||||||
for tag in sorted(tags):
|
for tag in sorted(tags):
|
||||||
self.add_label(tag)
|
self.add_label(tag)
|
||||||
|
doc_sample = []
|
||||||
|
label_sample = []
|
||||||
for example in islice(get_examples(), 10):
|
for example in islice(get_examples(), 10):
|
||||||
doc_sample.append(example.x)
|
doc_sample.append(example.x)
|
||||||
gold_tags = example.get_aligned("TAG", as_string=True)
|
gold_tags = example.get_aligned("TAG", as_string=True)
|
||||||
|
|
Loading…
Reference in New Issue