-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
train.py
140 lines (109 loc) 路 3.84 KB
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import argparse
from typing import Union
from rasa.cli.arguments.default_arguments import (
add_config_param,
add_stories_param,
add_nlu_data_param,
add_out_param,
add_domain_param,
)
from rasa.constants import DEFAULT_DATA_PATH, DEFAULT_CONFIG_PATH
def set_train_arguments(parser: argparse.ArgumentParser):
add_data_param(parser)
add_config_param(parser)
add_domain_param(parser)
add_out_param(parser, help_text="Directory where your models should be stored.")
add_augmentation_param(parser)
add_debug_plots_param(parser)
add_dump_stories_param(parser)
add_model_name_param(parser)
add_force_param(parser)
def set_train_core_arguments(parser: argparse.ArgumentParser):
add_stories_param(parser)
add_domain_param(parser)
add_core_config_param(parser)
add_out_param(parser, help_text="Directory where your models should be stored.")
add_augmentation_param(parser)
add_debug_plots_param(parser)
add_dump_stories_param(parser)
add_force_param(parser)
add_model_name_param(parser)
compare_arguments = parser.add_argument_group("Comparison Arguments")
add_compare_params(compare_arguments)
def set_train_nlu_arguments(parser: argparse.ArgumentParser):
add_config_param(parser)
add_out_param(parser, help_text="Directory where your models should be stored.")
add_nlu_data_param(parser, help_text="File or folder containing your NLU data.")
add_model_name_param(parser)
def add_force_param(parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]):
parser.add_argument(
"--force",
action="store_true",
help="Force a model training even if the data has not changed.",
)
def add_data_param(parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]):
parser.add_argument(
"--data",
default=[DEFAULT_DATA_PATH],
nargs="+",
help="Paths to the Core and NLU data files.",
)
def add_core_config_param(parser: argparse.ArgumentParser):
parser.add_argument(
"-c",
"--config",
nargs="+",
default=[DEFAULT_CONFIG_PATH],
help="The policy and NLU pipeline configuration of your bot. "
"If multiple configuration files are provided, multiple Rasa Core "
"models are trained to compare policies.",
)
def add_compare_params(
parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]
):
parser.add_argument(
"--percentages",
nargs="*",
type=int,
default=[0, 25, 50, 75],
help="Range of exclusion percentages.",
)
parser.add_argument(
"--runs", type=int, default=3, help="Number of runs for experiments."
)
def add_augmentation_param(
parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]
):
parser.add_argument(
"--augmentation",
type=int,
default=50,
help="How much data augmentation to use during training.",
)
def add_dump_stories_param(
parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]
):
parser.add_argument(
"--dump-stories",
default=False,
action="store_true",
help="If enabled, save flattened stories to a file.",
)
def add_debug_plots_param(
parser: Union[argparse.ArgumentParser, argparse._ActionsContainer]
):
parser.add_argument(
"--debug-plots",
default=False,
action="store_true",
help="If enabled, will create plots showing checkpoints "
"and their connections between story blocks in a "
"file called `story_blocks_connections.html`.",
)
def add_model_name_param(parser: argparse.ArgumentParser):
parser.add_argument(
"--fixed-model-name",
type=str,
help="If set, the name of the model file/directory will be set to the given "
"name.",
)