pythonrasa-nlurasarasa-corerasa-x

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


I am trying to train model using httpapi and json data blow is the code.

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)

It gives me 500 error. Below is the log for error:

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

When I train model using terminal commands and json file, it is trained successfully. I think I am missing some formatting required for /model/train api. Can someone tell me where am I going wrong?

I am using rasa version 1.10.14.

Thankyou in advance.


Solution

  • Turns out that the string in config was not proper. It was giving error when training model due to double quotes used with escape characters. I made some tweaks in the config and it trained the model successfully