Add set_morphology cfg option for Tagger

This commit is contained in:
Matthew Honnibal 2019-03-08 19:03:17 +01:00
parent 49cf002ac4
commit c91577db02
1 changed files with 15 additions and 6 deletions

View File

@ -357,6 +357,14 @@ class Tagger(Pipe):
self.cfg = OrderedDict(sorted(cfg.items())) self.cfg = OrderedDict(sorted(cfg.items()))
self.cfg.setdefault("cnn_maxout_pieces", 2) self.cfg.setdefault("cnn_maxout_pieces", 2)
@property
def set_morphology(self):
return self.cfg.get("set_morphology", True)
@property.setter
def set_morphology(self, value):
return self.cfg["set_morphology"] = True
@property @property
def labels(self): def labels(self):
return tuple(self.vocab.morphology.tag_names) return tuple(self.vocab.morphology.tag_names)
@ -410,7 +418,8 @@ class Tagger(Pipe):
doc_tag_ids = doc_tag_ids.get() doc_tag_ids = doc_tag_ids.get()
for j, tag_id in enumerate(doc_tag_ids): for j, tag_id in enumerate(doc_tag_ids):
# Don't clobber preset POS tags # Don't clobber preset POS tags
if doc.c[j].tag == 0 and doc.c[j].pos == 0: if doc.c[j].tag == 0:
if doc.c[j].pos == 0 and self.set_morphology:
# Don't clobber preset lemmas # Don't clobber preset lemmas
lemma = doc.c[j].lemma lemma = doc.c[j].lemma
vocab.morphology.assign_tag_id(&doc.c[j], tag_id) vocab.morphology.assign_tag_id(&doc.c[j], tag_id)