kacperwikiel commited on
Commit
1432aeb
·
1 Parent(s): b2fb895

Add progress logging to HPLT filtering

Browse files
Files changed (1) hide show
  1. src/filter_european_hplt.py +13 -0
src/filter_european_hplt.py CHANGED
@@ -206,6 +206,7 @@ def parse_args() -> argparse.Namespace:
206
  ap.add_argument("--min-words", type=int, default=80)
207
  ap.add_argument("--max-boilerplate-hits", type=int, default=3)
208
  ap.add_argument("--include-legalish", action="store_true")
 
209
  ap.add_argument("--dry-run", action="store_true")
210
  return ap.parse_args()
211
 
@@ -255,6 +256,12 @@ def main() -> None:
255
  keep, reason = keep_row(row, args)
256
  if not keep:
257
  stats["drop"][reason] = stats["drop"].get(reason, 0) + 1
 
 
 
 
 
 
258
  continue
259
 
260
  registers = row.get("web-register") or {}
@@ -279,6 +286,12 @@ def main() -> None:
279
  batch.clear()
280
  if stats["kept"] >= args.max_records or stats["tokens"] >= args.max_tokens:
281
  break
 
 
 
 
 
 
282
  finally:
283
  if batch:
284
  if writer:
 
206
  ap.add_argument("--min-words", type=int, default=80)
207
  ap.add_argument("--max-boilerplate-hits", type=int, default=3)
208
  ap.add_argument("--include-legalish", action="store_true")
209
+ ap.add_argument("--progress-every", type=int, default=100_000)
210
  ap.add_argument("--dry-run", action="store_true")
211
  return ap.parse_args()
212
 
 
256
  keep, reason = keep_row(row, args)
257
  if not keep:
258
  stats["drop"][reason] = stats["drop"].get(reason, 0) + 1
259
+ if args.progress_every and stats["read"] % args.progress_every == 0:
260
+ print(
261
+ f"progress read={stats['read']:,} kept={stats['kept']:,} "
262
+ f"tokens={stats['tokens']:,} last_drop={reason}",
263
+ flush=True,
264
+ )
265
  continue
266
 
267
  registers = row.get("web-register") or {}
 
286
  batch.clear()
287
  if stats["kept"] >= args.max_records or stats["tokens"] >= args.max_tokens:
288
  break
289
+ if args.progress_every and stats["read"] % args.progress_every == 0:
290
+ print(
291
+ f"progress read={stats['read']:,} kept={stats['kept']:,} "
292
+ f"tokens={stats['tokens']:,}",
293
+ flush=True,
294
+ )
295
  finally:
296
  if batch:
297
  if writer: