C4 badwords filter: capitalized entries in upstream wordlists never match (text is lower-cased, list entries are not)
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 20/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python, tensorflow
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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:
c4.py(generate_pages):badwords[lang].update(l.strip() for l in f)— raw entries from the upstream list.c4_utils.py::get_badwords_filter_fn:words = [re.escape(w) for w in words]— no lower-casing.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.
- 主要语言
- Python
- 星标
- 4.6k
- 派生
- 1.6k
- 平均合并
- 14 小时 3 分钟
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/datasets 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
tensorflow/datasets#11260 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
tensorflow/datasets#11253 ·
-
DatasetInfo.read_from_directory reads the deprecated FieldDescriptor.label eagerly, warning on every open可能已有人在做 @jabrailkhalil 于 48 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
tensorflow/datasets#11245 · 1 条评论 ·
-
required dependency on importlib_resources missing可能已有人在做 @ArS377 于 128 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
tensorflow/datasets#11212 · 2 条评论 · 1 个 reaction ·
-
tfds.features.Audio eagerly imports TensorFlow in _AudioDecoder.__init__, breaking TensorFlow-less usage可能已有人在做 @raashish1601 于 54 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 76/100
tensorflow/datasets#11233 ·
查看 tensorflow/datasets 的全部 Issue
相似的 Issue
-
difficulty:1 documentation
难度 2/5 1-3 小时 新手友好度 82/100
MakazhanAlpamys/Soup#3533 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
onyx-dot-app/onyx#18730 ·
维护者通常 1 天内回复
-
namespace team:operations
难度 1/5 1 小时以内 新手友好度 65/100
EclipseFdn/open-vsx.org#16509 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
langflow-ai/langflow#16689 ·
维护者通常 1 天内回复
-
ScoringSystem.get() and compute() return NotImplementedError instead of raising it可能已有人在做 @sc-lacanlale 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 83/100
aboutcode-org/vulnerablecode#2552 ·
维护者通常 5 天内回复