Datasets:
File size: 1,189 Bytes
cfe406c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Full-corpus unique word count. Streams parquet batches into a set.
ponytail: lowercased surface forms (Polish is heavily inflected, so this is
'distinct word forms', not lemmas). Counts total words too.
"""
import re
import pyarrow.parquet as pq
SOURCES = ["eurlex", "parliamentary", "wikisource", "wikipedia",
"dziennik_ustaw", "wolne_lektury"]
WORD = re.compile(r"[^\W\d_]+", re.UNICODE) # unicode letters, no digits/punct
total_vocab = set()
total_words = 0
print(f"{'source':<16} {'words':>14} {'uniq forms':>13}")
for s in SOURCES:
pf = pq.ParquetFile(f"data/{s}/{s}.parquet")
src_vocab = set()
src_words = 0
for batch in pf.iter_batches(columns=["text"], batch_size=2000):
for t in batch.column("text").to_pylist():
if not t:
continue
w = WORD.findall(t.lower())
src_words += len(w)
src_vocab.update(w)
total_words += src_words
total_vocab |= src_vocab
print(f"{s:<16} {src_words:>14,} {len(src_vocab):>13,}", flush=True)
print(f"\n{'TOTAL (deduped)':<16} {total_words:>14,} {len(total_vocab):>13,}")
print(f"type/token ratio: {len(total_vocab)/total_words:.5f}")
|