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

Don't evaluate entities if no entities present in test data #8813

Merged
merged 6 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions changelog/8812.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Don't evaluate entities if no entities present in test data.

Also, catch exception in `plot_paired_histogram` when data is empty.
4 changes: 3 additions & 1 deletion rasa/nlu/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,9 @@ def get_eval_data(
interpreter
)

should_eval_entities = is_entity_extractor_present(interpreter)
should_eval_entities = (
is_entity_extractor_present(interpreter) and len(test_data.entities) > 0
)

for example in tqdm(test_data.nlu_examples):
result = interpreter.parse(example.get(TEXT), only_output_properties=False)
Expand Down
24 changes: 17 additions & 7 deletions rasa/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ def _extract_paired_histogram_specification(

Returns:
The bins, values, ranges of either x-axis, and the range of the y-axis

Raises:
ValueError: If histogram_data does not contain values.
"""
if not histogram_data or not np.concatenate(histogram_data).size:
rasa.shared.utils.io.raise_warning("No data to plot paired histogram.")
raise ValueError("No data to plot paired histogram.")
min_data_value = np.min(np.concatenate(histogram_data))
max_data_value = np.max(np.concatenate(histogram_data))
bin_width = (max_data_value - min_data_value) / num_bins
Expand Down Expand Up @@ -244,13 +250,17 @@ def plot_paired_histogram(
)
return

bins, tallies, x_ranges, y_range = _extract_paired_histogram_specification(
histogram_data,
num_bins,
density=density,
x_pad_fraction=x_pad_fraction,
y_pad_fraction=y_pad_fraction,
)
try:
bins, tallies, x_ranges, y_range = _extract_paired_histogram_specification(
histogram_data,
num_bins,
density=density,
x_pad_fraction=x_pad_fraction,
y_pad_fraction=y_pad_fraction,
)
except ValueError as e:
rasa.shared.utils.io.raise_warning(f"Unable to plot paried histogram: {e}")
JEM-Mosig marked this conversation as resolved.
Show resolved Hide resolved
return
yticks = [float(f"{x:.2f}") for x in bins]

import matplotlib.pyplot as plt
Expand Down
25 changes: 25 additions & 0 deletions tests/utils/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ def test_paired_histogram_specification_bins(
assert np.all(bins == expected_bins)


@pytest.mark.parametrize(
"bad_data", [([[]]), ([[], []]),],
)
def test_paired_histogram_specification_bins_raises(bad_data: List):
"""`_extract_paired_histogram_specification` raises a ValueError on empty data"""
for density in [False, True]:
with pytest.raises(ValueError):
rasa.utils.plotting._extract_paired_histogram_specification(
bad_data,
num_bins=2,
density=density,
x_pad_fraction=0,
y_pad_fraction=0,
)


@pytest.mark.parametrize(
"bad_data", [([[]]), ([[], []]),],
)
def test_plot_paired_histogram_doesnt_raise(bad_data: List):
"""Empty data shouldn't raise an error."""
for density in [False, True]:
rasa.utils.plotting.plot_paired_histogram(bad_data, title="")
JEM-Mosig marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
"data, num_bins, density, expected_histograms",
[
Expand Down