Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make converter support response key for test stories #7080

Merged
merged 7 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/7034.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The converter tool now converts test stories and stories that contain full retrieval intents correctly.
Previously the response keys were deleted during conversion to YAML.
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,16 @@ def _parse_message(self, message: Text, line_num: int) -> UserUttered:
if self.use_e2e:
parsed = self.parse_e2e_message(message, self._is_used_for_training)
text = parsed.get("text")
intent = {INTENT_NAME_KEY: parsed.get("intent")}
intent = {
INTENT_NAME_KEY: parsed.get(
"intent_response_key", default=parsed.get("intent")
)
}
entities = parsed.get("entities")
parse_data = {
"text": text,
"intent": intent,
"intent_ranking": [{INTENT_NAME_KEY: parsed.get("intent")}],
"intent_ranking": [intent],
"entities": entities,
}
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,75 @@ async def test_test_stories(tmpdir: Path):
" - action: respond_faq\n"
" - action: action_set_faq_slot\n"
)


async def test_test_stories_conversion_response_key(tmpdir: Path):
converted_data_folder = tmpdir / "converted_data"
os.mkdir(converted_data_folder)

test_data_folder = tmpdir / "tests"
os.makedirs(test_data_folder, exist_ok=True)
test_data_file = Path(test_data_folder / "test_stories.md")

simple_story_md = """
## id

* out_of_scope/other: hahaha
- utter_out_of_scope/other
"""

with open(test_data_file, "w") as f:
f.write(simple_story_md)

await StoryMarkdownToYamlConverter().convert_and_write(
test_data_file, converted_data_folder
)

assert len(os.listdir(converted_data_folder)) == 1
with open(f"{converted_data_folder}/test_stories_converted.yml", "r") as f:
content = f.read()
assert content == (
f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n'
"stories:\n"
"- story: id\n"
" steps:\n"
" - intent: out_of_scope/other\n"
" user: |-\n"
" hahaha\n"
" - action: utter_out_of_scope/other\n"
)
Comment on lines +146 to +155
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPT: style suggestion, use multiline string instead (needs import textwrap)

Suggested change
assert content == (
f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n'
"stories:\n"
"- story: id\n"
" steps:\n"
" - intent: out_of_scope/other\n"
" user: |-\n"
" hahaha\n"
" - action: utter_out_of_scope/other\n"
)
assert content == textwrap.dedent(f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
stories:
- story: id
steps:
- intent: out_of_scope/other
user: |-
hahaha
- action: utter_out_of_scope/other
""")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!! since it already got merged, I will consider this for the next test I write!



async def test_stories_conversion_response_key(tmpdir: Path):
converted_data_folder = tmpdir / "converted_data"
os.mkdir(converted_data_folder)

training_data_folder = tmpdir / "data/core"
os.makedirs(training_data_folder, exist_ok=True)
training_data_file = Path(training_data_folder / "stories.md")

simple_story_md = """
## id
* out_of_scope/other
- utter_out_of_scope/other
"""

with open(training_data_file, "w") as f:
f.write(simple_story_md)

await StoryMarkdownToYamlConverter().convert_and_write(
training_data_file, converted_data_folder
)

assert len(os.listdir(converted_data_folder)) == 1

with open(f"{converted_data_folder}/stories_converted.yml", "r") as f:
content = f.read()
assert content == (
f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n'
"stories:\n"
"- story: id\n"
" steps:\n"
" - intent: out_of_scope/other\n"
" - action: utter_out_of_scope/other\n"
)