Repository navigation
Expand file tree
/
Copy pathtest_document_deduplicator.py
More file actions
175 lines (164 loc) · 6.18 KB
/
Copy pathtest_document_deduplicator.py
File metadata and controls
175 lines (164 loc) · 6.18 KB
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
import unittest
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.deduplicator.document_deduplicator import \
DocumentDeduplicator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class DocumentDeduplicatorTest(DataJuicerTestCaseBase):
def _run_doc_dedup(self, dataset: Dataset, target_list, op, show_num=0):
dataset = dataset.map(op.compute_hash)
dataset, dup_pairs = op.process(dataset, show_num=show_num)
dataset = dataset.select_columns(column_names=['text'])
res_list = dataset.to_list()
self.assertEqual(res_list, target_list)
return dup_pairs
def test_english_deduplication(self):
ds_list = [
{
'text': 'Today is Sunday and it\'s a happy day!'
},
{
'text': 'Do you need a cup of coffee?'
},
{
'text': 'Today is sunday and it\'s a happy day!'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
]
tgt_list = [{
'text': 'Today is Sunday and it\'s a happy day!'
}, {
'text': 'Do you need a cup of coffee?'
}, {
'text': 'Today is sunday and it\'s a happy day!'
}, {
'text':
'This paper proposed a novel method on LLM pretraining.'
}]
dataset = Dataset.from_list(ds_list)
op = DocumentDeduplicator(lowercase=False, ignore_non_character=False)
dup_pairs = self._run_doc_dedup(dataset, tgt_list, op)
self.assertEqual(len(dup_pairs), 0)
def test_english_deduplication_with_params(self):
ds_list = [
{
'text': 'Today is Sunday and it\'s a happy day!'
},
{
'text': 'Do you need a cup of coffee?'
},
{
'text': 'Today is sunday and it\'s a happy day!'
},
{
'text': 'Today is sunday and it\'s a happy day?'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
]
tgt_list = [{
'text': 'Today is Sunday and it\'s a happy day!'
}, {
'text': 'Do you need a cup of coffee?'
}, {
'text':
'This paper proposed a novel method on LLM pretraining.'
}]
dataset = Dataset.from_list(ds_list)
op = DocumentDeduplicator(lowercase=True, ignore_non_character=True)
dup_pairs = self._run_doc_dedup(dataset, tgt_list, op)
self.assertEqual(len(dup_pairs), 0)
def test_chinese_deduplication(self):
ds_list = [
{
'text': '你好,请问你是谁'
},
{
'text': '欢迎来到阿里巴巴!'
},
{
'text':
'第九届会议\n2003年7月28日至8月8日\n牙买加金斯敦\n为来自发展中国家的法'
'律和技术委员会以及财务委员会成员\n参加委员会会议支付费用的方式\n1.'
},
{
'text':
'第九届会议\n2003年7月28日至8月8日\n牙买加金斯敦\n为来自发展中国家的法'
'律和技术委员会以及财务委员会成员\n参加委员会会议支付费用的方式\n1.'
},
{
'text':
'第九届会议\n时间:2003年7月28日至8月8日\n牙买加金斯敦\n为来自发展中国家的法'
'律和技术委员会以及财务委员会成员\n参加委员会会议支付费用的方式\n1.'
},
]
tgt_list = [
{
'text': '你好,请问你是谁'
},
{
'text': '欢迎来到阿里巴巴!'
},
{
'text':
'第九届会议\n2003年7月28日至8月8日\n牙买加金斯敦\n为来自发展中国家的法'
'律和技术委员会以及财务委员会成员\n参加委员会会议支付费用的方式\n1.'
},
{
'text':
'第九届会议\n时间:2003年7月28日至8月8日\n牙买加金斯敦\n为来自发展中国家的法'
'律和技术委员会以及财务委员会成员\n参加委员会会议支付费用的方式\n1.'
},
]
dataset = Dataset.from_list(ds_list)
op = DocumentDeduplicator(lowercase=False, ignore_non_character=False)
dup_pairs = self._run_doc_dedup(dataset, tgt_list, op)
self.assertEqual(len(dup_pairs), 0)
def test_show_num(self):
ds_list = [
{
'text': 'Today is Sunday and it\'s a happy day!'
},
{
'text': 'Do you need a cup of coffee?'
},
{
'text': 'Today is sunday and it\'s a happy day!'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
{
'text':
'This paper proposed a novel method on LLM pretraining.'
},
]
tgt_list = [{
'text': 'Today is Sunday and it\'s a happy day!'
}, {
'text': 'Do you need a cup of coffee?'
}, {
'text': 'Today is sunday and it\'s a happy day!'
}, {
'text':
'This paper proposed a novel method on LLM pretraining.'
}]
dataset = Dataset.from_list(ds_list)
op = DocumentDeduplicator(lowercase=False, ignore_non_character=False)
dup_pairs = self._run_doc_dedup(dataset, tgt_list, op, show_num=1)
self.assertEqual(len(dup_pairs), 1)
if __name__ == '__main__':
unittest.main()