Skip to content

Instantly share code, notes, and snippets.

@nmstoker
Created January 11, 2018 00:07
Show Gist options
  • Save nmstoker/04355dc113608fe88b999ea1b95fb355 to your computer and use it in GitHub Desktop.
Save nmstoker/04355dc113608fe88b999ea1b95fb355 to your computer and use it in GitHub Desktop.
Convert a Rasa NLU training file from JSON to Markdown format
from rasa_nlu.converters import load_data
# This re-uses the Rasa NLU converters code to turn a JSON Rasa NLU training
# file into MD format and save it
# Assumes you have Rasa NLU installed :-)
# If you want other options, look at the NLU code to work out how to handle them
# USE AT YOUR OWN RISK
input_training_file = '/home/username/Projects/your-project/data/training.json'
# *******************************************************
# TAKE CARE: output_md_file is overwritten automatically
# *******************************************************
output_md_file = '/home/username/Projects/your-project/data/training.md'
with open(output_md_file,'w') as f:
f.write(load_data(input_training_file).as_markdown())
@guiguetz
Copy link

If you got here and is using a new version of rasa

-Change this line :
from rasa_nlu.converters import load_data
To:
from rasa_nlu.training_data import load_data

@sevetseh28
Copy link

I think it's also wise to explicitly set the encoding to utf-8 when creating the file. Thanks for the gist!

@chmodsss
Copy link

Another method.
from rasa.nlu.convert import convert_training_data
convert_training_data(data_file="ip_file.json", out_file="out_file.md", output_format="md", language="")

@KarthiAru
Copy link

What are the changes that I need to make to make this work for Rasa 1.1.4?

@chmodsss
Copy link

chmodsss commented Jul 2, 2019

Another method.
from rasa.nlu.convert import convert_training_data
convert_training_data(data_file="ip_file.json", out_file="out_file.md", output_format="md", language="")

@KarthiAru I am using Rasa1.x and this worked fine for me.

@KarthiAru
Copy link

@sivu1, I'm getting the below error
ImportError: No module named rasa.nlu.convert

I just installed rasa using the below command as mentioned in https://rasa.com/docs/getting-started/
pip install rasa-x --extra-index-url https://pypi.rasa.com/simple

Should I install any additional packages?

@chmodsss
Copy link

chmodsss commented Jul 2, 2019

@KarthiAru In a fresh environment, just try pip install rasa That will install the latest version 1.1.4. You will also get rasa x. The docs is not yet updated.

@KarthiAru
Copy link

@KarthiAru In a fresh environment, just try pip install rasa That will install the latest version 1.1.4. You will also get rasa x. The docs is not yet updated.

Thanks, @sivu1. This worked!

@ravikrcs
Copy link

ravikrcs commented Jul 26, 2019

Another method.
from rasa.nlu.convert import convert_training_data
convert_training_data(data_file="ip_file.json", out_file="out_file.md", output_format="md", language="")

ya its working. Thanks
from rasa_nlu.convert import convert_training_data
convert_training_data(data_file="nlu.json", out_file="out_file.md", output_format="md", language="")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment