-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathtest_dialog_intent_detection_mapper.py
201 lines (175 loc) · 7.82 KB
/
test_dialog_intent_detection_mapper.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import unittest
import json
from loguru import logger
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_intent_detection_mapper import DialogIntentDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.constant import Fields, MetaKeys
# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogIntentDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
# export OPENAI_API_KEY=your_key
def _run_op(self, op, samples, target_len, labels_key=None, analysis_key=None):
dataset = Dataset.from_list(samples)
dataset = op.run(dataset)
labels_key = labels_key or MetaKeys.dialog_intent_labels
analysis_key = analysis_key or MetaKeys.dialog_intent_labels_analysis
labels_list = dataset[0][Fields.meta][labels_key]
analysis_list = dataset[0][Fields.meta][analysis_key]
for analysis, labels in zip(analysis_list, labels_list):
logger.info(f'分析:{analysis}')
logger.info(f'意图:{labels}')
self.assertEqual(len(analysis_list), target_len)
self.assertEqual(len(labels_list), target_len)
def test_default(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
),
(
'你在说什么我听不懂。',
'「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
)
]
}]
op = DialogIntentDetectionMapper(api_model='qwen2.5-72b-instruct')
self._run_op(op, samples, 4)
def test_max_round(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
),
(
'你在说什么我听不懂。',
'「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
)
]
}]
op = DialogIntentDetectionMapper(api_model='qwen2.5-72b-instruct',
max_round=1)
self._run_op(op, samples, 4)
def test_max_round_zero(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
),
(
'你在说什么我听不懂。',
'「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
)
]
}]
op = DialogIntentDetectionMapper(api_model='qwen2.5-72b-instruct',
max_round=0)
self._run_op(op, samples, 4)
def test_query(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
)
],
'query': '你在说什么我听不懂。',
'response': '「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
}]
op = DialogIntentDetectionMapper(api_model='qwen2.5-72b-instruct',
max_round=1)
self._run_op(op, samples, 4)
def test_intent_candidates(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
),
(
'你在说什么我听不懂。',
'「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
)
]
}]
op = DialogIntentDetectionMapper(
api_model='qwen2.5-72b-instruct',
intent_candidates=['评价', '讽刺', '表达困惑']
)
self._run_op(op, samples, 4)
def test_rename_keys(self):
samples = [{
'history': [
(
'李莲花有口皆碑',
'「微笑」过奖了,我也就是个普通大夫,没什么值得夸耀的。'
),
(
'是的,你确实是一个普通大夫,没什么值得夸耀的。',
'「委屈」你这话说的,我也是尽心尽力治病救人了。'
),
(
'你自己说的呀,我现在说了,你又不高兴了。',
'or of of of of or or and or of of of of of of of,,, '
),
(
'你在说什么我听不懂。',
'「委屈」我也没说什么呀,就是觉得你有点冤枉我了'
)
]
}]
labels_key = 'my_label'
analysis_key = 'my_analysis'
op = DialogIntentDetectionMapper(api_model='qwen2.5-72b-instruct',
labels_key=labels_key,
analysis_key=analysis_key)
self._run_op(op, samples, 4, labels_key, analysis_key)
if __name__ == '__main__':
unittest.main()