Rasa訓練データフォーマットnlu.jsonとnlu.md相互回転

16530 ワード

文書ディレクトリ

  • JSON回転Markdown
  • 実行コマンド
  • 実行コード
  • Markdown回転JSON
  • 実行コマンド
  • 実行コード
  • 中国語
  • 参考文献
  • 実行コマンドと実行コードの2つの方法があります

    JSON回転Markdown

    {
      "rasa_nlu_data": {
        "common_examples": [
          {
            "text": "hey",
            "intent": "greet",
            "entities": []
          },
          {
            "text": "hello",
            "intent": "greet",
            "entities": []
          },
          {
            "text": "i'm looking for a place in the north of town",
            "intent": "restaurant_search",
            "entities": [
              {
                "start": 31,
                "end": 36,
                "value": "north",
                "entity": "location"
              }
            ]
          },
          {
            "text": "yes",
            "intent": "affirm",
            "entities": []
          },
          {
            "text": "show me a mexican place in the centre",
            "intent": "restaurant_search",
            "entities": [
              {
                "start": 31,
                "end": 37,
                "value": "centre",
                "entity": "location"
              },
              {
                "start": 10,
                "end": 17,
                "value": "mexican",
                "entity": "cuisine"
              }
            ]
          },
          {
            "text": "bye",
            "intent": "goodbye",
            "entities": []
          },
          {
            "text": "goodbye",
            "intent": "goodbye",
            "entities": []
          },
          {
            "text": "i am looking for an indian spot",
            "intent": "restaurant_search",
            "entities": [
              {
                "start": 20,
                "end": 26,
                "value": "indian",
                "entity": "cuisine"
              }
            ]
          },
          {
            "text": "central indian restaurant",
            "intent": "restaurant_search",
            "entities": [
              {
                "start": 0,
                "end": 7,
                "value": "central",
                "entity": "location"
              },
              {
                "start": 8,
                "end": 14,
                "value": "indian",
                "entity": "cuisine"
              }
            ]
          }
        ]
      }
    }
    

    コマンドの実行

    rasa data convert nlu --data data/nlu.md --out data/nlu.json -f json

    実行コード

    from rasa.nlu.training_data import load_data
    
    input_file = 'nlu.json'
    output_file = 'nlu.md'
    
    with open(output_file, 'w') as f:
        f.write(load_data(input_file).as_markdown())
    

    Markdown回転JSON

    ## intent:affirm
    - yes
    
    ## intent:goodbye
    - bye
    - goodbye
    
    ## intent:greet
    - hey
    - hello
    
    ## intent:restaurant_search
    - i'm looking for a place in the [north](location) of town
    - show me a [mexican](cuisine) place in the [centre](location)
    - i am looking for an [indian](cuisine) spot
    - [central](location) [indian](cuisine) restaurant
    

    コマンドの実行

    rasa data convert nlu --data data/nlu.json --out data/nlu.md -f md

    実行コード

    from rasa.nlu.training_data import load_data
    
    input_file = 'nlu.md'
    output_file = 'nlu.json'
    
    with open(output_file, 'w') as f:
        f.write(load_data(input_file).as_json())
    

    中国語を回す

    encoding='utf-8' language='zh'
    from rasa.nlu.training_data import load_data
    
    input_file = 'nlu.json'
    output_file = 'nlu.md'
    
    with open(output_file, 'w', encoding='utf-8') as f:
        f.write(load_data(input_file, language='zh').as_markdown())
    

    参考文献

  • Training Data Format
  • Convert a Rasa NLU training file from JSON to Markdown format
  • mmand Line Interface