kd13 commited on
Commit
63d5593
·
verified ·
1 Parent(s): 059f1cb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +91 -1
README.md CHANGED
@@ -17,4 +17,94 @@ tags:
17
  pretty_name: bookcorpus
18
  size_categories:
19
  - 10M<n<100M
20
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  pretty_name: bookcorpus
18
  size_categories:
19
  - 10M<n<100M
20
+ ---
21
+
22
+ # BookCorpus — Cleaned for Pre-training LLMs
23
+
24
+ A cleaned, deduplicated, document-segmented version of
25
+ [`SamuelYang/bookcorpus`](https://huggingface.co/datasets/SamuelYang/bookcorpus)
26
+
27
+ ## TL;DR
28
+
29
+ | Property | Value |
30
+ |---|---|
31
+ | Rows (sentences) | **33,649,142** |
32
+ | Documents (books) | **4,086** |
33
+ | Format | CSV, 3 columns: `doc_id`, `sent_id`, `text` |
34
+ | Language | English (lowercased) |
35
+ | Source | `SamuelYang/bookcorpus` (74,004,228 raw rows) |
36
+
37
+ ## Schema
38
+
39
+ | Column | Type | Description |
40
+ |---|---|---|
41
+ | `doc_id` | int | Inferred document/book identifier. Sentences sharing the same `doc_id` come from the same book. |
42
+ | `sent_id` | int | Sentence position within its document (0-indexed). Preserves original order. |
43
+ | `text` | string | Cleaned sentence text (lowercased, normalized). |
44
+
45
+ ## How to use it
46
+
47
+ ### Quick load
48
+
49
+ ```python
50
+ from datasets import load_dataset
51
+
52
+ ds = load_dataset("kd13/bookcorpus-clean", split="train")
53
+ print(ds[0])
54
+ # {'doc_id': 0, 'sent_id': 0, 'text': 'i wish i had a better answer ...'}
55
+ ```
56
+
57
+ ## Cleaning pipeline
58
+
59
+ Applied in this order to the source dataset:
60
+
61
+ 1. **Unicode + whitespace normalization** — NFKC normalization, collapse
62
+ consecutive whitespace, strip.
63
+ 2. **Document segmentation** — since the source is a flat stream of sentences
64
+ without book IDs, document boundaries are inferred from telltale markers
65
+ at the start of books:
66
+ - ISBN lines (e.g. `isbn : 1492913731`)
67
+ - Copyright declarations (`copyright 2013 ...`)
68
+ - `all rights reserved`
69
+ - `chapter 1`
70
+ 3. **Line-level filters** — sentences are dropped if they:
71
+ - have fewer than **20** or more than **1000** characters
72
+ - match boilerplate patterns (copyright, ISBN, "all rights reserved")
73
+ - have an alphabetic-character ratio below **0.6**
74
+ - have a digit ratio above **0.3**
75
+ - contain no alphabetic characters
76
+ 4. **Language filter** — cheap English stop-word ratio check (≥ 5% of tokens
77
+ must be in a small English stop-word set; short lines pass through).
78
+ 5. **Within-document exact dedup** — SHA-1 hashing drops repeated sentences
79
+ inside the same book (e.g. recurring chapter headers, section dividers).
80
+ Note: dedup is *not* applied globally — sentences like "he nodded." occur
81
+ legitimately across many books.
82
+ 6. **Document filter** — books with fewer than **8** surviving sentences are
83
+ dropped (not enough context for NSP).
84
+ 7. **Cross-document near-duplicate removal** — a SHA-1 fingerprint of each
85
+ document's first 5 sentences identifies same-book re-uploads; duplicates
86
+ are dropped.
87
+
88
+ ## Cleaning statistics
89
+
90
+ | Metric | Value |
91
+ |---|---|
92
+ | Raw rows (sentences) in source | 74,004,228 |
93
+ | Documents detected | 6,779 |
94
+ | Documents kept | **4,086** |
95
+ | Documents dropped (< 8 sentences) | 973 |
96
+ | Documents dropped (near-duplicate) | 1,720 |
97
+ | Sentences kept | **33,649,142** |
98
+
99
+ Drop rate: ~40% of detected documents removed (mostly same-book re-uploads
100
+ and too-short documents).
101
+
102
+ ## Source & licensing
103
+
104
+ - **Source dataset:** [`SamuelYang/bookcorpus`](https://huggingface.co/datasets/SamuelYang/bookcorpus)
105
+ - **Original corpus:** BookCorpus (Zhu et al., 2015), originally scraped from
106
+ Smashwords. The original BookCorpus has well-documented provenance and
107
+ consent concerns; downstream users should review them before commercial use.
108
+ - This cleaned derivative is released under the **MIT License** for the
109
+ cleaning code and structuring effort. The underlying text retains whatever
110
+ rights apply to the upstream source.