def create(model_metadata: Metadata,
               component_builder: Optional[ComponentBuilder] = None,
               skip_validation: bool = False) -> '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_validation:
            components.validate_requirements(model_metadata.component_classes)

        for component_name in model_metadata.component_classes:
            component = component_builder.load_component(
                component_name, model_metadata.model_dir, model_metadata,
                **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)
Exemple #2
0
    def load(model_metadata,
             config,
             component_builder=None,
             skip_valdation=False):
        # type: (Metadata, RasaNLUConfig, Optional[ComponentBuilder], bool) -> Interpreter
        """Load a stored model and its components defined by the provided metadata."""
        context = Interpreter.default_output_attributes()
        context.update({"model_dir": model_metadata.model_dir})

        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()

        model_config = config.as_dict()
        model_config.update(model_metadata.metadata)

        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, context, model_config, model_metadata)
            updates = component.pipeline_init()
            if updates:
                context.update(updates)
            pipeline.append(component)

        return Interpreter(pipeline, context, model_config)
Exemple #3
0
    def load(meta, config, component_builder=None, skip_valdation=False):
        # type: (Metadata, RasaNLUConfig, Optional[ComponentBuilder], bool) -> Interpreter
        """Load a stored model and its components defined by the provided metadata."""
        context = {"model_dir": meta.model_dir}
        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()

        model_config = config.as_dict()
        model_config.update(meta.metadata)

        pipeline = []

        # Before instantiating the component classes, lets check if all required packages are available
        if not skip_valdation:
            components.validate_requirements(meta.pipeline)

        for component_name in meta.pipeline:
            component = component_builder.load_component(
                component_name, context, model_config, meta)
            try:
                args = components.fill_args(component.pipeline_init_args(),
                                            context, model_config)
                updates = component.pipeline_init(*args)
                if updates:
                    context.update(updates)
                pipeline.append(component)
            except components.MissingArgumentError as e:
                raise Exception(
                    "Failed to initialize component '{}'. {}".format(
                        component.name, e.message))

        return Interpreter(pipeline, context, model_config)
Exemple #4
0
    def __init__(
        self,
        config,  # type: RasaNLUModelConfig
        component_builder=None,  # type: Optional[ComponentBuilder]
        skip_validation=False  # type: bool
    ):
        # type: (...) -> 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
        if not self.skip_validation:
            components.validate_requirements(config.component_names)

        # Transform the passed names of the pipeline components into classes
        for component_name in config.component_names:
            component = component_builder.create_component(
                component_name, config)
            self.pipeline.append(component)
Exemple #5
0
 def get(self, update, use_cache=True):
     interpreter = self.interpreters.get(update.id)
     if interpreter and use_cache:
         return interpreter
     persistor = BothubPersistor(update)
     model_directory = mkdtemp()
     persistor.retrieve(str(update.repository.uuid), str(update.id),
                        model_directory)
     self.interpreters[update.id] = BothubInterpreter.load(
         model_directory, components.ComponentBuilder(use_cache=False))
     return self.get(update)
Exemple #6
0
    def __init__(
        self,
        config,
        component_builder=None,
    ):
        # type: (RasaNLUConfig, Optional[ComponentBuilder], bool) -> None

        self.config = config
        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()

        # 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)
    def __init__(self,
                 cfg: RasaNLUModelConfig,
                 component_builder: Optional[ComponentBuilder] = None,
                 skip_validation: bool = False):

        self.config = cfg
        self.skip_validation = skip_validation
        self.training_data = None
        # type: Optional[TrainingData]

        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
        if not self.skip_validation:
            components.validate_requirements(cfg.component_names)

        # build pipeline
        self.pipeline = self._build_pipeline(cfg, component_builder)
Exemple #8
0
 def create(cls,
            model_metadata,
            component_builder=None,
            skip_validation=False):
     context = {}
     if component_builder is None:
         component_builder = components.ComponentBuilder()
     pipeline = []
     if not skip_validation:
         components.validate_requirements(model_metadata.component_classes)
     for component_name in model_metadata.component_classes:
         component = component_builder.load_component(
             component_name, model_metadata.model_dir, model_metadata,
             **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 cls(pipeline, context, model_metadata)