Exemple #1
0
    def train(self, data, **kwargs):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline using the provided training data."""

        self.training_data = data

        context = kwargs  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before the training starts: check that all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        # data gets modified internally during the training - hence the copy
        working_data = copy.deepcopy(data)

        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}"
                        "".format(component.name))
            component.prepare_partial_processing(self.pipeline[:i], context)
            updates = component.train(working_data, self.config,
                                      **context)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)
Exemple #2
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline by using the provided training data."""

        self.training_data = copy.deepcopy(data)

        context = {}  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before training the component classes, lets check if all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        for component in self.pipeline:
            logger.info("Starting to train component {}".format(
                component.name))
            updates = component.train(data, self.config, **context)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)
    def train(self, data: TrainingData, **kwargs: Any) -> 'Interpreter':
        """Trains the underlying pipeline using the provided training data."""

        self.training_data = data

        context = kwargs

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before the training starts: check that all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        # data gets modified internally during the training - hence the copy
        working_data = copy.deepcopy(data)

        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}"
                        "".format(component.name))
            component.prepare_partial_processing(self.pipeline[:i], context)
            updates = component.train(working_data, self.config, **context)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)
Exemple #4
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline using the provided training data."""

        self.training_data = data

        context = {}  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before the training starts: check that all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        # data gets modified internally during the training - hence the copy
        working_data = copy.deepcopy(data)

        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}".format(component.name))
            #print('[>>>>>>>DEBUG] Type of component: %s' % type(component))
            #print('[>>>>>>>DEBUG] Type of entity_examples: %s' % type(working_data.entity_examples))
            component.prepare_partial_processing(self.pipeline[:i], context)
            #print('[>>>>>>>DEBUG] Before Train: %s' % working_data.entity_examples[0].get('tokens'))
            updates = component.train(working_data, self.config, **context)
            #print('[>>>>>>>DEBUG] After Train: %s' % working_data.entity_examples[0].get('tokens'))
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)
Exemple #5
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline by using the provided training data."""

        # Before training the component classes, lets check if all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, self.config)

        self.training_data = data

        context = {}  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.pipeline_init()
            if updates:
                context.update(updates)

        init_context = context.copy()

        context["training_data"] = data

        for component in self.pipeline:
            args = components.fill_args(component.train_args(), context,
                                        self.config.as_dict())
            logger.info("Starting to train component {}".format(
                component.name))
            updates = component.train(*args)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline,
                           context=init_context,
                           config=self.config.as_dict())
Exemple #6
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline by using the provided training data."""

        self.training_data = data

        context = {}  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before training the component classes, lets check if all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        working_data = copy.deepcopy(
            data
        )  # data gets modified internally during the training - hence the copy

        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}".format(
                component.name))
            component.prepare_partial_processing(self.pipeline[:i], context)
            updates = component.train(working_data, self.config, **context)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)
Exemple #7
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline by using the provided training data."""

        # Before training the component classes, lets check if all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, self.config)

        self.training_data = data

        context = {}        # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.pipeline_init()
            if updates:
                context.update(updates)

        init_context = context.copy()

        context["training_data"] = data

        for component in self.pipeline:
            args = components.fill_args(component.train_args(), context, self.config.as_dict())
            logger.info("Starting to train component {}".format(component.name))
            updates = component.train(*args)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context=init_context, config=self.config.as_dict())
Exemple #8
0
    def train(self, data):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline by using the provided training data."""

        self.training_data = copy.deepcopy(data)

        context = {}        # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before training the component classes, lets check if all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}".format(component.name))
            component.prepare_partial_processing(self.pipeline[:i], context)
            updates = component.train(data, self.config, **context)
            logger.info("Finished training component.")
            if updates:
                context.update(updates)

        return Interpreter(self.pipeline, context)