Beispiel #1
0
async def _core_model_for_finetuning(
    model_to_finetune: Text,
    file_importer: TrainingDataImporter,
    finetuning_epoch_fraction: float = 1.0,
) -> Optional[Agent]:
    path_to_archive = model.get_model_for_finetuning(model_to_finetune)
    if not path_to_archive:
        return None

    rasa.shared.utils.cli.print_info(
        f"Loading Core model from {path_to_archive} for finetuning...", )

    with model.unpack_model(path_to_archive) as unpacked:
        new_fingerprint = await model.model_fingerprint(file_importer)
        old_fingerprint = model.fingerprint_from_path(unpacked)
        if not model.can_finetune(old_fingerprint, new_fingerprint, core=True):
            rasa.shared.utils.cli.print_error_and_exit(
                "Core model can not be finetuned.")

        config = await file_importer.get_config()
        agent = Agent.load(
            unpacked,
            new_config=config,
            finetuning_epoch_fraction=finetuning_epoch_fraction,
        )
        # Agent might be empty if no underlying Core model was found.
        if agent.domain is not None and agent.policy_ensemble is not None:
            return agent

        return None
Beispiel #2
0
async def _nlu_model_for_finetuning(
    model_to_finetune: Text,
    file_importer: TrainingDataImporter,
    finetuning_epoch_fraction: float = 1.0,
    called_from_combined_training: bool = False,
) -> Optional[Interpreter]:

    path_to_archive = model.get_model_for_finetuning(model_to_finetune)
    if not path_to_archive:
        return None

    rasa.shared.utils.cli.print_info(
        f"Loading NLU model from {path_to_archive} for finetuning...", )
    with model.unpack_model(path_to_archive) as unpacked:
        _, old_nlu = model.get_model_subdirectories(unpacked)
        new_fingerprint = await model.model_fingerprint(file_importer)
        old_fingerprint = model.fingerprint_from_path(unpacked)
        if not model.can_finetune(
                old_fingerprint,
                new_fingerprint,
                nlu=True,
                core=called_from_combined_training,
        ):
            rasa.shared.utils.cli.print_error_and_exit(
                "NLU model can not be finetuned.")

        config = await file_importer.get_config()
        model_to_finetune = Interpreter.load(
            old_nlu,
            new_config=config,
            finetuning_epoch_fraction=finetuning_epoch_fraction,
        )
        if not model_to_finetune:
            return None
    return model_to_finetune
Beispiel #3
0
async def test_can_finetune_min_version(
    project: Text,
    monkeypatch: MonkeyPatch,
    old_model_version: Text,
    min_compatible_version: Text,
    can_tune: bool,
):
    importer = _project_files(project)

    monkeypatch.setattr(rasa.constants, "MINIMUM_COMPATIBLE_VERSION",
                        min_compatible_version)
    monkeypatch.setattr(rasa, "__version__", old_model_version)
    old_fingerprint = await model_fingerprint(importer)
    new_fingerprint = await model_fingerprint(importer)

    with mock.patch("rasa.model.MINIMUM_COMPATIBLE_VERSION",
                    min_compatible_version):
        assert can_finetune(old_fingerprint, new_fingerprint) == can_tune