C4 badwords filter: capitalized entries in upstream wordlists never match (text is lower-cased, list entries are not)

Đang mở
#11,258 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@Jefferyjia đang làm issue này rồi.

Từ ngày 27/11/2026.

  • #11259 của @Jefferyjia — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
20/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python, tensorflow
Lĩnh vực
data-engineering

Hướng nghiên cứu

Start with tensorflow_datasets/text/c4_utils.py::get_badwords_filter_fn and the existing test_badwords_filter test mentioned in the issue. Check how entries are compiled and how text is matched, then verify the regression case with the capitalized Spanish word Cabrón. Done means that case is filtered correctly; an open pull request is already linked to this issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

C4 badwords filter: capitalized entries in upstream wordlists never match, because matching is done against lower-cased text

Summary

C4BadWordsFlag loads language-specific badword lists from the LDNOOBW repository and builds regexes in tensorflow_datasets/text/c4_utils.py::get_badwords_filter_fn. Matching, however, is performed against lower-cased page text (_badwords_filter calls badwords_regex[lang].search(text.lower())).

The wordlist entries are never lower-cased before being compiled into the regex:

# c4_utils.py, get_badwords_filter_fn
words = [re.escape(w) for w in words]

So any entry that contains an uppercase character can never match, and pages containing those words pass the filter.

Evidence

I downloaded the exact pinned wordlists referenced by tensorflow_datasets/text/c4.py (_EN_BADWORDS_URL at commit 25e679f.../en, _BADWORDS_URL at commit 5faf2ba.../{lang}) and counted entries that contain an uppercase character and whose lowercase form is not itself already in the list (i.e. entries that become newly effective after lower-casing):

Language Dead uppercase entries Examples
es 61 Cabrón, Asesinato, Bollera, Caca
tr 11 Çingenede, ...
zh 7 卖B, 妈个B, 干死CS, 贱B
tlh 2 QI'yaH, Qu'vatlh
de 1 MILF
fr 1 MALPT
Total 83

(Many more entries are mixed-case duplicates of lower-case entries already in the same list; the 83 above are the ones that are newly effective after the fix.)

Reproduction

from tensorflow_datasets.text import c4_utils

# entry is capitalized exactly as it appears in the pinned 'es' list
badwords_filter_fn = c4_utils.get_badwords_filter_fn(badwords={"es": ["Cabrón"]})

badwords_filter_fn(page=type(c4_utils.PageFeatures)(
    text="Esto es un Cabrón muy fuerte.", language="es"))  # True (page kept)

The page is kept even though it contains a listed badword. Lower-casing the entry at compile time makes both "Cabrón" and "cabrón" trigger the filter.

Root cause chain:

  1. c4.py (generate_pages): badwords[lang].update(l.strip() for l in f) — raw entries from the upstream list.
  2. c4_utils.py::get_badwords_filter_fn: words = [re.escape(w) for w in words] — no lower-casing.
  3. c4_utils.py::_badwords_filter: badwords_regex[lang].search(text.lower()) — matching against lower-cased text.

Proposed fix

One line in get_badwords_filter_fn:

# Matching is done against lower-cased text (see `_badwords_filter`), so
# word list entries must be lower-cased as well. Some entries in the
# upstream lists are capitalized (e.g. in es/tr) and would never match
# otherwise.
words = [re.escape(w.lower()) for w in words]

The _BADWORDS_ALLOWLIST subtraction in c4.py is unaffected (its entries are already lower-case / CJK). Regression test added alongside, mirroring the existing test_badwords_filter style.

Related work

This is the same bug family already identified and fixed in other data-pipeline projects: huggingface/datatrove #529 (fixed in PR #591) and modelscope/data-juicer PR #1275. tfds is the third instance of this pattern.

Transparency note: this issue was investigated and drafted with AI assistance (Claude), including the wordlist analysis and reproduction.

Ngôn ngữ chính
Python
Star
4.6k
Fork
1.6k
Merge trung bình
14 giờ 3 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tensorflow/datasets

Tất cả issue của tensorflow/datasets

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.