-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikipedia.py
39 lines (34 loc) · 1.4 KB
/
wikipedia.py
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
"""
An API for ingesting wikimedia/wikipedia dataset at https://huggingface.co/datasets/wikimedia/wikipedia
rlsn 2024
"""
import pandas as pd
from ..dataset_wrapper import BaseDataset, Dataset
from ..utils import AttrDict
@Dataset.register('wikimedia/wikipedia')
class WikipediaDataset(BaseDataset):
namespace = "wikimedia/wikipedia"
abstract = False
@classmethod
def get_metadata(cls, verbose=False):
from .hf_parquet import HuggingFaceParquetDataset
url = "https://huggingface.co/datasets/wikimedia/wikipedia"
meta = HuggingFaceParquetDataset.get_metadata(cls.namespace, url, verbose)
meta["description"] = "Wikipedia dataset containing cleaned articles of all languages."
meta["modality"]="text"
return meta
@classmethod
def download(cls, datapath):
from .hf_parquet import HuggingFaceParquetDataset
return HuggingFaceParquetDataset.download(datapath)
@classmethod
def check_update_to_date(cls, name):
from .hf_parquet import HuggingFaceParquetDataset
return HuggingFaceParquetDataset.check_update_to_date(name)
@classmethod
def process_samples(cls, samples:pd.DataFrame)->AttrDict:
data = AttrDict([(col,[]) for col in samples.columns])
for row in samples.itertuples():
for col in samples.columns:
data[col].append(getattr(row, col))
return data