MCPcopy
hub / github.com/explosion/spaCy / select_pipes

Method select_pipes

spacy/language.py:1076–1112  ·  view source on GitHub ↗

Disable one or more pipeline components. If used as a context manager, the pipeline will be restored to the initial state at the end of the block. Otherwise, a DisabledPipes object is returned, that has a `.restore()` method you can use to undo your changes. disable

(
        self,
        *,
        disable: Optional[Union[str, Iterable[str]]] = None,
        enable: Optional[Union[str, Iterable[str]]] = None,
    )

Source from the content-addressed store, hash-verified

1074 return self.select_pipes(disable=names)
1075
1076 def select_pipes(
1077 self,
1078 *,
1079 disable: Optional[Union[str, Iterable[str]]] = None,
1080 enable: Optional[Union[str, Iterable[str]]] = None,
1081 ) -> "DisabledPipes":
1082 """Disable one or more pipeline components. If used as a context
1083 manager, the pipeline will be restored to the initial state at the end
1084 of the block. Otherwise, a DisabledPipes object is returned, that has
1085 a `.restore()` method you can use to undo your changes.
1086
1087 disable (str or iterable): The name(s) of the pipes to disable
1088 enable (str or iterable): The name(s) of the pipes to enable - all others will be disabled
1089
1090 DOCS: https://spacy.io/api/language#select_pipes
1091 """
1092 if enable is None and disable is None:
1093 raise ValueError(Errors.E991)
1094 if isinstance(disable, str):
1095 disable = [disable]
1096 if enable is not None:
1097 if isinstance(enable, str):
1098 enable = [enable]
1099 to_disable = [pipe for pipe in self.pipe_names if pipe not in enable]
1100 # raise an error if the enable and disable keywords are not consistent
1101 if disable is not None and disable != to_disable:
1102 raise ValueError(
1103 Errors.E992.format(
1104 enable=enable, disable=disable, names=self.pipe_names
1105 )
1106 )
1107 disable = to_disable
1108 assert disable is not None
1109 # DisabledPipes will restore the pipes in 'disable' when it's done, so we need to exclude
1110 # those pipes that were already disabled.
1111 disable = [d for d in disable if d not in self._disabled]
1112 return DisabledPipes(self, disable)
1113
1114 def make_doc(self, text: str) -> Doc:
1115 """Turn a text into a Doc object.

Callers 15

disable_pipesMethod · 0.95
convertFunction · 0.80
assemble_cliFunction · 0.80
create_pretraining_modelFunction · 0.80
init_nlpFunction · 0.80
trainFunction · 0.80
test_issue3611Function · 0.80
test_issue4030Function · 0.80
test_enable_pipes_methodFunction · 0.80

Calls 1

DisabledPipesClass · 0.85

Tested by 9

test_issue3611Function · 0.64
test_issue4030Function · 0.64
test_enable_pipes_methodFunction · 0.64
test_select_pipes_errorsFunction · 0.64
test_tok2vec_listenerFunction · 0.64