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

Use response selector keys for confusion matrix labelling #7423

Merged
merged 6 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions changelog/7423.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use response selector keys (sub-intents) as labels for plotting the confusion matrix during NLU evaluation to improve readability.
17 changes: 15 additions & 2 deletions rasa/nlu/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ENTITY_ATTRIBUTE_TYPE,
ENTITY_ATTRIBUTE_GROUP,
ENTITY_ATTRIBUTE_ROLE,
RESPONSE_KEY_ATTRIBUTE,
)
from rasa.model import get_model
from rasa.nlu import config, training_data, utils
Expand Down Expand Up @@ -62,7 +63,7 @@

ResponseSelectionEvaluationResult = namedtuple(
"ResponseSelectionEvaluationResult",
"intent_target " "response_target " "response_prediction " "message " "confidence",
"intent_target response_key response_target response_prediction_full_intent response_prediction message confidence",
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like with this change we can also get rid of intent_target, response_target and response_prediction. Can you scrub those off as well? There will be some more places where you will have to make changes.

)

EntityEvaluationResult = namedtuple(
Expand Down Expand Up @@ -373,7 +374,7 @@ def evaluate_response_selections(
)

target_responses, predicted_responses = _targets_predictions_from(
response_selection_results, "response_target", "response_prediction"
response_selection_results, "response_key", "response_prediction_full_intent"
)

if report_folder:
Expand Down Expand Up @@ -1050,12 +1051,24 @@ def get_eval_data(
response_prediction_key, {}
).get(OPEN_UTTERANCE_PREDICTION_KEY, {})

response_prediction_full_intent = selector_properties.get(
response_prediction_key, {}
).get("full_retrieval_intent", {})

if isinstance(response_prediction_full_intent, str):
response_prediction_full_intent = response_prediction_full_intent.split(
"/"
)[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest not splitting the predicted retrieval_intent/sub_intent because you could have same sub_intent under multiple retrieval intents. So, let's compare for e.g. faq/ask_name to faq/ask_weather and not ask_name to ask_weather.


response_target = example.get("response", "")
response_key = example.get(RESPONSE_KEY_ATTRIBUTE, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Following from the above comment, this would then change to example.get_combined_intent_response_key()


response_selection_results.append(
ResponseSelectionEvaluationResult(
intent_target,
response_key,
response_target,
response_prediction_full_intent,
response_prediction.get("name"),
result.get("text", {}),
response_prediction.get("confidence"),
Expand Down
16 changes: 14 additions & 2 deletions tests/nlu/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,18 @@ def test_response_evaluation_report(tmpdir_factory):
response_results = [
ResponseSelectionEvaluationResult(
"chitchat",
"weather",
"It's sunny in Berlin",
"weather",
"It's sunny in Berlin",
"What's the weather",
0.65432,
),
ResponseSelectionEvaluationResult(
"chitchat",
"bot_name",
"My name is Mr.bot",
"bot_name",
"My name is Mr.bot",
"What's your name?",
0.98765,
Expand Down Expand Up @@ -506,7 +510,7 @@ def test_response_evaluation_report(tmpdir_factory):
}

assert len(report.keys()) == 5
assert report["My name is Mr.bot"] == name_query_results
assert report["bot_name"] == name_query_results
assert result["predictions"][1] == prediction


Expand Down Expand Up @@ -591,11 +595,19 @@ def test_empty_intent_removal():
def test_empty_response_removal():
response_results = [
ResponseSelectionEvaluationResult(
"chitchat", None, "It's sunny in Berlin", "What's the weather", 0.65432
"chitchat",
None,
None,
"It's sunny in Berlin",
None,
"What's the weather",
0.65432,
),
ResponseSelectionEvaluationResult(
"chitchat",
None,
"My name is Mr.bot",
None,
"My name is Mr.bot",
"What's your name?",
0.98765,
Expand Down