Skip to content

Commit

Permalink
deprecate: deprecate NLU JSON format
Browse files Browse the repository at this point in the history
NLU data in JSON format is deprecated and will be removed in Rasa Open Source 4.0.

Refs: ATO-26
  • Loading branch information
wochinge committed Mar 14, 2022
1 parent 291f6c6 commit 4f30454
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/10989.removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[NLU training data](nlu-training-data.mdx) in JSON format is deprecated and will be
removed in Rasa Open Source 4.0.
Please use `rasa data convert nlu -f yaml --data <path to NLU data>` to convert your
NLU JSON data to YAML format before support for NLU JSON data is removed.
7 changes: 7 additions & 0 deletions docs/docs/migration-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ this new version for inference.

Please check whether your trained model still performs as expected and retrain if needed.

### NLU JSON Format

[NLU training data](nlu-training-data.mdx) in JSON format is deprecated and will be
removed in Rasa Open Source 4.0.
Please use `rasa data convert nlu -f yaml --data <path to NLU data>` to convert your
NLU JSON data to YAML format before support for NLU JSON data is removed.

## Rasa 2.x to 3.0

### Markdown Data
Expand Down
58 changes: 57 additions & 1 deletion rasa/shared/nlu/training_data/formats/rasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict
from typing import Any, Dict, Text

from rasa.shared.constants import DOCS_URL_MIGRATION_GUIDE
from rasa.shared.nlu.constants import TEXT, INTENT, ENTITIES
from rasa.shared.nlu.training_data.formats.readerwriter import (
JsonTrainingDataReader,
Expand All @@ -12,11 +13,55 @@

from rasa.shared.nlu.training_data.training_data import TrainingData
from rasa.shared.nlu.training_data.message import Message
import rasa.shared.utils.io

logger = logging.getLogger(__name__)


class RasaReader(JsonTrainingDataReader):
"""Reader for Rasa NLU training data in JSON format.
Example:
{
"rasa_nlu_data": {
"regex_features": [
{
"name": "zipcode",
"pattern": "[0-9]{5}"
}
],
"entity_synonyms": [
{
"value": "chinese",
"synonyms": ["Chinese", "Chines", "chines"]
}
],
"common_examples": [
{
"text": "hey",
"intent": "greet",
"entities": []
},
{
"text": "howdy",
"intent": "greet",
"entities": []
}
]
}
}
"""

def __init__(self) -> None:
"""Creates reader."""
super().__init__()
rasa.shared.utils.io.raise_deprecation_warning(
"NLU data in Rasa JSON format is deprecated and will be removed in Rasa "
"Open Source 4.0.0. Please convert your JSON NLU data to the "
"Rasa YAML format.",
docs=DOCS_URL_MIGRATION_GUIDE,
)

def read_from_json(self, js: Dict[Text, Any], **_: Any) -> "TrainingData":
"""Loads training data stored in the rasa NLU data format."""
import rasa.shared.nlu.training_data.schemas.data_schema as schema
Expand Down Expand Up @@ -49,9 +94,20 @@ def read_from_json(self, js: Dict[Text, Any], **_: Any) -> "TrainingData":


class RasaWriter(TrainingDataWriter):
"""Dumps NLU data as Rasa JSON string."""

def __init__(self) -> None:
"""Creates writer."""
super().__init__()
rasa.shared.utils.io.raise_deprecation_warning(
"NLU data in Rasa JSON format is deprecated and will be removed in Rasa "
"Open Source 4.0.0. Please convert your JSON NLU data to the "
"Rasa YAML format.",
docs=DOCS_URL_MIGRATION_GUIDE,
)

def dumps(self, training_data: "TrainingData", **kwargs: Any) -> Text:
"""Writes Training Data to a string in json format."""

js_entity_synonyms = defaultdict(list)
for k, v in training_data.entity_synonyms.items():
if k != v:
Expand Down
3 changes: 2 additions & 1 deletion tests/cli/test_rasa_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_data_split_nlu(run_in_simple_project: Callable[..., RunResult]):


def test_data_convert_nlu(run_in_simple_project: Callable[..., RunResult]):
run_in_simple_project(
result = run_in_simple_project(
"data",
"convert",
"nlu",
Expand All @@ -67,6 +67,7 @@ def test_data_convert_nlu(run_in_simple_project: Callable[..., RunResult]):
"json",
)

assert "NLU data in Rasa JSON format is deprecated" in str(result.stderr)
assert os.path.exists("out_nlu_data.json")


Expand Down

0 comments on commit 4f30454

Please sign in to comment.