Beispiel #1
0
    def __init__(
        self,
        config_file: Text,
        domain_path: Optional[Text] = None,
        training_data_paths: Optional[Union[List[Text], Text]] = None,
        project_directory: Optional[Text] = None,
    ):
        self.config = io_utils.read_config_file(config_file)
        if domain_path:
            self._domain_paths = [domain_path]
        else:
            self._domain_paths = []
        self._story_paths = []
        self._e2e_story_paths = []
        self._nlu_paths = []
        self._imports = []
        self._additional_paths = training_data_paths or []
        self._project_directory = project_directory or os.path.dirname(config_file)

        self._init_from_dict(self.config, self._project_directory)

        extra_nlu_files = data.get_data_files(training_data_paths, data.is_nlu_file)
        extra_story_files = data.get_data_files(training_data_paths, data.is_story_file)
        self._story_paths += extra_story_files
        self._nlu_paths += extra_nlu_files

        logger.debug(
            "Selected projects: {}".format("".join([f"\n-{i}" for i in self._imports]))
        )

        mark_as_experimental_feature(feature_name="MultiProjectImporter")
Beispiel #2
0
async def train(
    nlu_config: Union[Text, Dict, RasaNLUModelConfig],
    data: Union[Text, "TrainingDataImporter"],
    path: Optional[Text] = None,
    fixed_model_name: Optional[Text] = None,
    storage: Optional[Text] = None,
    component_builder: Optional[ComponentBuilder] = None,
    training_data_endpoint: Optional[EndpointConfig] = None,
    persist_nlu_training_data: bool = False,
    **kwargs: Any,
) -> Tuple[Trainer, Interpreter, Optional[Text]]:
    """Loads the trainer and the data and runs the training of the model."""
    from rasa.importers.importer import TrainingDataImporter

    if not isinstance(nlu_config, RasaNLUModelConfig):
        nlu_config = config.load(nlu_config)

    # Ensure we are training a model that we can save in the end
    # WARN: there is still a race condition if a model with the same name is
    # trained in another subprocess
    trainer = Trainer(nlu_config, component_builder)
    persistor = create_persistor(storage)
    if training_data_endpoint is not None:
        training_data = await load_data_from_endpoint(
            training_data_endpoint, nlu_config.language
        )
    elif isinstance(data, TrainingDataImporter):
        training_data = await data.get_nlu_data(nlu_config.language)
    else:
        training_data = load_data(data, nlu_config.language)

    training_data.print_stats()
    if training_data.entity_roles_groups_used():
        common_utils.mark_as_experimental_feature("Entity Roles and Groups feature")

    interpreter = trainer.train(training_data, **kwargs)

    if path:
        persisted_path = trainer.persist(
            path, persistor, fixed_model_name, persist_nlu_training_data
        )
    else:
        persisted_path = None

    return trainer, interpreter, persisted_path
    def __init__(
        self,
        config: Dict[Text, Any],
        model_storage: ModelStorage,
        resource: Resource,
        execution_context: ExecutionContext,
        model: Optional[RasaModel] = None,
        featurizer: Optional[TrackerFeaturizer] = None,
        fake_features: Optional[Dict[Text, List[Features]]] = None,
        entity_tag_specs: Optional[List[EntityTagSpec]] = None,
        label_quantiles: Optional[Dict[int, List[float]]] = None,
    ):
        """Declares instance variables with default values."""
        # Set all invalid / non configurable parameters
        config[ENTITY_RECOGNITION] = False
        config[BILOU_FLAG] = False
        config[SIMILARITY_TYPE] = INNER
        config[LOSS_TYPE] = CROSS_ENTROPY
        self.config = config

        super().__init__(
            self.config,
            model_storage,
            resource,
            execution_context,
            model,
            featurizer,
            fake_features,
            entity_tag_specs,
        )

        self.label_quantiles = label_quantiles or {}
        self.label_thresholds = (self._pick_thresholds(self.label_quantiles,
                                                       self.config[TOLERANCE])
                                 if self.label_quantiles else {})
        self.ignore_intent_list = self.config[IGNORE_INTENTS_LIST]

        common.mark_as_experimental_feature("UnexpecTED Intent Policy")