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

Success Markers CLI #9824

Merged
merged 20 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Start changing over args to new format
  • Loading branch information
usc-m committed Oct 28, 2021
commit 6a90fc2a353443fcdf00068c06077409b2d13a26
2 changes: 2 additions & 0 deletions rasa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
train,
visualize,
x,
evaluate,
)
from rasa.cli.arguments.default_arguments import add_logging_options
from rasa.cli.utils import parse_last_positional_argument_as_model_path
Expand Down Expand Up @@ -69,6 +70,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
data.add_subparser(subparsers, parents=parent_parsers)
export.add_subparser(subparsers, parents=parent_parsers)
x.add_subparser(subparsers, parents=parent_parsers)
evaluate.add_subparser(subparsers, parents=parent_parsers)

return parser

Expand Down
77 changes: 77 additions & 0 deletions rasa/cli/arguments/evaluate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import argparse
from rasa.cli.arguments.default_arguments import add_endpoint_param


def set_markers_arguments(parser: argparse.ArgumentParser):
"""Specifies arguments for `rasa markers extract`"""
parser.add_argument(
"--by",
choices=["first-n", "sample", "all"],
required=True,
dest="strategy",
help="The strategy used to select trackers for marker extraction",
)

parser.add_subparsers()

parser.add_argument(
"output_filename",
type=argparse.FileType("w"),
help="The filename to write the extracted markers to",
)

stats = parser.add_mutually_exclusive_group()

stats.add_argument(
"--no-stats",
default=True,
action="store_false",
dest="stats",
help="Do not compute summary statistics",
)

stats.add_argument(
"--stats-file",
type=argparse.FileType("w"),
help="Che filename to write out computed summary statistics",
)

first_n_arguments = parser.add_argument_group("Arguments for strategy 'by_first_n'")
set_markers_first_n_arguments(first_n_arguments)

sample_arguments = parser.add_argument_group("Arguments for strategy 'by_sample'")
set_markers_sample_arguments(sample_arguments)

add_endpoint_param(parser)


def set_markers_first_n_arguments(parser: argparse.ArgumentParser):
"""Specifies arguments for `rasa markers by_first_n`"""
parser.add_argument(
"--num-trackers",
type=int,
dest="count",
help="The number of trackers to extract markers from",
)


def set_markers_sample_arguments(parser: argparse.ArgumentParser):
"""Specifies arguments for `rasa markers by_sample"""
parser.add_argument(
"--seed", type=int, help="Seed to use if selecting trackers by 'sample'"
)
parser.add_argument(
"--num-trackers",
type=int,
dest="count",
help="The number of trackers to extract markers from",
)


def set_markers_all_arguments(parser: argparse.ArgumentParser):
pass


def set_evaluate_arguments(parser: argparse.ArgumentParser):
# Two subparsers
pass
53 changes: 0 additions & 53 deletions rasa/cli/arguments/markers.py

This file was deleted.

47 changes: 30 additions & 17 deletions rasa/cli/markers.py → rasa/cli/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ def add_subparser(
subparsers: subparser we are going to attach to
parents: Parent parsers, needed to ensure tree structure in argparse
"""
marker_parser = subparsers.add_parser(
evaluate_parser = subparsers.add_parser(
"evaluate",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Tools for evaluating models.",
)

evaluate_subparsers = evaluate_parser.add_subparsers()

marker_parser = evaluate_subparsers.add_parser(
"marker",
parents=parents,
conflict_handler="resolve",
Expand All @@ -29,26 +39,35 @@ def add_subparser(
markers_arguments.set_markers_arguments(marker_parser)

markers_subparser = marker_parser.add_subparsers()
marker_extract_parser = markers_subparser.add_parser(
"extract",

markers_first_n_subparser = markers_subparser.add_parser(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done with argument i.e. with add_mutually_exclusive_group? Feels a bit weird doing it with subparsers...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check again, I looked into how rasa test does it and it looks like it uses sub-parsers (though I agree it's a bit odd). I think I could do it with add_mutually_exclusive_group and choices though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I had a look, and I'm not sure that's possible easily - add_mutually_exclusive_group lets us force one of the args in the group to be picked, but we have a situation where one option has 2 args that are allowed, one has one arg, and one has none. Those are all dependent on the value of strategy (which we could force with choices), but I'm not sure we can do mutual exclusion another way without the use of sub-parsers here (which I agree looks quite nasty)

"by_first_n",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Extract markers from trackers in a tracker store.",
help="Tests Rasa models using your test NLU data and stories.",
)
markers_arguments.set_markers_extract_arguments(marker_extract_parser)
markers_arguments.set_markers_first_n_arguments(markers_first_n_subparser)

marker_extract_parser.set_defaults(func=_run_extract)
markers_sample_subparser = markers_subparser.add_parser(
"by_sample",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Tests Rasa models using your test NLU data and stories.",
)
markers_arguments.set_markers_sample_arguments(markers_sample_subparser)

marker_stats_parser = markers_subparser.add_parser(
"stats",
markers_all_subparser = markers_subparser.add_parser(
"by_all",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Compute stats from previously extracted markers.",
help="Tests Rasa models using your test NLU data and stories.",
)
markers_arguments.set_markers_stats_arguments(marker_stats_parser)
markers_arguments.set_markers_all_arguments(markers_all_subparser)

marker_stats_parser.set_defaults(func=_run_stats)
marker_parser.set_defaults(func=_run_extract)


def _run_extract(args: argparse.Namespace):
Expand All @@ -65,12 +84,6 @@ def _run_extract(args: argparse.Namespace):
pass


def _run_stats(args: argparse.Namespace):
# markers = ConversationMarkers.from_file(args.input_filename)
# _stats(markers, args.output_filename)
pass


def _stats(markers, out_file: TextIO):
# TODO: Figure out how this is done
pass