mirror of https://github.com/explosion/spaCy.git
Add Pipe.hide_labels to omit labels from pipeline meta (#10175)
This commit is contained in:
parent
6f551043e4
commit
0668a449ba
|
@ -354,12 +354,15 @@ class Language:
|
||||||
@property
|
@property
|
||||||
def pipe_labels(self) -> Dict[str, List[str]]:
|
def pipe_labels(self) -> Dict[str, List[str]]:
|
||||||
"""Get the labels set by the pipeline components, if available (if
|
"""Get the labels set by the pipeline components, if available (if
|
||||||
the component exposes a labels property).
|
the component exposes a labels property and the labels are not
|
||||||
|
hidden).
|
||||||
|
|
||||||
RETURNS (Dict[str, List[str]]): Labels keyed by component name.
|
RETURNS (Dict[str, List[str]]): Labels keyed by component name.
|
||||||
"""
|
"""
|
||||||
labels = {}
|
labels = {}
|
||||||
for name, pipe in self._components:
|
for name, pipe in self._components:
|
||||||
|
if hasattr(pipe, "hide_labels") and pipe.hide_labels is True:
|
||||||
|
continue
|
||||||
if hasattr(pipe, "labels"):
|
if hasattr(pipe, "labels"):
|
||||||
labels[name] = list(pipe.labels)
|
labels[name] = list(pipe.labels)
|
||||||
return SimpleFrozenDict(labels)
|
return SimpleFrozenDict(labels)
|
||||||
|
|
|
@ -26,6 +26,8 @@ class Pipe:
|
||||||
@property
|
@property
|
||||||
def labels(self) -> Tuple[str, ...]: ...
|
def labels(self) -> Tuple[str, ...]: ...
|
||||||
@property
|
@property
|
||||||
|
def hide_labels(self) -> bool: ...
|
||||||
|
@property
|
||||||
def label_data(self) -> Any: ...
|
def label_data(self) -> Any: ...
|
||||||
def _require_labels(self) -> None: ...
|
def _require_labels(self) -> None: ...
|
||||||
def set_error_handler(
|
def set_error_handler(
|
||||||
|
|
|
@ -102,6 +102,10 @@ cdef class Pipe:
|
||||||
def labels(self) -> Tuple[str, ...]:
|
def labels(self) -> Tuple[str, ...]:
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hide_labels(self) -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def label_data(self):
|
def label_data(self):
|
||||||
"""Optional JSON-serializable data that would be sufficient to recreate
|
"""Optional JSON-serializable data that would be sufficient to recreate
|
||||||
|
|
|
@ -99,6 +99,10 @@ class SentenceRecognizer(Tagger):
|
||||||
# are 0
|
# are 0
|
||||||
return tuple(["I", "S"])
|
return tuple(["I", "S"])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hide_labels(self):
|
||||||
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def label_data(self):
|
def label_data(self):
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -97,3 +97,7 @@ def test_overfitting_IO():
|
||||||
]
|
]
|
||||||
assert_equal(batch_deps_1, batch_deps_2)
|
assert_equal(batch_deps_1, batch_deps_2)
|
||||||
assert_equal(batch_deps_1, no_batch_deps)
|
assert_equal(batch_deps_1, no_batch_deps)
|
||||||
|
|
||||||
|
# test internal pipe labels vs. Language.pipe_labels with hidden labels
|
||||||
|
assert nlp.get_pipe("senter").labels == ("I", "S")
|
||||||
|
assert "senter" not in nlp.pipe_labels
|
||||||
|
|
Loading…
Reference in New Issue