备忘录
创建新工程
训练模型
交互学习
使用你的助手
开启服务
开启Action服务
故事可视化
在测试数据集上评估模型
拆分训练测试数据
Markdown和JSON数据转换
开启Rasa X
备忘录
命令行接口提供了易于记忆的常用任务的命令
命令 | 作用 |
rasa init | 使用训练数据样本,执行动作和配置文件创建新的工程 |
rasa train | 使用NLU 数据和故事训练模型,将经过训练的模型保存在 ./models目录下 |
rasa interactive | 开启交互学习会话,并通过聊天收集新的训练数据 |
rasa shell | 加载训练好模型并通过命令行与智能助手交互 |
rasa run | 使用训练好的模型启动Rasa服务。有关详细信息,请参阅 Running the Server文档。 |
rasa run actions | 使用Rasa SDK启动action 服务 |
rasa visualize | 故事可视化 |
rasa test | 使用测试NLU 数据和故事测试训练好的Rasa模型 |
rasa data split nlu | 根据指定的百分比拆分NLU数据 |
rasa data convert nlu | 在不同的格式之间转换NLU训练数据 |
rasa x | 在本地启动rasa x |
rasa -h | 显示所有可用命令 |
创建新工程
该命令可以使用例程的训练数据创建一个完整工程
rasa init
这个命令将创建以下文件:
.
├── __init__.py
├── actions.py
├── config.yml
├── credentials.yml
├── data
│ ├── nlu.md
│ └── stories.md
├── domain.yml
├── endpoints.yml
└── models
└── <timestamp>.tar.gz
rasa init 命令会询问你是否要使用这些数据训练初始模型。如果你回答是 no ,models目录将是空的。
通过该工程的设置,是很容易记住常用命令的。训练模型的命令是 rasa train ,通过命令行与模型交互的命令是rasa shell ,测试模型的命令是rasa test 。
训练模型
主要命令是:
rasa train
这个命令的训练是结合了Rasa NLU和Rasa Core模型的Rasa模型。如果你只想训练NLU或Core模型,可以使用rasa train nlu或rasa train core命令。但是,如果训练数据和配置没有改变,Rasa会自动跳过Core或NLU的训练。
rasa train 命令将把训练好的模型存储在被--out参数指定的目录中。模型的默认名称是
<timestamp>.tar.gz 。如果你想自定义模型名称,可以使用--fixed-model-name指定名称。
在训练过程中可以使用下面的参数:
usage: rasa train [-h] [-v] [-vv] [--quiet] [--data DATA [DATA ...]]
[-c CONFIG] [-d DOMAIN] [--out OUT]
[--augmentation AUGMENTATION] [--debug-plots]
[--dump-stories] [--fixed-model-name FIXED_MODEL_NAME]
[--force]
{core,nlu} ...
positional arguments:
{core,nlu}
core Trains a Rasa Core model using your stories.
nlu Trains a Rasa NLU model using your NLU data.
optional arguments:
-h, --help show this help message and exit
--data DATA [DATA ...]
Paths to the Core and NLU data files. (default:
['data'])
-c CONFIG, --config CONFIG
The policy and NLU pipeline configuration of your bot.
(default: config.yml)
-d DOMAIN, --domain DOMAIN
Domain specification (yml file). (default: domain.yml)
--out OUT Directory where your models should be stored.
(default: models)
--augmentation AUGMENTATION
How much data augmentation to use during training.
(default: 50)
--debug-plots If enabled, will create plots showing checkpoints and
their connections between story blocks in a file
called `story_blocks_connections.html`. (default:
False)
--dump-stories If enabled, save flattened stories to a file.
(default: False)
--fixed-model-name FIXED_MODEL_NAME
If set, the name of the model file/directory will be
set to the given name. (default: None)
--force Force a model training even if the data has not
changed. (default: False)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
注意
在使用rasa train 训练模型时请确保Core和NLU的训练数据都存在 。如果Core和NLU的训练数据仅存在其中一种,命令会根据提供的训练文件自动回退到 rasa train nlu 或rasa train core命令。
交互学习
使用下面命令开启与你的助手的交互式学习会话:
rasa interactive
如果你使用参数--model提供训练模型,交互学习使用你提供的模型启动。否则,在没有使用参数 --data指定目录的情况下,rasa interactive命令将使用data/目录下的数据训练新的Rasa模。训练完初始模型后,会启动交互学习。如果训练数据和配置没有改变将跳过模型训练。
下面列出了 rasa interactive命令的参数:
usage: rasa interactive [-h] [-v] [-vv] [--quiet] [--e2e] [-m MODEL]
[--data DATA [DATA ...]] [--skip-visualization]
[--endpoints ENDPOINTS] [-c CONFIG] [-d DOMAIN]
[--out OUT] [--augmentation AUGMENTATION]
[--debug-plots] [--dump-stories] [--force]
{core} ... [model-as-positional-argument]
positional arguments:
{core}
core Starts an interactive learning session model to create
new training data for a Rasa Core model by chatting.
Uses the 'RegexInterpreter', i.e. `/<intent>` input
format.
model-as-positional-argument
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: None)
optional arguments:
-h, --help show this help message and exit
--e2e Save story files in e2e format. In this format user
messages will be included in the stories. (default:
False)
-m MODEL, --model MODEL
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: None)
--data DATA [DATA ...]
Paths to the Core and NLU data files. (default:
['data'])
--skip-visualization Disable plotting the visualization during interactive
learning. (default: False)
--endpoints ENDPOINTS
Configuration file for the model server and the
connectors as a yml file. (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
Train Arguments:
-c CONFIG, --config CONFIG
The policy and NLU pipeline configuration of your bot.
(default: config.yml)
-d DOMAIN, --domain DOMAIN
Domain specification (yml file). (default: domain.yml)
--out OUT Directory where your models should be stored.
(default: models)
--augmentation AUGMENTATION
How much data augmentation to use during training.
(default: 50)
--debug-plots If enabled, will create plots showing checkpoints and
their connections between story blocks in a file
called `story_blocks_connections.html`. (default:
False)
--dump-stories If enabled, save flattened stories to a file.
(default: False)
--force Force a model training even if the data has not
changed. (default: False)
与助手进行交互
使用下面命令,在命令行上启动与智能助手的聊天会话:
rasa shell
可以使用参数--model指定用户交互的模型。如果在启动会话时你仅指定NLU模型,你可以从命令行输入的文本中获取意图和实体。如果模型包含了Core模型,你不但可以和机器人交互也可以预测机器人下一步的动作。如果模型是Core和NLU的组合模型,但是你想查看你的模型从文本中提取的意图和实体,你可以使用rasa shell nlu 命令。
可以使用下面命令提高调试日志级别:
rasa shell --debug
下面列出了rasa shell命令的所有参数设置:
usage: rasa shell [-h] [-v] [-vv] [--quiet] [-m MODEL] [--log-file LOG_FILE]
[--endpoints ENDPOINTS] [-p PORT] [-t AUTH_TOKEN]
[--cors [CORS [CORS ...]]] [--enable-api]
[--remote-storage REMOTE_STORAGE]
[--ssl-certificate SSL_CERTIFICATE]
[--ssl-keyfile SSL_KEYFILE] [--ssl-password SSL_PASSWORD]
[--credentials CREDENTIALS] [--connector CONNECTOR]
[--jwt-secret JWT_SECRET] [--jwt-method JWT_METHOD]
{nlu} ... [model-as-positional-argument]
positional arguments:
{nlu}
nlu Interprets messages on the command line using your NLU
model.
model-as-positional-argument
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: None)
optional arguments:
-h, --help show this help message and exit
-m MODEL, --model MODEL
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: models)
--log-file LOG_FILE Store logs in specified file. (default: None)
--endpoints ENDPOINTS
Configuration file for the model server and the
connectors as a yml file. (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
Server Settings:
-p PORT, --port PORT Port to run the server at. (default: 5005)
-t AUTH_TOKEN, --auth-token AUTH_TOKEN
Enable token based authentication. Requests need to
provide the token to be accepted. (default: None)
--cors [CORS [CORS ...]]
Enable CORS for the passed origin. Use * to whitelist
all origins. (default: None)
--enable-api Start the web server API in addition to the input
channel. (default: False)
--remote-storage REMOTE_STORAGE
Set the remote location where your Rasa model is
stored, e.g. on AWS. (default: None)
--ssl-certificate SSL_CERTIFICATE
Set the SSL Certificate to create a TLS secured
server. (default: None)
--ssl-keyfile SSL_KEYFILE
Set the SSL Keyfile to create a TLS secured server.
(default: None)
--ssl-password SSL_PASSWORD
If your ssl-keyfile is protected by a password, you
can specify it using this paramer. (default: None)
Channels:
--credentials CREDENTIALS
Authentication credentials for the connector as a yml
file. (default: None)
--connector CONNECTOR
Service to connect to. (default: None)
JWT Authentication:
--jwt-secret JWT_SECRET
Public key for asymmetric JWT methods or shared
secretfor symmetric methods. Please also make sure to
use --jwt-method to select the method of the
signature, otherwise this argument will be ignored.
(default: None)
--jwt-method JWT_METHOD
Method used for the signature of the JWT
authentication payload. (default: HS256)
开启服务
启动运行Rasa 模型的服务器,可以使用下面命令:
rasa run
下面参数可用于Rasa服务配置:
usage: rasa run [-h] [-v] [-vv] [--quiet] [-m MODEL] [--log-file LOG_FILE]
[--endpoints ENDPOINTS] [-p PORT] [-t AUTH_TOKEN]
[--cors [CORS [CORS ...]]] [--enable-api]
[--remote-storage REMOTE_STORAGE]
[--ssl-certificate SSL_CERTIFICATE]
[--ssl-keyfile SSL_KEYFILE] [--ssl-password SSL_PASSWORD]
[--credentials CREDENTIALS] [--connector CONNECTOR]
[--jwt-secret JWT_SECRET] [--jwt-method JWT_METHOD]
{actions} ... [model-as-positional-argument]
positional arguments:
{actions}
actions Runs the action server.
model-as-positional-argument
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: None)
optional arguments:
-h, --help show this help message and exit
-m MODEL, --model MODEL
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: models)
--log-file LOG_FILE Store logs in specified file. (default: None)
--endpoints ENDPOINTS
Configuration file for the model server and the
connectors as a yml file. (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
Server Settings:
-p PORT, --port PORT Port to run the server at. (default: 5005)
-t AUTH_TOKEN, --auth-token AUTH_TOKEN
Enable token based authentication. Requests need to
provide the token to be accepted. (default: None)
--cors [CORS [CORS ...]]
Enable CORS for the passed origin. Use * to whitelist
all origins. (default: None)
--enable-api Start the web server API in addition to the input
channel. (default: False)
--remote-storage REMOTE_STORAGE
Set the remote location where your Rasa model is
stored, e.g. on AWS. (default: None)
--ssl-certificate SSL_CERTIFICATE
Set the SSL Certificate to create a TLS secured
server. (default: None)
--ssl-keyfile SSL_KEYFILE
Set the SSL Keyfile to create a TLS secured server.
(default: None)
--ssl-password SSL_PASSWORD
If your ssl-keyfile is protected by a password, you
can specify it using this paramer. (default: None)
Channels:
--credentials CREDENTIALS
Authentication credentials for the connector as a yml
file. (default: None)
--connector CONNECTOR
Service to connect to. (default: None)
JWT Authentication:
--jwt-secret JWT_SECRET
Public key for asymmetric JWT methods or shared
secretfor symmetric methods. Please also make sure to
use --jwt-method to select the method of the
signature, otherwise this argument will be ignored.
(default: None)
--jwt-method JWT_METHOD
Method used for the signature of the JWT
authentication payload. (default: HS256)
想了解更多其他参数信息,参阅 Running the Server。查看Rasa的HTTP API 文档了解详细的节点文档。
开启动作服务
启动执行动作的服务器,使用下面命令:
rasa run actions
以下参数可用于调整服务器设置:
usage: rasa run actions [-h] [-v] [-vv] [--quiet] [-p PORT]
[--cors [CORS [CORS ...]]] [--actions ACTIONS]
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT port to run the server at (default: 5055)
--cors [CORS [CORS ...]]
enable CORS for the passed origin. Use * to whitelist
all origins (default: None)
--actions ACTIONS name of action package to be loaded (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
故事可视化
在浏览器中用图表显示你的故事,使用下面命令:
rasa visualize
通常,data目录下的训练故事是可视化的。如果你的故事在其他目录,可以使用--stories参数指定。
其他参数:
usage: rasa visualize [-h] [-v] [-vv] [--quiet] [-d DOMAIN] [-s STORIES]
[-c CONFIG] [--out OUT] [--max-history MAX_HISTORY]
[-u NLU]
optional arguments:
-h, --help show this help message and exit
-d DOMAIN, --domain DOMAIN
Domain specification (yml file). (default: domain.yml)
-s STORIES, --stories STORIES
File or folder containing your training stories.
(default: data)
-c CONFIG, --config CONFIG
The policy and NLU pipeline configuration of your bot.
(default: config.yml)
--out OUT Filename of the output path, e.g. 'graph.html'.
(default: graph.html)
--max-history MAX_HISTORY
Max history to consider when merging paths in the
output graph. (default: 2)
-u NLU, --nlu NLU File or folder containing your NLU data, used to
insert example messages into the graph. (default:
None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
在测试数据集上评估模型
使用下面命令在测试数据集上评估模型:
rasa test
使用参数 --model 来指定要测试的模型。在 Evaluating an NLU Model 和 Evaluating a Core Model查看更详细的信息。
下面是rasa test 命令可以使用的参数:
usage: rasa test [-h] [-v] [-vv] [--quiet] [-m MODEL] [-s STORIES]
[--max-stories MAX_STORIES] [--e2e] [--endpoints ENDPOINTS]
[--fail-on-prediction-errors] [--url URL]
[--evaluate-model-directory] [-u NLU] [--out OUT]
[--successes] [--no-errors] [--histogram HISTOGRAM]
[--confmat CONFMAT] [-c CONFIG [CONFIG ...]]
[--cross-validation] [-f FOLDS] [-r RUNS]
[-p PERCENTAGES [PERCENTAGES ...]]
{core,nlu} ...
positional arguments:
{core,nlu}
core Tests Rasa Core models using your test stories.
nlu Tests Rasa NLU models using your test NLU data.
optional arguments:
-h, --help show this help message and exit
-m MODEL, --model MODEL
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: models)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
Core Test Arguments:
-s STORIES, --stories STORIES
File or folder containing your test stories. (default:
data)
--max-stories MAX_STORIES
Maximum number of stories to test on. (default: None)
--e2e, --end-to-end Run an end-to-end evaluation for combined action and
intent prediction. Requires a story file in end-to-end
format. (default: False)
--endpoints ENDPOINTS
Configuration file for the connectors as a yml file.
(default: None)
--fail-on-prediction-errors
If a prediction error is encountered, an exception is
thrown. This can be used to validate stories during
tests, e.g. on travis. (default: False)
--url URL If supplied, downloads a story file from a URL and
trains on it. Fetches the data by sending a GET
request to the supplied URL. (default: None)
--evaluate-model-directory
Should be set to evaluate models trained via 'rasa
train core --config <config-1> <config-2>'. All models
in the provided directory are evaluated and compared
against each other. (default: False)
NLU Test Arguments:
-u NLU, --nlu NLU File or folder containing your NLU data. (default:
data)
--out OUT Output path for any files created during the
evaluation. (default: results)
--successes If set successful predictions (intent and entities)
will be written to a file. (default: False)
--no-errors If set incorrect predictions (intent and entities)
will NOT be written to a file. (default: False)
--histogram HISTOGRAM
Output path for the confidence histogram. (default:
hist.png)
--confmat CONFMAT Output path for the confusion matrix plot. (default:
confmat.png)
-c CONFIG [CONFIG ...], --config CONFIG [CONFIG ...]
Model configuration file. If a single file is passed
and cross validation mode is chosen, cross-validation
is performed, if multiple configs or a folder of
configs are passed, models will be trained and
compared directly. (default: None)
拆分训练测试数据
通过下面命令拆分NLU数据:
rasa data split nlu
使用下面的参数你可以指定训练数据,权值和输出路径:
usage: rasa data split nlu [-h] [-v] [-vv] [--quiet] [-u NLU]
[--training-fraction TRAINING_FRACTION] [--out OUT]
optional arguments:
-h, --help show this help message and exit
-u NLU, --nlu NLU File or folder containing your NLU data. (default:
data)
--training-fraction TRAINING_FRACTION
Percentage of the data which should be in the training
data. (default: 0.8)
--out OUT Directory where the split files should be stored.
(default: train_test_split)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
该命令将尽量保持训练和测试数据中意图比例不变。
Markdown和JSON数据转换
下面命令可以把LUIS格式、WIT格式、Dialogflow格式、JSON格式或Markdown格式的NLU数据转化为JSON或Markdown格式:
rasa data convert nlu
使用下面的参数可以指定输入文件,输出文件和输出格式:
usage: rasa data convert nlu [-h] [-v] [-vv] [--quiet] --data DATA --out OUT
[-l LANGUAGE] -f {json,md}
optional arguments:
-h, --help show this help message and exit
--data DATA Path to the file or directory containing Rasa NLU
data. (default: None)
--out OUT File where to save training data in Rasa format.
(default: None)
-l LANGUAGE, --language LANGUAGE
Language of data. (default: en)
-f {json,md}, --format {json,md}
Output format the training data should be converted
into. (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
开启Rasa X
Rasa X是一个可以帮你构建、改进和部署由Rasa框架支持的AI助手的工具。你可在 here页面查看更多相关信息。
你可以使用下面命令在本地启动Rasa X:
rasa x
为了能够成功运行Rasa X,你需要先安装Rasa X(安装指导说明在这里here)和创建Rasa工程。
注意
Rasa X的默认端口是5002. 可以通过参数 --rasa-x-port 指定自定义端口。
下面是rasa x命令可用参数:
usage: rasa x [-h] [-v] [-vv] [--quiet] [-m MODEL] [--data DATA] [--no-prompt]
[--production] [--rasa-x-port RASA_X_PORT]
[--config-endpoint CONFIG_ENDPOINT] [--log-file LOG_FILE]
[--endpoints ENDPOINTS] [-p PORT] [-t AUTH_TOKEN]
[--cors [CORS [CORS ...]]] [--enable-api]
[--remote-storage REMOTE_STORAGE]
[--ssl-certificate SSL_CERTIFICATE] [--ssl-keyfile SSL_KEYFILE]
[--ssl-password SSL_PASSWORD] [--credentials CREDENTIALS]
[--connector CONNECTOR] [--jwt-secret JWT_SECRET]
[--jwt-method JWT_METHOD]
optional arguments:
-h, --help show this help message and exit
-m MODEL, --model MODEL
Path to a trained Rasa model. If a directory is
specified, it will use the latest model in this
directory. (default: models)
--data DATA Path to the file or directory containing stories and
Rasa NLU data. (default: data)
--no-prompt Automatic yes or default options to prompts and
oppressed warnings. (default: False)
--production Run Rasa X in a production environment. (default:
False)
--rasa-x-port RASA_X_PORT
Port to run the Rasa X server at. (default: 5002)
--config-endpoint CONFIG_ENDPOINT
Rasa X endpoint URL from which to pull the runtime
config. This URL typically contains the Rasa X token
for authentication. Example:
https://example.com/api/config?token=my_rasa_x_token
(default: None)
--log-file LOG_FILE Store logs in specified file. (default: None)
--endpoints ENDPOINTS
Configuration file for the model server and the
connectors as a yml file. (default: None)
Python Logging Options:
-v, --verbose Be verbose. Sets logging level to INFO. (default:
None)
-vv, --debug Print lots of debugging statements. Sets logging level
to DEBUG. (default: None)
--quiet Be quiet! Sets logging level to WARNING. (default:
None)
Server Settings:
-p PORT, --port PORT Port to run the server at. (default: 5005)
-t AUTH_TOKEN, --auth-token AUTH_TOKEN
Enable token based authentication. Requests need to
provide the token to be accepted. (default: None)
--cors [CORS [CORS ...]]
Enable CORS for the passed origin. Use * to whitelist
all origins. (default: None)
--enable-api Start the web server API in addition to the input
channel. (default: False)
--remote-storage REMOTE_STORAGE
Set the remote location where your Rasa model is
stored, e.g. on AWS. (default: None)
--ssl-certificate SSL_CERTIFICATE
Set the SSL Certificate to create a TLS secured
server. (default: None)
--ssl-keyfile SSL_KEYFILE
Set the SSL Keyfile to create a TLS secured server.
(default: None)
--ssl-password SSL_PASSWORD
If your ssl-keyfile is protected by a password, you
can specify it using this paramer. (default: None)
Channels:
--credentials CREDENTIALS
Authentication credentials for the connector as a yml
file. (default: None)
--connector CONNECTOR
Service to connect to. (default: None)
JWT Authentication:
--jwt-secret JWT_SECRET
Public key for asymmetric JWT methods or shared
secretfor symmetric methods. Please also make sure to
use --jwt-method to select the method of the
signature, otherwise this argument will be ignored.
(default: None)
--jwt-method JWT_METHOD
Method used for the signature of the JWT
authentication payload. (default: HS256)