-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
test_mr_publish_results.py
132 lines (115 loc) · 3.92 KB
/
test_mr_publish_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
from pathlib import Path
import sys
from unittest import mock
sys.path.append(".github/scripts")
from mr_publish_results import ( # noqa: E402
prepare_ml_metric,
prepare_ml_metrics,
transform_to_seconds,
generate_json,
prepare_datadog_tags,
)
EXAMPLE_CONFIG = "Sparse + BERT + DIET(seq) + ResponseSelector(t2t)"
EXAMPLE_DATASET_NAME = "financial-demo"
ENV_VARS = {
"BRANCH": "my-branch",
"PR_ID": "10927",
"PR_URL": "https://github.com/RasaHQ/rasa/pull/10856/",
"GITHUB_EVENT_NAME": "pull_request",
"GITHUB_RUN_ID": "1882718340",
"GITHUB_SHA": "abc",
"GITHUB_WORKFLOW": "CI - Model Regression",
"IS_EXTERNAL": "false",
"DATASET_REPOSITORY_BRANCH": "main",
"CONFIG": EXAMPLE_CONFIG,
"DATASET_NAME": EXAMPLE_DATASET_NAME,
"CONFIG_REPOSITORY_BRANCH": "main",
"DATASET_COMMIT": "52a3ad3eb5292d56542687e23b06703431f15ead",
"ACCELERATOR_TYPE": "CPU",
"TEST_RUN_TIME": "1m54s",
"TRAIN_RUN_TIME": "4m4s",
"TOTAL_RUN_TIME": "5m58s",
"TYPE": "nlu",
"INDEX_REPETITION": "0",
"HOST_NAME": "github-runner-2223039222-22df222fcd-2cn7d",
}
@mock.patch.dict(os.environ, ENV_VARS, clear=True)
def test_generate_json():
f = Path(__file__).parent / "test_data" / "intent_report.json"
result = generate_json(f, task="intent_classification", data={})
assert isinstance(result[EXAMPLE_DATASET_NAME][EXAMPLE_CONFIG], list)
actual = result[EXAMPLE_DATASET_NAME][EXAMPLE_CONFIG][0]["intent_classification"]
expected = {
"accuracy": 1.0,
"weighted avg": {
"precision": 1.0,
"recall": 1.0,
"f1-score": 1.0,
"support": 28,
},
"macro avg": {"precision": 1.0, "recall": 1.0, "f1-score": 1.0, "support": 28},
}
assert expected == actual
def test_transform_to_seconds():
assert 87.0 == transform_to_seconds("1m27s")
assert 87.3 == transform_to_seconds("1m27.3s")
assert 27.0 == transform_to_seconds("27s")
assert 3627.0 == transform_to_seconds("1h27s")
assert 3687.0 == transform_to_seconds("1h1m27s")
def test_prepare_ml_model_perf_metrics():
results = [
{
"macro avg": {
"precision": 0.8,
"recall": 0.8,
"f1-score": 0.8,
"support": 14,
},
"micro avg": {
"precision": 1.0,
"recall": 0.7857142857142857,
"f1-score": 0.88,
"support": 14,
},
"file_name": "DIETClassifier_report.json",
"task": "Entity Prediction",
},
{
"accuracy": 1.0,
"weighted avg": {
"precision": 1.0,
"recall": 1.0,
"f1-score": 1.0,
"support": 28,
},
"macro avg": {
"precision": 1.0,
"recall": 1.0,
"f1-score": 1.0,
"support": 28,
},
"file_name": "intent_report.json",
"task": "Intent Classification",
},
]
metrics_ml = prepare_ml_metrics(results)
assert len(metrics_ml) == 17
def test_prepare_ml_model_perf_metrics_simple():
result = {
"accuracy": 1.0,
"weighted avg": {"precision": 1, "recall": 1.0, "f1-score": 1, "support": 28},
"task": "Intent Classification",
}
metrics_ml = prepare_ml_metric(result)
assert len(metrics_ml) == 5
for _, v in metrics_ml.items():
assert isinstance(v, float)
key, value = "Intent Classification.accuracy", 1.0
assert key in metrics_ml and value == metrics_ml[key]
key, value = "Intent Classification.weighted avg.f1-score", 1.0
assert key in metrics_ml and value == metrics_ml[key]
@mock.patch.dict(os.environ, ENV_VARS, clear=True)
def test_prepare_datadog_tags():
tags_list = prepare_datadog_tags()
assert "dataset:financial-demo" in tags_list