Datasets:
File size: 1,235 Bytes
46e27b5 | 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 34 35 36 37 38 39 |
import glob, json, os, re
import pyarrow.parquet as pq
TERMINALS = set('.?!')
def is_eligible(s):
s = s.strip()
if not s or s[-1] not in TERMINALS:
return False
if any(c in s for c in ':;"“”‘’!—–()[]'):
return False
words = s.split()
if not (6 <= len(words) <= 24):
return False
if not words[0][0].isalpha() or not words[0][0].isupper():
return False
return True
gutenberg_count = 0
for f in glob.glob('/opt/vox/temp/downloads/clean_corpora/gutenberg_books/*.txt'):
for line in open(f, errors='ignore'):
line = line.strip()
if is_eligible(line):
gutenberg_count += 1
ubuntu_count = 0
if os.path.exists('/opt/vox/temp/downloads/clean_corpora/ubuntu_dialogue_qa/train.parquet'):
t = pq.read_table('/opt/vox/temp/downloads/clean_corpora/ubuntu_dialogue_qa/train.parquet')
for row in t.to_pylist():
txt = (row.get('question') or '') + ' ' + (row.get('answer') or '')
for part in txt.split('.'):
p = part.strip() + '.'
if is_eligible(p):
ubuntu_count += 1
print(f'Gutenberg eligible sentences: {gutenberg_count}')
print(f'Ubuntu eligible sentences: {ubuntu_count}')
|