Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let rasa interactive automatically do rasa interactive core when no nlu data #4834

Merged
merged 27 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
20b2494
let train decide what to do with the data files
erohmensing Nov 25, 2019
4fe8a45
move error logic
erohmensing Nov 27, 2019
cf8bf39
don't run interactive on NLU only models
erohmensing Nov 28, 2019
bde1311
join logic
erohmensing Nov 28, 2019
bfd33fe
changelog
erohmensing Nov 28, 2019
f46ac75
review comments
erohmensing Nov 29, 2019
bbdc969
add tests that train is called if no model passed
erohmensing Dec 11, 2019
56ede94
handle no core data
erohmensing Dec 11, 2019
322e716
changelog
erohmensing Dec 11, 2019
b96aab1
improve test
erohmensing Dec 11, 2019
1dfac09
fix type
erohmensing Dec 13, 2019
0847b4c
some review comments
erohmensing Dec 16, 2019
4ca90c6
use fileimporter
erohmensing Dec 16, 2019
35024b5
update changelog
erohmensing Dec 16, 2019
2679790
Merge branch 'master' into interactive-core
erohmensing Dec 16, 2019
131be73
Update 4834.improvement.rst
erohmensing Dec 16, 2019
cb9049c
use get_stories()
erohmensing Dec 17, 2019
a84fd1d
fix changelog
erohmensing Dec 17, 2019
bcfd832
use fileimporter for story visualization
erohmensing Dec 17, 2019
e76a326
Merge branch 'master' into interactive-core
erohmensing Dec 17, 2019
649de67
Merge branch 'master' into interactive-core
erohmensing Dec 17, 2019
2098a0c
some review comments
erohmensing Dec 17, 2019
5f88e56
make fileimporter non-optional for visualization
erohmensing Dec 17, 2019
5e35e0b
fix tests and clean up test_interactive imports
erohmensing Dec 18, 2019
198d5a9
Merge branch 'master' into interactive-core
erohmensing Dec 18, 2019
e1691b4
types for mocked data importer
erohmensing Dec 18, 2019
97cbf53
Merge branch 'master' into interactive-core
erohmensing Dec 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4799.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Running ``rasa interactive`` with no NLU data now works, with the functionality of ``rasa interactive core``.
7 changes: 7 additions & 0 deletions changelog/4834.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Made it explicit that interactive learning does not work with NLU-only models.

Interactive learning no longer trains NLU-only models if no model is provided
and no core data is provided.

Made the ``_story_files`` and ``_nlu_files`` of the ``RasaFileImporter`` class
public. They are now ``story_files`` and ``nlu_files``.
97 changes: 41 additions & 56 deletions rasa/cli/interactive.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import argparse
import os
from typing import List, Text
from typing import List, Optional, Text

from rasa.cli import utils
import rasa.cli.train as train
from rasa.cli.arguments import interactive as arguments
from rasa import data, model
erohmensing marked this conversation as resolved.
Show resolved Hide resolved


# noinspection PyProtectedMember
from rasa.cli.utils import get_validated_path, print_error
from rasa.constants import (
DEFAULT_DATA_PATH,
DEFAULT_MODELS_PATH,
DEFAULT_ENDPOINTS_PATH,
)
from rasa.model import get_latest_model
from rasa.constants import DEFAULT_MODELS_PATH, DEFAULT_ENDPOINTS_PATH
from rasa.importers.rasa import RasaFileImporter


def add_subparser(
Expand All @@ -28,7 +23,7 @@ def add_subparser(
help="Starts an interactive learning session to create new training data for a "
"Rasa model by chatting.",
)
interactive_parser.set_defaults(func=interactive)
interactive_parser.set_defaults(func=interactive, core_only=False)
interactive_parser.add_argument(
"--e2e",
action="store_true",
Expand All @@ -45,20 +40,37 @@ def add_subparser(
"for a Rasa Core model by chatting. Uses the 'RegexInterpreter', i.e. "
"`/<intent>` input format.",
)
interactive_core_parser.set_defaults(func=interactive_core)
interactive_core_parser.set_defaults(func=interactive, core_only=True)

arguments.set_interactive_arguments(interactive_parser)
arguments.set_interactive_core_arguments(interactive_core_parser)


def interactive(args: argparse.Namespace):
def interactive(args: argparse.Namespace) -> None:
_set_not_required_args(args)
file_importer = RasaFileImporter(args.config, args.domain, args.data)
erohmensing marked this conversation as resolved.
Show resolved Hide resolved

if args.model is None:
check_training_data(args)
zipped_model = train.train(args)
story_files = file_importer.story_files
erohmensing marked this conversation as resolved.
Show resolved Hide resolved
if not story_files:
utils.print_error_and_exit(
"Could not run interactive learning without either core data or a model containing core data."
)

zipped_model = train.train_core(args) if args.core_only else train.train(args)
if not zipped_model:
utils.print_error_and_exit(
"Could not train an initial model. Either pass paths "
"to the relevant training files (`--data`, `--config`, `--domain`), "
"or use 'rasa train' to train a model."
)
else:
zipped_model = get_provided_model(args.model)
if not (zipped_model and os.path.exists(zipped_model)):
utils.print_error_and_exit(
f"Interactive learning process cannot be started as no initial model was "
f"found at path '{args.model}'. Use 'rasa train' to train a model."
)

perform_interactive_learning(args, zipped_model)

Expand All @@ -68,57 +80,30 @@ def _set_not_required_args(args: argparse.Namespace) -> None:
args.store_uncompressed = False


def interactive_core(args: argparse.Namespace):
_set_not_required_args(args)

if args.model is None:
zipped_model = train.train_core(args)
else:
zipped_model = get_provided_model(args.model)

perform_interactive_learning(args, zipped_model)


def perform_interactive_learning(args, zipped_model) -> None:
def perform_interactive_learning(args: argparse.Namespace, zipped_model: Text) -> None:
from rasa.core.train import do_interactive_learning

if zipped_model and os.path.exists(zipped_model):
args.model = zipped_model

with model.unpack_model(zipped_model) as model_path:
args.core, args.nlu = model.get_model_subdirectories(model_path)
stories_directory = data.get_core_directory(args.data)
args.model = zipped_model

args.endpoints = get_validated_path(
args.endpoints, "endpoints", DEFAULT_ENDPOINTS_PATH, True
with model.unpack_model(zipped_model) as model_path:
args.core, args.nlu = model.get_model_subdirectories(model_path)
if args.core is None:
utils.print_error_and_exit(
"Can not run interactive learning on an NLU-only model."
)
stories_directory = data.get_core_directory(args.data)
erohmensing marked this conversation as resolved.
Show resolved Hide resolved

do_interactive_learning(args, stories_directory)
else:
print_error(
"Interactive learning process cannot be started as no initial model was "
"found. Use 'rasa train' to train a model."
args.endpoints = utils.get_validated_path(
args.endpoints, "endpoints", DEFAULT_ENDPOINTS_PATH, True
)

do_interactive_learning(args, stories_directory)
erohmensing marked this conversation as resolved.
Show resolved Hide resolved


def get_provided_model(arg_model: Text):
model_path = get_validated_path(arg_model, "model", DEFAULT_MODELS_PATH)
def get_provided_model(arg_model: Text) -> Optional[Text]:
model_path = utils.get_validated_path(arg_model, "model", DEFAULT_MODELS_PATH)
erohmensing marked this conversation as resolved.
Show resolved Hide resolved

if os.path.isdir(model_path):
model_path = get_latest_model(model_path)
model_path = model.get_latest_model(model_path)

return model_path


def check_training_data(args) -> None:
training_files = [
get_validated_path(f, "data", DEFAULT_DATA_PATH, none_is_valid=True)
for f in args.data
]
story_files, nlu_files = data.get_core_nlu_files(training_files)
if not story_files or not nlu_files:
print_error(
"Cannot train initial Rasa model. Please provide NLU and Core data "
"using the '--data' argument."
)
exit(1)
9 changes: 2 additions & 7 deletions rasa/core/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,12 @@ async def do_compare_training(


def do_interactive_learning(
args: argparse.Namespace,
stories: Optional[Text] = None,
additional_arguments: Dict[Text, typing.Any] = None,
args: argparse.Namespace, stories: Optional[Text] = None,
):
from rasa.core.training import interactive

interactive.run_interactive_learning(
stories,
skip_visualization=args.skip_visualization,
server_args=args.__dict__,
additional_arguments=additional_arguments,
stories, skip_visualization=args.skip_visualization, server_args=args.__dict__,
)


Expand Down
Loading