File size: 712 Bytes
4dca11c | 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 | from datasets import load_dataset
import json
ds = load_dataset("wikimedia/wikipedia", "20231101.en")
def get_text(text):
arr = text.split('\n\n')
if len(arr) == 1:
return text
else:
return "\n\n".join(arr[:2])
url = [get_text(t) for t in ds['train']['url']]
train = [get_text(t) for t in ds['train']['text']]
title = [t for t in ds['train']['title']]
with open("wikipedia-title-20231101-en.txt", "w") as f:
for l in title:
print(json.dumps(l), file=f)
with open("wikipedia-text-20231101-en.txt", "w") as f:
for l in train:
print(json.dumps(l), file=f)
with open("wikipedia-url-20231101-en.txt", "w") as f:
for l in url:
print(l, file=f)
|