davanstrien HF Staff Claude Opus 4.5 commited on
Commit
f5b8667
·
1 Parent(s): 5c4289f

Simplify README to only document existing script

Browse files

Remove basic-stats.py documentation (file doesn't exist yet)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. README.md +13 -248
README.md CHANGED
@@ -3,250 +3,27 @@ viewer: false
3
  tags:
4
  - uv-script
5
  - dataset-statistics
6
- - data-quality
7
- - text-analysis
8
  license: apache-2.0
9
  ---
10
 
11
  # Dataset Statistics
12
 
13
- Calculate essential text statistics for HuggingFace datasets using streaming mode. No ML models, pure Python, works on datasets of any size.
14
 
15
  ## Scripts
16
 
17
- | Script | Description |
18
- |--------|-------------|
19
- | `basic-stats.py` | Essential text statistics (chars, words, sentences) for any dataset |
20
- | `finepdfs-stats.py` | Temporal analysis of educational quality in finepdfs-edu |
21
-
22
- ---
23
-
24
- ### `basic-stats.py` - Essential Text Statistics
25
-
26
- Calculate fundamental text statistics using pure Python (no ML dependencies). Uses streaming mode by default, so it works on datasets of any size without downloading the full dataset.
27
-
28
- **Statistics calculated:**
29
- - Character, word, line, sentence counts (per sample and total)
30
- - Streaming mean and standard deviation using Welford's algorithm
31
- - Character type distributions (alphanumeric, digits, punctuation, whitespace, special characters)
32
- - Length statistics (min, max)
33
- - Derived metrics (words per line, chars per word, words per sentence)
34
-
35
- **Features:**
36
- - ✅ Pure Python (no ML models required)
37
- - ✅ Streaming mode (constant memory usage)
38
- - ✅ Progress tracking with tqdm
39
- - ✅ Optional per-sample CSV output
40
- - ✅ Works on datasets of any size
41
- - ✅ Fast: ~10k-50k samples/sec on CPU
42
-
43
- ## Installation
44
-
45
- No installation needed! Just use `uv run`:
46
-
47
- ```bash
48
- # Run directly with uv
49
- uv run https://huggingface.co/datasets/uv-scripts/dataset-stats/raw/main/basic-stats.py --help
50
- ```
51
-
52
- ## Usage Examples
53
-
54
- ### Quick Test (10k samples)
55
-
56
- ```bash
57
- uv run basic-stats.py HuggingFaceFW/fineweb-edu --max-samples 10000
58
- ```
59
-
60
- ### Full Dataset Statistics
61
-
62
- ```bash
63
- uv run basic-stats.py allenai/c4 --split train
64
- ```
65
-
66
- ### Different Text Column
67
-
68
- ```bash
69
- uv run basic-stats.py username/dataset --text-column content
70
- ```
71
-
72
- ### Save Per-Sample Statistics
73
-
74
- ```bash
75
- uv run basic-stats.py username/dataset --per-sample --output-file my-stats.csv
76
- ```
77
-
78
- ### Using HF Jobs (for large datasets)
79
-
80
- ```bash
81
- hf jobs uv run \
82
- -e HF_TOKEN=$(python3 -c "from huggingface_hub import get_token; print(get_token())") \
83
- https://huggingface.co/datasets/uv-scripts/dataset-stats/raw/main/basic-stats.py \
84
- username/very-large-dataset --max-samples 100000
85
- ```
86
-
87
- ## Example Output
88
-
89
- ```json
90
- {
91
- "dataset": "HuggingFaceFW/fineweb-edu",
92
- "split": "train",
93
- "text_column": "text",
94
- "total_samples": 10000,
95
- "statistics": {
96
- "character_count": {
97
- "count": 10000,
98
- "mean": 3542.18,
99
- "std": 2134.52,
100
- "min": 120.0,
101
- "max": 45231.0
102
- },
103
- "word_count": {
104
- "count": 10000,
105
- "mean": 642.34,
106
- "std": 387.21,
107
- "min": 18.0,
108
- "max": 8234.0
109
- },
110
- "line_count": {
111
- "count": 10000,
112
- "mean": 28.5,
113
- "std": 16.3,
114
- "min": 2.0,
115
- "max": 234.0
116
- },
117
- "sentence_count": {
118
- "count": 10000,
119
- "mean": 24.7,
120
- "std": 14.2,
121
- "min": 1.0,
122
- "max": 187.0
123
- },
124
- "mean_word_length": {
125
- "count": 10000,
126
- "mean": 5.52,
127
- "std": 0.87,
128
- "min": 2.1,
129
- "max": 12.4
130
- }
131
- },
132
- "character_type_distribution": {
133
- "alphanumeric": 0.8234,
134
- "alphabetic": 0.7891,
135
- "digit": 0.0343,
136
- "uppercase": 0.0456,
137
- "lowercase": 0.9544,
138
- "whitespace": 0.1523,
139
- "punctuation": 0.0187,
140
- "special": 0.0056
141
- },
142
- "derived_metrics": {
143
- "avg_words_per_line": 22.54,
144
- "avg_chars_per_word": 5.52,
145
- "avg_words_per_sentence": 26.01
146
- }
147
- }
148
- ```
149
-
150
- ## Performance
151
-
152
- - **Speed**: ~10,000-50,000 samples/sec on CPU (depending on text length)
153
- - **Memory**: Constant O(1) memory usage (streaming statistics)
154
- - **Dependencies**: Pure Python + datasets library
155
- - **GPU**: Not needed
156
-
157
- ## Use Cases
158
-
159
- ### Understanding Dataset Characteristics
160
-
161
- Get a quick overview of your dataset's basic properties:
162
- ```bash
163
- uv run basic-stats.py username/my-dataset --max-samples 10000
164
- ```
165
-
166
- ### Comparing Datasets
167
-
168
- Generate statistics for multiple datasets to compare their characteristics:
169
- ```bash
170
- for dataset in "allenai/c4" "HuggingFaceFW/fineweb" "cerebras/SlimPajama-627B"; do
171
- uv run basic-stats.py $dataset --max-samples 50000
172
- done
173
- ```
174
-
175
- ### Quality Checking
176
-
177
- Check if your dataset has reasonable statistics before training:
178
- - Are word counts within expected range?
179
- - Is the character distribution reasonable?
180
- - Are there too many special characters (potential quality issues)?
181
-
182
- ### Setting Filter Thresholds
183
-
184
- Use the statistics to inform filtering decisions:
185
- - If mean word count is 500, you might filter out samples < 50 or > 10,000 words
186
- - If punctuation ratio is very low, might indicate low-quality text
187
- - Character type distributions can reveal encoding issues
188
-
189
- ## Command-Line Options
190
-
191
- ```
192
- usage: basic-stats.py [-h] [--split SPLIT] [--text-column TEXT_COLUMN]
193
- [--max-samples MAX_SAMPLES] [--per-sample]
194
- [--output-file OUTPUT_FILE] [--streaming]
195
- dataset
196
-
197
- positional arguments:
198
- dataset Dataset name (e.g., 'HuggingFaceFW/fineweb-edu') or local path
199
-
200
- optional arguments:
201
- -h, --help show this help message and exit
202
- --split SPLIT Dataset split to process (default: train)
203
- --text-column TEXT_COLUMN
204
- Name of the text column (default: text)
205
- --max-samples MAX_SAMPLES
206
- Maximum number of samples to process (for testing)
207
- --per-sample Save per-sample statistics to CSV file
208
- --output-file OUTPUT_FILE
209
- Output file for per-sample stats (default: dataset-stats.csv)
210
- --streaming Use streaming mode (default: True)
211
- ```
212
-
213
- ## Technical Details
214
-
215
- ### Welford's Algorithm
216
-
217
- The script uses Welford's algorithm for calculating streaming mean and variance. This provides:
218
- - Numerical stability (no catastrophic cancellation)
219
- - Constant memory usage (O(1))
220
- - Single-pass computation
221
- - Accurate results even for very large datasets
222
-
223
- ### Character Type Classification
224
-
225
- Character types are classified as:
226
- - **Alphanumeric**: Letters + digits
227
- - **Alphabetic**: Letters only
228
- - **Digit**: Numbers (0-9)
229
- - **Uppercase/Lowercase**: Case ratios (relative to total letters)
230
- - **Whitespace**: Spaces, tabs, newlines
231
- - **Punctuation**: Standard ASCII punctuation
232
- - **Special**: Everything else (emojis, symbols, etc.)
233
-
234
- ### Sentence Counting
235
-
236
- Simple heuristic-based sentence boundary detection using `.!?` as terminators. This is fast but not as accurate as NLP-based sentence tokenization. Good enough for statistical analysis.
237
-
238
- ---
239
-
240
  ### `finepdfs-stats.py` - Temporal Educational Quality Analysis
241
 
242
  Analyze educational quality trends across CommonCrawl dumps using Polars streaming. Answers: **"Is the web getting more educational over time?"**
243
 
244
  **Features:**
245
- - Polars streaming (no download of 300GB+ dataset)
246
- - Temporal analysis across 106 CommonCrawl dumps (2013-2025)
247
- - ASCII chart visualizations
248
- - Uploads results to HF Hub with auto-generated dataset card
249
- - Supports single language or all 70+ languages
250
 
251
  **Quick Examples:**
252
 
@@ -281,34 +58,22 @@ hf jobs uv run \
281
  - Single scan using Polars streaming
282
  - Works on HF Jobs CPU instances
283
 
284
- ---
285
-
286
  ## Related Scripts
287
 
288
- Check out other scripts in the `uv-scripts` organization:
289
  - **dataset-creation**: Create datasets from PDFs and other formats
290
  - **vllm**: GPU-accelerated classification and inference
291
  - **ocr**: Document OCR using vision-language models
292
 
293
- ## Contributing
294
-
295
- Have ideas for additional statistics or improvements? Feel free to:
296
- 1. Fork this repository
297
- 2. Add your script or improvements
298
- 3. Submit a pull request
299
-
300
- Or open an issue on the [uv-scripts organization](https://huggingface.co/uv-scripts).
301
-
302
- ## License
303
-
304
- Apache 2.0
305
-
306
  ## Why UV Scripts?
307
 
308
  UV scripts are self-contained Python scripts that:
309
  - Run with a single `uv run` command (no setup required)
310
  - Include all dependencies in PEP 723 inline metadata
311
  - Work seamlessly on both local machines and HF Jobs
312
- - Serve as educational examples of best practices
313
 
314
  Learn more about UV: https://docs.astral.sh/uv/
 
 
 
 
 
3
  tags:
4
  - uv-script
5
  - dataset-statistics
6
+ - polars
7
+ - temporal-analysis
8
  license: apache-2.0
9
  ---
10
 
11
  # Dataset Statistics
12
 
13
+ UV scripts for analyzing HuggingFace datasets using streaming mode.
14
 
15
  ## Scripts
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ### `finepdfs-stats.py` - Temporal Educational Quality Analysis
18
 
19
  Analyze educational quality trends across CommonCrawl dumps using Polars streaming. Answers: **"Is the web getting more educational over time?"**
20
 
21
  **Features:**
22
+ - Polars streaming (no download of 300GB+ dataset)
23
+ - Temporal analysis across 106 CommonCrawl dumps (2013-2025)
24
+ - ASCII chart visualizations
25
+ - Uploads results to HF Hub with auto-generated dataset card
26
+ - Supports single language or all 70+ languages
27
 
28
  **Quick Examples:**
29
 
 
58
  - Single scan using Polars streaming
59
  - Works on HF Jobs CPU instances
60
 
 
 
61
  ## Related Scripts
62
 
63
+ Check out other scripts in the [uv-scripts organization](https://huggingface.co/uv-scripts):
64
  - **dataset-creation**: Create datasets from PDFs and other formats
65
  - **vllm**: GPU-accelerated classification and inference
66
  - **ocr**: Document OCR using vision-language models
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  ## Why UV Scripts?
69
 
70
  UV scripts are self-contained Python scripts that:
71
  - Run with a single `uv run` command (no setup required)
72
  - Include all dependencies in PEP 723 inline metadata
73
  - Work seamlessly on both local machines and HF Jobs
 
74
 
75
  Learn more about UV: https://docs.astral.sh/uv/
76
+
77
+ ## License
78
+
79
+ Apache 2.0