Datasets:
ArXiv:
License:
Commit
·
a441c27
1
Parent(s):
f9528ce
Update filtered_mc4.py
Browse files- filtered_mc4.py +7 -7
filtered_mc4.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import json
|
2 |
import re
|
3 |
-
from re import Pattern
|
4 |
import gzip
|
5 |
import json
|
6 |
|
@@ -257,7 +256,7 @@ _N_SHARDS_PER_SPLIT = {
|
|
257 |
"zu": {"train": 8, "validation": 1},
|
258 |
}
|
259 |
|
260 |
-
MC4_MAX_REJECT_PATTERN_OCCURENCE =
|
261 |
MC4_FILTER_TARGET_FIELD = "text"
|
262 |
|
263 |
|
@@ -269,7 +268,7 @@ class FilteredMc4Config(datasets.BuilderConfig):
|
|
269 |
*args,
|
270 |
languages,
|
271 |
filter_target_field: str=MC4_FILTER_TARGET_FIELD,
|
272 |
-
|
273 |
max_reject_pattern_occurence: int=MC4_MAX_REJECT_PATTERN_OCCURENCE,
|
274 |
**kwargs,
|
275 |
):
|
@@ -285,13 +284,14 @@ class FilteredMc4Config(datasets.BuilderConfig):
|
|
285 |
)
|
286 |
self.languages = languages
|
287 |
self.filter_target_field = filter_target_field
|
288 |
-
self.
|
289 |
self.max_reject_pattern_occurence = max_reject_pattern_occurence
|
290 |
|
291 |
def filter(self, example: dict) -> bool:
|
292 |
-
for
|
293 |
-
|
294 |
-
|
|
|
295 |
return True
|
296 |
|
297 |
|
|
|
1 |
import json
|
2 |
import re
|
|
|
3 |
import gzip
|
4 |
import json
|
5 |
|
|
|
256 |
"zu": {"train": 8, "validation": 1},
|
257 |
}
|
258 |
|
259 |
+
MC4_MAX_REJECT_PATTERN_OCCURENCE = 3
|
260 |
MC4_FILTER_TARGET_FIELD = "text"
|
261 |
|
262 |
|
|
|
268 |
*args,
|
269 |
languages,
|
270 |
filter_target_field: str=MC4_FILTER_TARGET_FIELD,
|
271 |
+
reject_patterns: List[str]=[r"(?!)"],
|
272 |
max_reject_pattern_occurence: int=MC4_MAX_REJECT_PATTERN_OCCURENCE,
|
273 |
**kwargs,
|
274 |
):
|
|
|
284 |
)
|
285 |
self.languages = languages
|
286 |
self.filter_target_field = filter_target_field
|
287 |
+
self.reject_patterns = [re.compile(_) for _ in reject_patterns]
|
288 |
self.max_reject_pattern_occurence = max_reject_pattern_occurence
|
289 |
|
290 |
def filter(self, example: dict) -> bool:
|
291 |
+
for reject_pattern in self.reject_patterns:
|
292 |
+
for count, _ in enumerate(reject_pattern.finditer(example[self.filter_target_field])):
|
293 |
+
if count == self.max_reject_pattern_occurence:
|
294 |
+
return False
|
295 |
return True
|
296 |
|
297 |
|