Upload wikipedia.py with huggingface_hub
Browse files- wikipedia.py +31 -0
wikipedia.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import load_dataset
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
ds = load_dataset("wikimedia/wikipedia", "20231101.en")
|
| 5 |
+
|
| 6 |
+
def get_text(text):
|
| 7 |
+
arr = text.split('\n\n')
|
| 8 |
+
if len(arr) == 1:
|
| 9 |
+
return text
|
| 10 |
+
else:
|
| 11 |
+
return "\n\n".join(arr[:2])
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
url = [get_text(t) for t in ds['train']['url']]
|
| 16 |
+
train = [get_text(t) for t in ds['train']['text']]
|
| 17 |
+
title = [t for t in ds['train']['title']]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
with open("wikipedia-title-20231101-en.txt", "w") as f:
|
| 21 |
+
for l in title:
|
| 22 |
+
print(json.dumps(l), file=f)
|
| 23 |
+
|
| 24 |
+
with open("wikipedia-text-20231101-en.txt", "w") as f:
|
| 25 |
+
for l in train:
|
| 26 |
+
print(json.dumps(l), file=f)
|
| 27 |
+
|
| 28 |
+
with open("wikipedia-url-20231101-en.txt", "w") as f:
|
| 29 |
+
for l in url:
|
| 30 |
+
print(l, file=f)
|
| 31 |
+
|