/model/train http API 在 json 中提供“nlu”数据时出现 500 错误

/model/train http API giving 500 error when providing “nlu” data in json

我正在尝试使用 httpapi 和 json 数据训练模型。

import requests
import json

data = {
    "config": "language: en\npipeline:\n- name: WhitespaceTokenizer\n- name: RegexFeaturizer\n- name: LexicalSyntacticFeaturizer\n- name: CountVectorsFeaturizer\n- name: CountVectorsFeaturizer\nanalyzer: \"char_wb\"\nmin_ngram: 1\nmax_ngram: 4\n- name: DIETClassifier\nepochs: 100\n- name: EntitySynonymMapper\n- name: ResponseSelector\nepochs: 100",
    "nlu": json.dumps({
        "rasa_nlu_data": {
            "regex_features": [],
            "entity_synonyms": [],
            "common_examples": [
                {
                    "text": "i m looking for a place to eat",
                            "intent": "restaurant_search",
                            "entities": []
                },
                {
                    "text": "I want to grab lunch",
                            "intent": "restaurant_search",
                            "entities": []
                },
                {
                    "text": "I am searching for a dinner spot",
                            "intent": "restaurant_search",
                            "entities": []
                },
            ]
        }
    }),
    "force": False,
    "save_to_default_model_directory": True
}

r = requests.post('http://localhost:5005/model/train', json=data)

它给了我 500 个错误。以下是错误日志:

2020-09-30 07:40:37,511 [DEBUG]  Traceback (most recent call last):
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/server.py", line 810, in train
    None, functools.partial(train_model, **info)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/train.py", line 50, in train
    additional_arguments=additional_arguments,
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/train.py", line 83, in train_async
    config, domain, training_files
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/importers/importer.py", line 79, in load_from_config
    config = io_utils.read_config_file(config_path)
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/utils/io.py", line 188, in read_config_file
    content = read_yaml(read_file(filename))
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/rasa/utils/io.py", line 124, in read_yaml
    return yaml_parser.load(content) or {}
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/ruamel/yaml/main.py", line 343, in load
    return constructor.get_single_data()
  File "/home/Documents/practice/rasa/test1/venv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
    node = self.composer.get_single_node()
  File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
  File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 891, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 1, column 1
did not find expected key
  in "<unicode string>", line 11, column 1

当我使用终端命令和 json 文件训练模型时,它训练成功。我想我缺少 /model/train api 所需的一些格式。谁能告诉我哪里错了?

我正在使用 rasa 版本 1.10.14。

提前谢谢你。

原来是配置中的字符串不正确。由于双引号与转义字符一起使用,训练模型时出现错误。我在配置中做了一些调整,它成功地训练了模型