Пример #1
0
 def create(model_metadata,  # type: Metadata or annotation config
            config = {},  # type: addtional config
            component_builder=None,  # type: Optional[ComponentBuilder]
            skip_valdation=False  # type: bool
            ):
     # type: (...) -> Interpreter
     """Load stored model and components defined by the provided metadata."""
     context = {}
     if component_builder is None:
         # If no builder is passed, every interpreter creation will result
         # in a new builder. hence, no components are reused.
         component_builder = components.ComponentBuilder()
     pipeline = []
     # Before instantiating the component classes,
     # lets check if all required packages are available
     # if not skip_valdation:
     #     components.validate_requirements(model_metadata.pipeline)
     for component_name in model_metadata.pipeline:
         component = component_builder.load_component(
             component_name, model_metadata.model_meta_path,
             model_metadata, config=config, **context)
         try:
             updates = component.provide_context()
             if updates:
                 context.update(updates)
             pipeline.append(component)
         except components.MissingArgumentError as e:
             raise Exception("Failed to initialize component '{}'. "
                             "{}".format(component.name, e))
     return Interpreter(pipeline, context, model_metadata)
Пример #2
0
    def __init__(self, config, component_builder=None, skip_validation=False):
        # type: (AnnotatorConfig, Optional[ComponentBuilder], bool) -> None
        self.config = config
        self.skip_validation = skip_validation
        self.training_data = None  # type: Optional[TrainingData]
        self.pipeline = []  # type: List[Component]
        if component_builder is None:
            # If no builder is passed, every interpreter creation will result in
            # a new builder. hence, no components are reused.
            component_builder = components.ComponentBuilder()

        # Before instantiating the component classes, lets check if all
        # required packages are available
        # TODO
        # if not self.skip_validation:
        #    components.validate_requirements(config.pipeline)

        # Transform the passed names of the pipeline components into classes
        for component_name in config.pipeline:
            component = component_builder.create_component(component_name, config)
            self.pipeline.append(component)