Zaid's picture
Upload dummy.py with huggingface_hub
a31e2c3 verified
raw
history blame
No virus
1.45 kB
import os
import pandas as pd
import datasets
from glob import glob
import zipfile
class dummy(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(features=datasets.Features({'tweet':datasets.Value('string'),'label': datasets.features.ClassLabel(names=['satire', 'non'])}))
def extract_all(self, dir):
zip_files = glob(dir+'/**/**.zip', recursive=True)
for file in zip_files:
with zipfile.ZipFile(file) as item:
item.extractall('/'.join(file.split('/')[:-1]))
def get_all_files(self, dir):
files = []
valid_file_ext = ['txt', 'csv', 'tsv', 'xlsx', 'xls', 'xml', 'json', 'jsonl', 'html', 'wav', 'mp3', 'jpg', 'png']
for ext in valid_file_ext:
files += glob(f"{dir}/**/**.{ext}", recursive = True)
return files
def _split_generators(self, dl_manager):
url = ['https://raw.githubusercontent.com/Noza1234/Arbic-satire-dataset/main/sat_nosat_ml_dl.xlsx']
downloaded_files = dl_manager.download(url)
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'filepaths': {'inputs':downloaded_files} })]
def _generate_examples(self, filepaths):
_id = 0
for i,filepath in enumerate(filepaths['inputs']):
df = pd.read_excel(open(filepath, 'rb'), skiprows = 0, header = 0)
if len(df.columns) != 2:
continue
df.columns = ['tweet', 'label']
for _, record in df.iterrows():
yield str(_id), {'tweet':record['tweet'],'label':str(record['label'])}
_id += 1