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

add function to add frequently confused intent to intent report #4899

Merged
merged 34 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fc07bcb
add function to add frequently confused intent to intent report
amn41 Dec 4, 2019
25cb1e5
update test, add types, format
amn41 Dec 4, 2019
159ef9d
avoid index out of bounds
amn41 Dec 5, 2019
4e8180e
Update rasa/nlu/test.py
amn41 Dec 5, 2019
ec174eb
Update rasa/nlu/test.py
amn41 Dec 5, 2019
7558b29
Update rasa/nlu/test.py
amn41 Dec 5, 2019
791ef37
review comments
amn41 Dec 5, 2019
21361d3
add test with bigger confusion matrix
amn41 Dec 5, 2019
c3f5ffb
fix file
amn41 Dec 5, 2019
3f54895
fix keys len
amn41 Dec 5, 2019
41596d5
type annotation and fix test
amn41 Dec 5, 2019
f96eb79
fix typo
amn41 Dec 5, 2019
bcc118f
add docstring
amn41 Dec 5, 2019
632b115
fix linter errors
amn41 Dec 5, 2019
29189f3
Merge branch 'master' into add-most-confused-intents-to-report
amn41 Dec 5, 2019
8426628
Update rasa/nlu/test.py
amn41 Dec 10, 2019
275d8c8
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
2d12fa2
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
af686fd
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
50951fd
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
16be17a
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
9b5e23f
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
92cf483
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
5558d53
Update tests/nlu/base/test_evaluation.py
amn41 Dec 10, 2019
cae2313
add another condition to test
amn41 Dec 10, 2019
9396f63
add imports
amn41 Dec 10, 2019
6bb8f49
fix error with negative index starting at -0
amn41 Dec 11, 2019
c08962e
add changelog file
amn41 Dec 11, 2019
355c679
Merge branch 'master' into add-most-confused-intents-to-report
amn41 Dec 11, 2019
517ad02
Merge branch 'pin-multidict' into add-most-confused-intents-to-report
amn41 Dec 11, 2019
019be00
Merge branch 'master' into add-most-confused-intents-to-report
amn41 Dec 12, 2019
b93dbe7
Update rasa/nlu/test.py
amn41 Dec 12, 2019
13d32a2
fix import
amn41 Dec 12, 2019
a566f66
Merge branch 'master' into add-most-confused-intents-to-report
amn41 Dec 12, 2019
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
31 changes: 31 additions & 0 deletions rasa/nlu/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,33 @@ def evaluate_response_selections(
}


def add_confused_intents_to_report(
amn41 marked this conversation as resolved.
Show resolved Hide resolved
report: Dict, target_intents: Iterable[Any], predicted_intents: Iterable[Any]
amn41 marked this conversation as resolved.
Show resolved Hide resolved
) -> Dict:
amn41 marked this conversation as resolved.
Show resolved Hide resolved

from sklearn.metrics import confusion_matrix
amn41 marked this conversation as resolved.
Show resolved Hide resolved
from sklearn.utils.multiclass import unique_labels

cnf_matrix = confusion_matrix(target_intents, predicted_intents)
amn41 marked this conversation as resolved.
Show resolved Hide resolved

indices = np.argsort(cnf_matrix, axis=1)
amn41 marked this conversation as resolved.
Show resolved Hide resolved
labels = unique_labels(target_intents, predicted_intents)
n_candidates = min(3, len(labels))

for label in labels:
if report.get(label):
amn41 marked this conversation as resolved.
Show resolved Hide resolved
report[label]["confused_with"] = {}
for i, label in enumerate(labels):
for j in range(n_candidates):
label_idx = indices[i, -j]
_label = labels[label_idx]
amn41 marked this conversation as resolved.
Show resolved Hide resolved
num_hits = int(cnf_matrix[i, label_idx])
amn41 marked this conversation as resolved.
Show resolved Hide resolved
if _label != label and num_hits > 0:
amn41 marked this conversation as resolved.
Show resolved Hide resolved
report[label]["confused_with"][_label] = num_hits

return report


def evaluate_intents(
intent_results: List[IntentEvaluationResult],
output_directory: Optional[Text],
Expand Down Expand Up @@ -435,6 +462,9 @@ def evaluate_intents(
report, precision, f1, accuracy = get_evaluation_metrics(
target_intents, predicted_intents, output_dict=True
)
report = add_confused_intents_to_report(
report, target_intents, predicted_intents
)

report_filename = os.path.join(output_directory, "intent_report.json")

Expand Down Expand Up @@ -473,6 +503,7 @@ def evaluate_intents(

cnf_matrix = confusion_matrix(target_intents, predicted_intents)
labels = unique_labels(target_intents, predicted_intents)

plot_confusion_matrix(
cnf_matrix,
classes=labels,
Expand Down
8 changes: 7 additions & 1 deletion tests/nlu/base/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ def test_intent_evaluation_report(tmpdir_factory):

report = json.loads(rasa.utils.io.read_file(report_filename))

greet_results = {"precision": 1.0, "recall": 1.0, "f1-score": 1.0, "support": 1}
greet_results = {
"precision": 1.0,
"recall": 1.0,
"f1-score": 1.0,
"support": 1,
"confused_with": {},
}

prediction = {
"text": "hello",
Expand Down