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

Method create_pipe_from_source

spacy/language.py:729–766  ·  view source on GitHub ↗

Create a pipeline component by copying it from an existing model. source_name (str): Name of the component in the source pipeline. source (Language): The source nlp object to copy from. name (str): Optional alternative name to use in current pipeline. RETURNS (Tuple[

(
        self, source_name: str, source: "Language", *, name: str
    )

Source from the content-addressed store, hash-verified

727 return resolved[factory_name]
728
729 def create_pipe_from_source(
730 self, source_name: str, source: "Language", *, name: str
731 ) -> Tuple[PipeCallable, str]:
732 """Create a pipeline component by copying it from an existing model.
733
734 source_name (str): Name of the component in the source pipeline.
735 source (Language): The source nlp object to copy from.
736 name (str): Optional alternative name to use in current pipeline.
737 RETURNS (Tuple[Callable[[Doc], Doc], str]): The component and its factory name.
738 """
739 # Check source type
740 if not isinstance(source, Language):
741 raise ValueError(Errors.E945.format(name=source_name, source=type(source)))
742 if self.vocab.vectors != source.vocab.vectors:
743 warnings.warn(Warnings.W113.format(name=source_name))
744 if source_name not in source.component_names:
745 raise KeyError(
746 Errors.E944.format(
747 name=source_name,
748 model=f"{source.meta['lang']}_{source.meta['name']}",
749 opts=", ".join(source.component_names),
750 )
751 )
752 pipe = source.get_pipe(source_name)
753 # There is no actual solution here. Either the component has the right
754 # name for the source pipeline or the component has the right name for
755 # the current pipeline. This prioritizes the current pipeline.
756 if hasattr(pipe, "name"):
757 pipe.name = name
758 # Make sure the source config is interpolated so we don't end up with
759 # orphaned variables in our final config
760 source_config = source.config.interpolate()
761 pipe_config = util.copy_config(source_config["components"][source_name])
762 self._pipe_configs[name] = pipe_config
763 if self.vocab.strings != source.vocab.strings:
764 for s in source.vocab.strings:
765 self.vocab.strings.add(s)
766 return pipe, pipe_config["factory"]
767
768 def add_pipe(
769 self,

Callers 1

add_pipeMethod · 0.95

Calls 2

get_pipeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected