Datasets:
humanizer v2 training data: SFT, DPO and RL rows used to train v2, split by license
Browse files- .gitattributes +2 -0
- README.md +156 -0
- dpo/noncommercial.jsonl +0 -0
- dpo/redistributable.jsonl +0 -0
- dpo/reference_only.jsonl +0 -0
- eval_drafts/test.jsonl +0 -0
- rewrite_sft/noncommercial.jsonl +0 -0
- rewrite_sft/redistributable.jsonl +3 -0
- rewrite_sft/reference_only.jsonl +3 -0
- rl_prompts/noncommercial.jsonl +0 -0
- rl_prompts/redistributable.jsonl +0 -0
- rl_prompts/reference_only.jsonl +0 -0
- scripts/rebuild_reference_only.py +265 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
rewrite_sft/redistributable.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
rewrite_sft/reference_only.jsonl filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: mixed-per-row
|
| 4 |
+
license_link: https://github.com/sgaofen/humanizer-local-model/blob/main/docs/DATA.md
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
- zh
|
| 8 |
+
pretty_name: humanizer training data (v2)
|
| 9 |
+
size_categories:
|
| 10 |
+
- 10K<n<100K
|
| 11 |
+
task_categories:
|
| 12 |
+
- text-generation
|
| 13 |
+
tags:
|
| 14 |
+
- rewriting
|
| 15 |
+
- paraphrase
|
| 16 |
+
- style-transfer
|
| 17 |
+
- dpo
|
| 18 |
+
- rlhf
|
| 19 |
+
configs:
|
| 20 |
+
- config_name: rewrite_sft
|
| 21 |
+
data_files:
|
| 22 |
+
- split: redistributable
|
| 23 |
+
path: rewrite_sft/redistributable.jsonl
|
| 24 |
+
- split: noncommercial
|
| 25 |
+
path: rewrite_sft/noncommercial.jsonl
|
| 26 |
+
- split: reference_only
|
| 27 |
+
path: rewrite_sft/reference_only.jsonl
|
| 28 |
+
- config_name: dpo
|
| 29 |
+
data_files:
|
| 30 |
+
- split: redistributable
|
| 31 |
+
path: dpo/redistributable.jsonl
|
| 32 |
+
- split: noncommercial
|
| 33 |
+
path: dpo/noncommercial.jsonl
|
| 34 |
+
- split: reference_only
|
| 35 |
+
path: dpo/reference_only.jsonl
|
| 36 |
+
- config_name: rl_prompts
|
| 37 |
+
data_files:
|
| 38 |
+
- split: redistributable
|
| 39 |
+
path: rl_prompts/redistributable.jsonl
|
| 40 |
+
- split: noncommercial
|
| 41 |
+
path: rl_prompts/noncommercial.jsonl
|
| 42 |
+
- split: reference_only
|
| 43 |
+
path: rl_prompts/reference_only.jsonl
|
| 44 |
+
- config_name: eval_drafts
|
| 45 |
+
data_files:
|
| 46 |
+
- split: test
|
| 47 |
+
path: eval_drafts/test.jsonl
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
# humanizer-data
|
| 51 |
+
|
| 52 |
+
Training data for **[humanizer](https://huggingface.co/jialinyyzz/humanizer) v2**, a 12B model that rewrites AI-written drafts (English and Chinese) so they read like a person wrote them, keeping every fact. Code and app: [GitHub](https://github.com/sgaofen/humanizer-local-model). How the data was built, step by step: **[docs/DATA.md](https://github.com/sgaofen/humanizer-local-model/blob/main/docs/DATA.md)** ([中文](https://github.com/sgaofen/humanizer-local-model/blob/main/docs/DATA.zh.md)).
|
| 53 |
+
|
| 54 |
+
Only rows that were actually used to train v2 are here, one config per training step:
|
| 55 |
+
|
| 56 |
+
| Config | Training step | Used in training | With text | Reference only | Removed before release |
|
| 57 |
+
|---|---|---|---|---|---|
|
| 58 |
+
| `rewrite_sft` | SFT: AI draft → human original | 28,560 | 5,471 | 21,632 | 1,457 |
|
| 59 |
+
| `dpo` | DPO: draft, chosen rewrite, rejected rewrite | 4,124 | 1,068 | 2,619 | 437 |
|
| 60 |
+
| `rl_prompts` | RL, three rounds: drafts only (the reward came from an LLM judge, no reference answer) | 5,299 | 1,264 | 3,744 | 291 |
|
| 61 |
+
| `eval_drafts` | Not trained on: the evaluation drafts from the model card, written from scratch by models | — | 311 | — | — |
|
| 62 |
+
|
| 63 |
+
## Splits are licenses
|
| 64 |
+
|
| 65 |
+
| Split | What | Rows (SFT / DPO / RL) |
|
| 66 |
+
|---|---|---|
|
| 67 |
+
| `redistributable` | Public-domain or openly licensed human text (U.S. government reports, CC BY, ODC-BY, Apache-2.0), plus drafts an AI wrote from a scenario with no human original. Full text. | 4,932 / 821 / 965 |
|
| 68 |
+
| `noncommercial` | CC BY-NC-SA human text (PERSUADE 2.0, wikiHow, OpenStax). Full text; **non-commercial, share-alike**. | 539 / 247 / 299 |
|
| 69 |
+
| `reference_only` | Sources whose license does not let us pass the text on. **No text**: source dataset, record ID/URL where we could recover it, SHA-256 and length of the exact text we trained on. The draft is withheld too (it is a close rewrite of the original). Rebuild with [`scripts/rebuild_reference_only.py`](https://github.com/sgaofen/humanizer-local-model/blob/main/scripts/rebuild_reference_only.py). | 21,632 / 2,619 / 3,744 |
|
| 70 |
+
|
| 71 |
+
Every row has a `license` and `tier` column; follow the license of each row. In `rewrite_sft` and `dpo`, `split` = `train` or `validation` (validation rows only measured loss to pick the checkpoint).
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
from datasets import load_dataset
|
| 75 |
+
sft = load_dataset("jialinyyzz/humanizer-data", "rewrite_sft", split="redistributable")
|
| 76 |
+
print(sft[0]["draft"][:300], "\n---\n", sft[0]["original"][:300])
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Sources
|
| 80 |
+
|
| 81 |
+
| Source | License | Tier | Rows published (SFT / DPO / RL) |
|
| 82 |
+
|---|---|---|---|
|
| 83 |
+
| [Congressional Research Service reports](https://www.everycrsreport.com/) | Public domain (U.S. federal government work) | A · redistributable | 3,490 / 216 / 58 |
|
| 84 |
+
| [eLife peer reviews and decision letters](https://github.com/elifesciences/elife-article-xml) | CC BY 4.0 (eLife) | A · redistributable | 1,268 / 52 / 12 |
|
| 85 |
+
| [NTSB aviation accident narratives](https://data.ntsb.gov/avdata) | Public domain (U.S. federal government work) | A · redistributable | – / 95 / 147 |
|
| 86 |
+
| [Apache Software Foundation board minutes](https://www.apache.org/foundation/records/minutes/) | Apache-2.0 (The Apache Software Foundation) | A · redistributable | – / 99 / 142 |
|
| 87 |
+
| [Project Gutenberg](https://www.gutenberg.org/policy/license.html) | Public domain in the U.S. (Project Gutenberg, headers removed) | A · redistributable | – / – / 194 |
|
| 88 |
+
| [PeerRead (ACL 2017 / CoNLL 2016 reviews)](https://github.com/allenai/PeerRead) | CC BY 4.0 | A · redistributable | 94 / 32 / – |
|
| 89 |
+
| [peS2o (s2orc open-access subset)](https://huggingface.co/datasets/allenai/peS2o) | ODC-BY 1.0 | A · redistributable | 80 / 2 / 7 |
|
| 90 |
+
| [NIH RePORTER project abstracts](https://reporter.nih.gov/) | ODbL 1.0 (NIH RePORTER on data.gov) | A · redistributable | – / – / 46 |
|
| 91 |
+
| [NSF award abstracts](https://www.nsf.gov/awardsearch/) | Public domain (U.S. federal government work); NSF award abstracts | A · redistributable | – / – / 19 |
|
| 92 |
+
| AI-written from a scenario prompt (no human original) | AI-generated draft; see model terms | A · AI-written | – / 325 / 340 |
|
| 93 |
+
| [PERSUADE 2.0](https://github.com/scrosseye/persuade_corpus_2.0) | CC BY-NC-SA 4.0 | B · non-commercial | 539 / 219 / 232 |
|
| 94 |
+
| [wikiHow](https://www.wikihow.com/wikiHow:Creative-Commons) | CC BY-NC-SA 3.0 (wikiHow) | B · non-commercial | – / 28 / 66 |
|
| 95 |
+
| [OpenStax textbooks](https://help.openstax.org/s/article/Licensing-information-of-OpenStax-textbooks) | CC BY-NC-SA 4.0 (OpenStax) | B · non-commercial | – / – / 1 |
|
| 96 |
+
| [PubMed abstracts (via MedRAG/pubmed)](https://huggingface.co/datasets/MedRAG/pubmed) | Publisher/author copyright (NLM does not grant rights) | C · reference only | 4,933 / 327 / 115 |
|
| 97 |
+
| [python-dev mailing list archive](https://mail.python.org/pipermail/python-dev/) | No license (each sender holds copyright) | C · reference only | 4,289 / 507 / 28 |
|
| 98 |
+
| [Zhihu-KOL (Zhihu answers)](https://huggingface.co/datasets/bzb2023/Zhihu-KOL-More-Than-100-Upvotes) | No license (Zhihu user content) | C · reference only | 2,161 / 182 / 143 |
|
| 99 |
+
| [COIG-CQIA](https://huggingface.co/datasets/m-a-p/COIG-CQIA) | No license stated (mixed platform content) | C · reference only | 1,953 / 160 / 126 |
|
| 100 |
+
| [Blog Authorship Corpus](https://u.cs.biu.ac.il/~koppel/BlogCorpus.htm) | Non-commercial research use; redistribution not granted | C · reference only | 1,791 / 135 / 254 |
|
| 101 |
+
| [AESLC / Enron email](https://huggingface.co/datasets/Yale-LILY/aeslc) | No license stated | C · reference only | 1,641 / 336 / 83 |
|
| 102 |
+
| [Enron email corpus (CMU)](https://www.cs.cmu.edu/~enron/) | No license stated | C · reference only | 1,657 / 231 / 82 |
|
| 103 |
+
| [Hacker News comments](https://news.ycombinator.com/) | Hacker News terms (no redistribution) | C · reference only | 1,260 / 159 / 5 |
|
| 104 |
+
| [Webis-TLDR-17 (Reddit)](https://huggingface.co/datasets/webis/tldr-17) | CC BY 4.0 from the aggregator over Reddit user content (not cleared with authors) | C · reference only | 923 / 67 / 173 |
|
| 105 |
+
| [CSL (Chinese scientific abstracts)](https://github.com/ydli-ai/CSL) | Journal/author copyright | C · reference only | 491 / 53 / 315 |
|
| 106 |
+
| [Webis-CMV-20 (Reddit r/changemyview)](https://zenodo.org/records/3778298) | CC BY 4.0 from the aggregator over Reddit user content (not cleared with authors) | C · reference only | – / 38 / 439 |
|
| 107 |
+
| [IMDb Large Movie Review Dataset](https://ai.stanford.edu/~amaas/data/sentiment/) | No license stated (IMDb user content) | C · reference only | 286 / 24 / – |
|
| 108 |
+
| [Listed-company announcements (Duxiaoman-DI/FinCorpus)](https://huggingface.co/datasets/Duxiaoman-DI/FinCorpus) | Aggregator license; content not cleared | C · reference only | – / – / 308 |
|
| 109 |
+
| [Stack Exchange data dump (2021)](https://archive.org/details/stackexchange) | CC BY-SA, but author attribution not kept in our copy | C · reference only | – / 90 / 207 |
|
| 110 |
+
| [Amazon Reviews 2023 (McAuley Lab)](https://amazon-reviews-2023.github.io/) | No license stated (user content) | C · reference only | – / 57 / 222 |
|
| 111 |
+
| [Paul Graham essays](https://www.paulgraham.com/articles.html) | All rights reserved | C · reference only | 246 / 20 / – |
|
| 112 |
+
| [NASA ASRS report narratives](https://asrs.arc.nasa.gov/) | No written license for reporter narratives | C · reference only | – / 101 / 156 |
|
| 113 |
+
| [ASAP-AES (Kaggle)](https://www.kaggle.com/c/asap-aes) | Kaggle competition data (no redistribution) | C · reference only | – / 70 / 161 |
|
| 114 |
+
| [MNBVC (Tianya forum)](https://huggingface.co/datasets/liwu/MNBVC) | Aggregator license; content not cleared | C · reference only | – / 3 / 227 |
|
| 115 |
+
| [Tweets (enryu43/twitter100m_tweets)](https://huggingface.co/datasets/enryu43/twitter100m_tweets) | X/Twitter terms (post IDs only) | C · reference only | – / – / 156 |
|
| 116 |
+
| [LinkedIn posts (Kaggle)](https://www.linkedin.com/legal/user-agreement) | Platform terms (no redistribution) | C · reference only | – / – / 139 |
|
| 117 |
+
| [People's Daily commentaries (Papersnake/people_daily_news)](https://huggingface.co/datasets/Papersnake/people_daily_news) | People's Daily copyright | C · reference only | – / 2 / 117 |
|
| 118 |
+
| [THUCNews (Sina News)](http://thuctc.thunlp.org/) | Sina News copyright; commercial use needs a license | C · reference only | – / 8 / 94 |
|
| 119 |
+
| [Dianping reviews (yf_dianping)](https://github.com/SophonPlus/ChineseNlpCorpus) | No license (user content) | C · reference only | – / 1 / 75 |
|
| 120 |
+
| [Yelp reviews (Yelp/yelp_review_full)](https://huggingface.co/datasets/Yelp/yelp_review_full) | Yelp dataset agreement (no redistribution) | C · reference only | – / – / 76 |
|
| 121 |
+
| [CNN/DailyMail](https://huggingface.co/datasets/abisee/cnn_dailymail) | Article copyright retained by CNN / Daily Mail | C · reference only | – / 47 / 4 |
|
| 122 |
+
| [nlp_chinese_corpus (brightmart)](https://github.com/brightmart/nlp_chinese_corpus) | Aggregator license; content not cleared | C · reference only | – / – / 14 |
|
| 123 |
+
| [NUS Corpus of Learner English](https://www.comp.nus.edu.sg/~nlp/conll14st/nucle_license.pdf) | NUS license (non-sublicensable) | C · reference only | – / – / 13 |
|
| 124 |
+
| [WritingPrompts (Reddit)](https://huggingface.co/datasets/euclaise/writingprompts) | Aggregator license over Reddit user content | C · reference only | – / – / 10 |
|
| 125 |
+
| Mixed academic text | Mixed source; not redistributed | C · reference only | 1 / 1 / 2 |
|
| 126 |
+
|
| 127 |
+
## AI-written side: check the model terms
|
| 128 |
+
|
| 129 |
+
Drafts were written by GLM-5.3, GPT-5.6 Luna, Claude Opus, Claude Sonnet and Muse Spark (`draft_model` column); the DPO rewrites came from earlier checkpoints of humanizer and were judged by GLM-5.3 or GPT-5.6 Luna. These providers restrict using outputs to train other models (Anthropic and OpenAI: no competing models; Zhipu's mainland-China platform: no training of other models at all). Links in [DATA.md](https://github.com/sgaofen/humanizer-local-model/blob/main/docs/DATA.md#model-terms-for-the-ai-written-side). You are responsible for complying with them.
|
| 130 |
+
|
| 131 |
+
## Privacy
|
| 132 |
+
|
| 133 |
+
All text fields were scanned before release. Rows mentioning the project author were removed everywhere; rows with any email address, phone number or ID number were removed from the two splits that carry text. Some openly licensed sources (U.S. government reports, Apache board minutes) name public officials and contributors, as in the originals.
|
| 134 |
+
|
| 135 |
+
## Dates
|
| 136 |
+
|
| 137 |
+
v2 was trained on 178 rows (SFT / DPO / RL: 167 / 8 / 3) whose Zhihu answer is dated after 2022-11-30 (for the Zhihu subset of COIG-CQIA the date is inferred from the answer ID), 1,426 rows (1,148 / 169 / 109) whose peS2o paper is dated after 2022-11-30 (1,396 of them in December 2022), and 11 rows from CRS reports whose latest version is dated after 2022-11-30. All of these are left out of this release. 1,879 human texts have no date we could check, mostly the non-Zhihu parts of COIG-CQIA (1,817); they are kept.
|
| 138 |
+
|
| 139 |
+
## Limitations
|
| 140 |
+
|
| 141 |
+
- Most human text is reference-only; rebuilding it depends on upstream sources staying online, and our texts are often tidied excerpts, so a rebuild may differ slightly.
|
| 142 |
+
- The judges are LLMs: strict, sometimes flagging harmless rewording, and they miss some errors. No AI detector was used anywhere.
|
| 143 |
+
- The SFT side leans formal (abstracts, reports, email).
|
| 144 |
+
|
| 145 |
+
## Citation
|
| 146 |
+
|
| 147 |
+
```bibtex
|
| 148 |
+
@misc{humanizer2026data,
|
| 149 |
+
title = {humanizer-data: training data for the humanizer rewriting model (v2)},
|
| 150 |
+
author = {Stephen Yu},
|
| 151 |
+
year = {2026},
|
| 152 |
+
url = {https://huggingface.co/datasets/jialinyyzz/humanizer-data}
|
| 153 |
+
}
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
Please also cite the upstream datasets you use.
|
dpo/noncommercial.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dpo/redistributable.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dpo/reference_only.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
eval_drafts/test.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
rewrite_sft/noncommercial.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
rewrite_sft/redistributable.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d75127abb5dadc2a693f3b55d703c39c22fa634d5db5b7ceeb86da03fc72fa0a
|
| 3 |
+
size 32405275
|
rewrite_sft/reference_only.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2422f77eeb38cabcc5a131d5c43d3d063e3dfdb9f3dc861fe2278cd6b56fe55
|
| 3 |
+
size 12381779
|
rl_prompts/noncommercial.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
rl_prompts/redistributable.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
rl_prompts/reference_only.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/rebuild_reference_only.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Rebuild the reference-only rows of jialinyyzz/humanizer-data.
|
| 3 |
+
|
| 4 |
+
Those rows carry no text because the source license does not let us pass it on. Each row has
|
| 5 |
+
`upstream_dataset`, `upstream_id` and (often) `upstream_url`; this script fetches the original record
|
| 6 |
+
from its public source and checks it against `original_sha256`.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
pip install datasets requests pyarrow huggingface_hub
|
| 10 |
+
python scripts/rebuild_reference_only.py --config rewrite_sft --out rebuilt_sft.jsonl [--only MedRAG/pubmed] [--limit 100]
|
| 11 |
+
python scripts/rebuild_reference_only.py --input reference_only.jsonl --out rebuilt.jsonl # a local copy of the split
|
| 12 |
+
|
| 13 |
+
Output, one line per row: {id, upstream_dataset, upstream_id, how, text, sha256_match, error?}
|
| 14 |
+
|
| 15 |
+
Notes:
|
| 16 |
+
* You get the whole upstream record. The text we trained on is often an excerpt of it with whitespace,
|
| 17 |
+
hard line breaks, quoted replies and signatures tidied, so `sha256_match` is false for many rows even
|
| 18 |
+
when the record is the right one. `sha256_match` compares the lower-cased, whitespace-collapsed text.
|
| 19 |
+
* Row-index IDs ("[config:]split:N") are 0-based positions in the upstream Hugging Face dataset
|
| 20 |
+
(the `row_idx` of the datasets-server /rows API).
|
| 21 |
+
* Some sources must be downloaded by hand or need you to accept terms first (PERSUADE 2.0, the Enron
|
| 22 |
+
archive, Kaggle data, NUCLE, large corpora); the script reports what to do for those rows.
|
| 23 |
+
* Respect each source's license and terms. These rows are reference-only for a reason.
|
| 24 |
+
"""
|
| 25 |
+
import csv, gzip, html, io, json, os, re, sys, time, urllib.parse, urllib.request
|
| 26 |
+
|
| 27 |
+
UA = 'humanizer-data-rebuild/1.0'
|
| 28 |
+
ROWS_API = 'https://datasets-server.huggingface.co/rows'
|
| 29 |
+
HF_TOKEN = os.environ.get('HF_TOKEN')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def http(url, data=None, headers=None, tries=5):
|
| 33 |
+
h = {'User-Agent': UA}
|
| 34 |
+
if headers: h.update(headers)
|
| 35 |
+
for a in range(tries):
|
| 36 |
+
try:
|
| 37 |
+
with urllib.request.urlopen(urllib.request.Request(url, data=data, headers=h), timeout=120) as r:
|
| 38 |
+
return r.read()
|
| 39 |
+
except urllib.error.HTTPError as e:
|
| 40 |
+
if e.code == 404: raise
|
| 41 |
+
time.sleep(45 if e.code == 429 else 3 * (a + 1))
|
| 42 |
+
except Exception:
|
| 43 |
+
time.sleep(3 * (a + 1))
|
| 44 |
+
raise RuntimeError(f'fetch failed: {url}')
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def hf_row(ds, cfg, split, idx, revision=None):
|
| 48 |
+
q = {'dataset': ds, 'config': cfg, 'split': split, 'offset': int(idx), 'length': 1}
|
| 49 |
+
hd = {'Authorization': f'Bearer {HF_TOKEN}'} if HF_TOKEN else None
|
| 50 |
+
j = json.loads(http(f'{ROWS_API}?{urllib.parse.urlencode(q)}', headers=hd))
|
| 51 |
+
rows = j.get('rows') or []
|
| 52 |
+
if not rows: raise LookupError(f'{ds} {cfg}/{split} row {idx} not found')
|
| 53 |
+
r = rows[0]
|
| 54 |
+
if r.get('truncated_cells'): # the rows API truncates very large cells
|
| 55 |
+
raise LookupError(f'{ds} row {idx}: cell truncated by the rows API; download the parquet file instead')
|
| 56 |
+
return r['row']
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def parse_rowid(uid, default_cfg='default'):
|
| 60 |
+
p = uid.split(':')
|
| 61 |
+
if len(p) == 2: return default_cfg, p[0], int(p[1])
|
| 62 |
+
return p[0], p[1], int(p[2])
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def hf_file(repo, path, revision='main'):
|
| 66 |
+
"""Download one file from a Hugging Face dataset repo (cached)."""
|
| 67 |
+
try:
|
| 68 |
+
from huggingface_hub import hf_hub_download
|
| 69 |
+
return open(hf_hub_download(repo, path, repo_type='dataset', revision=revision), 'rb').read()
|
| 70 |
+
except ImportError:
|
| 71 |
+
url = f'https://huggingface.co/datasets/{repo}/resolve/{urllib.parse.quote(revision, safe="")}/{path}'
|
| 72 |
+
return http(url)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------- per-source fetchers
|
| 76 |
+
def get_rowindex(ds, field, default_cfg='default', post=None):
|
| 77 |
+
def f(r):
|
| 78 |
+
cfg, split, i = parse_rowid(r['upstream_id'], default_cfg)
|
| 79 |
+
t = hf_row(ds, cfg, split, i)[field]
|
| 80 |
+
return post(t) if post else t
|
| 81 |
+
return f
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_hn(r):
|
| 85 |
+
j = json.loads(http(f"https://hacker-news.firebaseio.com/v0/item/{r['upstream_id']}.json"))
|
| 86 |
+
return j.get('text')
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
_medrag = {}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def get_pubmed(r):
|
| 93 |
+
m = re.match(r'(pubmed\d+n\d+)_(\d+)$', r['upstream_id'])
|
| 94 |
+
if m:
|
| 95 |
+
fn, k = m.group(1), int(m.group(2))
|
| 96 |
+
if fn not in _medrag:
|
| 97 |
+
_medrag[fn] = hf_file('MedRAG/pubmed', f'chunk/{fn}.jsonl').decode().splitlines()
|
| 98 |
+
o = json.loads(_medrag[fn][k])
|
| 99 |
+
assert o['id'] == r['upstream_id'], 'MedRAG id mismatch'
|
| 100 |
+
return o['contents']
|
| 101 |
+
pmid = re.search(r'/(\d+)/?$', r.get('upstream_url') or '').group(1) # fallback: NCBI E-utilities (format differs from MedRAG)
|
| 102 |
+
return http(f'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id={pmid}&rettype=abstract&retmode=text').decode()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def get_gutenberg2(r):
|
| 106 |
+
k = int(r['upstream_id'].split(':')[1])
|
| 107 |
+
return json.loads(hf_file('nbeerbower/gutenberg2-dpo', 'gb2_2024_11_16.json'))[k]['chosen']
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
_small = {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def get_by_col(repo, path, col, field, kind):
|
| 114 |
+
"""Download a small file once and index it by a column."""
|
| 115 |
+
def f(r):
|
| 116 |
+
key = (repo, path)
|
| 117 |
+
if key not in _small:
|
| 118 |
+
b = hf_file(repo, path)
|
| 119 |
+
if kind == 'parquet':
|
| 120 |
+
import pyarrow.parquet as pq
|
| 121 |
+
rows = pq.read_table(io.BytesIO(b)).to_pylist()
|
| 122 |
+
else:
|
| 123 |
+
rows = list(csv.DictReader(io.StringIO(b.decode('utf-8'))))
|
| 124 |
+
_small[key] = {str(x[col]): x for x in rows}
|
| 125 |
+
return _small[key][r['upstream_id']][field]
|
| 126 |
+
return f
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def get_peerread(r):
|
| 130 |
+
path, k = r['upstream_id'].split('#')
|
| 131 |
+
j = json.loads(http(f'https://raw.githubusercontent.com/allenai/PeerRead/master/data/{path}'))
|
| 132 |
+
return j['reviews'][int(k)]['comments']
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
_crs = {}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def get_crs(r):
|
| 139 |
+
if not _crs:
|
| 140 |
+
for row in csv.DictReader(io.StringIO(http('https://www.everycrsreport.com/reports.csv').decode('utf-8'))):
|
| 141 |
+
_crs[row['number']] = row
|
| 142 |
+
h = http('https://www.everycrsreport.com/' + _crs[r['upstream_id']]['latestHTML']).decode('utf-8', 'replace')
|
| 143 |
+
t = re.sub(r'(?i)<br\s*/?>', '\n', h); t = re.sub(r'(?i)</p>', '\n\n', t); t = re.sub(r'<[^>]+>', '', t)
|
| 144 |
+
return re.sub(r'\n{3,}', '\n\n', re.sub(r'[ \t]+', ' ', html.unescape(t))).strip()
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def get_elife(r):
|
| 148 |
+
x = http('https://raw.githubusercontent.com/elifesciences/elife-article-xml/master/' + r['upstream_id']).decode()
|
| 149 |
+
m = re.search(r'<sub-article[^>]*article-type="decision-letter".*?</sub-article>', x, re.S)
|
| 150 |
+
return html.unescape(re.sub(r'<[^>]+>', ' ', m.group(0))) if m else None
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
_mbox = {}
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def get_pipermail(r):
|
| 157 |
+
lst, date, subj = r['upstream_id'].split('|', 2)
|
| 158 |
+
url = r['upstream_url']
|
| 159 |
+
if url not in _mbox:
|
| 160 |
+
try: raw = http(url)
|
| 161 |
+
except urllib.error.HTTPError: raw = gzip.decompress(http(url + '.gz'))
|
| 162 |
+
_mbox[url] = re.split(r'\n(?=From \S+ at \S+ )', raw.decode('utf-8', 'replace'))
|
| 163 |
+
for msg in _mbox[url]:
|
| 164 |
+
if f'\nDate: {date}' in msg and subj.strip() in re.sub(r'\s+', ' ', msg[:2000]):
|
| 165 |
+
return msg.split('\n\n', 1)[1] if '\n\n' in msg else msg # message body (quoted replies and signatures were removed for training)
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def get_gutenberg_chunk(r):
|
| 170 |
+
bid, k = re.match(r'(\d+)#chunk(\d+)', r['upstream_id']).groups()
|
| 171 |
+
txt = http(f'https://www.gutenberg.org/cache/epub/{bid}/pg{bid}.txt').decode('utf-8', 'replace')
|
| 172 |
+
return {'book_text': txt, 'chunk_index': int(k), 'note': 'whole book; strip the Project Gutenberg header/footer, split into ~3,500-character chunks on paragraph breaks and take chunk k'}
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
_barilan = {}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def get_barilan(r):
|
| 179 |
+
"""Script-based dataset: read row N of the converted parquet shard."""
|
| 180 |
+
if not _barilan:
|
| 181 |
+
import pyarrow.parquet as pq
|
| 182 |
+
b = hf_file('barilan/blog_authorship_corpus', 'blog_authorship_corpus/train/0000.parquet', revision='refs/convert/parquet')
|
| 183 |
+
_barilan['t'] = pq.read_table(io.BytesIO(b), columns=['text'])
|
| 184 |
+
return _barilan['t'].column('text')[int(r['upstream_id'].split(':')[1])].as_py()
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def manual(why):
|
| 188 |
+
def f(r): raise NotImplementedError(why)
|
| 189 |
+
return f
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
RECIPES = [ # (upstream_dataset prefix, fetcher)
|
| 193 |
+
('Yale-LILY/aeslc', get_rowindex('Yale-LILY/aeslc', 'email_body')),
|
| 194 |
+
('barilan/blog_authorship_corpus (data/blogs.zip', manual('download blogs.zip from barilan/blog_authorship_corpus; upstream_id = blog:<blogger id>:<post index>')),
|
| 195 |
+
('barilan/blog_authorship_corpus', get_barilan),
|
| 196 |
+
('tasksource/blog_authorship_corpus', lambda r: get_rowindex('tasksource/blog_authorship_corpus', 'text')(r)
|
| 197 |
+
if r['upstream_id'].startswith('train:') else manual('tasksource/blog_authorship_corpus: upstream_id = blog_<id>_<row>; look the row up in the CSV')(r)),
|
| 198 |
+
('stanfordnlp/imdb', get_rowindex('stanfordnlp/imdb', 'text', 'plain_text', post=lambda t: t.replace('<br />', '\n'))),
|
| 199 |
+
('euclaise/WritingPrompts_curated', get_rowindex('euclaise/WritingPrompts_curated', 'body')),
|
| 200 |
+
('m-a-p/COIG-CQIA', get_rowindex('m-a-p/COIG-CQIA', 'output')),
|
| 201 |
+
('nbeerbower/gutenberg2-dpo', get_gutenberg2),
|
| 202 |
+
('OpenPipe/hacker-news', get_hn),
|
| 203 |
+
('MedRAG/pubmed', get_pubmed),
|
| 204 |
+
('jondurbin/gutenberg-dpo-v0.1', get_by_col('jondurbin/gutenberg-dpo-v0.1', 'gutenberg-dpo.parquet', 'id', 'chosen', 'parquet')),
|
| 205 |
+
('sgoel9/paul_graham_essays', get_by_col('sgoel9/paul_graham_essays', 'pual_graham_essays.csv', 'id', 'text', 'csv')),
|
| 206 |
+
('allenai/PeerRead', get_peerread),
|
| 207 |
+
('EveryCRSReport.com', get_crs),
|
| 208 |
+
('elifesciences/elife-article-xml', get_elife),
|
| 209 |
+
('python-dev pipermail', get_pipermail), ('python-ideas pipermail', get_pipermail),
|
| 210 |
+
('Project Gutenberg', get_gutenberg_chunk),
|
| 211 |
+
('allenai/peS2o', manual('large: stream allenai/peS2o (v2) and filter by id; collect all ids first and scan once')),
|
| 212 |
+
('neuclir/csl', manual('download neuclir/csl (csl split) and filter by doc_id')),
|
| 213 |
+
('bzb2023/Zhihu-KOL', manual('download the parquet shards and filter on METADATA.answer_id')),
|
| 214 |
+
('webis/tldr-17', manual('large: filter the refs/convert/parquet shards by id')),
|
| 215 |
+
('abisee/cnn_dailymail', manual('config 3.0.0, train split: filter by id')),
|
| 216 |
+
('Enron Email Dataset', manual('download enron_mail_20150507.tar.gz from CMU and read the maildir path in upstream_id')),
|
| 217 |
+
('PERSUADE 2.0', manual('get the CSV linked from the PERSUADE 2.0 README and look up essay_id_comp')),
|
| 218 |
+
]
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def resolve(r):
|
| 224 |
+
ds = r.get('upstream_dataset') or ''
|
| 225 |
+
for pre, fn in RECIPES:
|
| 226 |
+
if ds.startswith(pre): return fn, pre
|
| 227 |
+
url = r.get('upstream_url')
|
| 228 |
+
return manual(f'open upstream_url ({url}) or look the id up in {ds}' if url else f'look the id up in {ds}'), 'manual'
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def norm(t): return re.sub(r'\s+', ' ', t).strip().lower()
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def main():
|
| 235 |
+
import argparse, hashlib
|
| 236 |
+
ap = argparse.ArgumentParser()
|
| 237 |
+
ap.add_argument('--config', choices=['rewrite_sft', 'dpo', 'rl_prompts'])
|
| 238 |
+
ap.add_argument('--input', help='local jsonl of reference_only rows instead of --config')
|
| 239 |
+
ap.add_argument('--out', required=True); ap.add_argument('--only'); ap.add_argument('--limit', type=int)
|
| 240 |
+
a = ap.parse_args()
|
| 241 |
+
if a.input:
|
| 242 |
+
rows = [json.loads(l) for l in open(a.input, encoding='utf-8') if l.strip()]
|
| 243 |
+
else:
|
| 244 |
+
from datasets import load_dataset
|
| 245 |
+
rows = load_dataset('jialinyyzz/humanizer-data', a.config, split='reference_only')
|
| 246 |
+
n = ok = 0
|
| 247 |
+
with open(a.out, 'w', encoding='utf-8') as w:
|
| 248 |
+
for r in rows:
|
| 249 |
+
if not r.get('upstream_id'): continue
|
| 250 |
+
if a.only and not (r.get('upstream_dataset') or '').startswith(a.only): continue
|
| 251 |
+
fn, how = resolve(r)
|
| 252 |
+
rec = {'id': r['id'], 'upstream_dataset': r['upstream_dataset'], 'upstream_id': r['upstream_id'], 'how': how}
|
| 253 |
+
try:
|
| 254 |
+
t = fn(r); rec['text'] = t
|
| 255 |
+
rec['sha256_match'] = isinstance(t, str) and hashlib.sha256(norm(t).encode()).hexdigest() == r.get('original_sha256')
|
| 256 |
+
ok += bool(t)
|
| 257 |
+
except Exception as e:
|
| 258 |
+
rec['text'] = None; rec['error'] = f'{type(e).__name__}: {e}'[:300]
|
| 259 |
+
w.write(json.dumps(rec, ensure_ascii=False) + '\n'); n += 1
|
| 260 |
+
if a.limit and n >= a.limit: break
|
| 261 |
+
print(f'{n} rows, {ok} fetched -> {a.out}')
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
if __name__ == '__main__':
|
| 265 |
+
main()
|