-
Notifications
You must be signed in to change notification settings - Fork 187
/
test_remove_long_words_mapper.py
65 lines (52 loc) · 2.21 KB
/
test_remove_long_words_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
import unittest
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.remove_long_words_mapper import \
RemoveLongWordsMapper
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class RemoveLongWordsMapperTest(DataJuicerTestCaseBase):
def _run_remove_long_words(self, samples, op):
dataset = Dataset.from_list(samples)
dataset = dataset.map(op.process, batch_size=2)
for data in dataset:
self.assertEqual(data['text'], data['target'])
def test_normal_case(self):
samples = [{
'text':
'This paper proposed novel method LLM pretraining.',
'target':
'This paper proposed novel method LLM pretraining.'
}]
op = RemoveLongWordsMapper(min_len=3, max_len=15)
self._run_remove_long_words(samples, op)
def test_long_short_words_case(self):
samples = [{
'text':
'This paper a novel eqeqweqwewqeqwe121e1 method on LLM pretrain.',
'target': 'This paper novel method LLM pretrain.'
}, {
'text':
'Sur la plateforme MT4, manières à ces fonctionnalités sont conçu',
'target':
'Sur plateforme MT4, manières ces fonctionnalités sont conçu'
}]
op = RemoveLongWordsMapper(min_len=3, max_len=15)
self._run_remove_long_words(samples, op)
def test_special_words_case(self):
samples = [{
'text':
'This paper proposed a novel eqeqweqwewqenhq😊😠 method on LLM.',
'target':
'This paper proposed novel eqeqweqwewqenhq😊😠 method LLM.'
}, {
'text':
"Sur la plateforme MT4, plusieurs manières d'accéder0123813976125",
'target':
"Sur plateforme MT4, plusieurs manières d'accéder0123813976125"
}, {
'text': 'The Mona Lisa doesn’t have eyebrows.',
'target': 'The Mona Lisa have eyebrows.'
}]
op = RemoveLongWordsMapper(min_len=3, max_len=15)
self._run_remove_long_words(samples, op)
if __name__ == '__main__':
unittest.main()