File size: 3,027 Bytes
cf246c7 34c44fc cf246c7 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import os
import datasets
import pandas as pd
class TWEETS(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"ID": datasets.Value("string"),
"tweet": datasets.Value("string"),
"unnecessary": datasets.Value("bool"),
"mandatory": datasets.Value("bool"),
"pharma": datasets.Value("bool"),
"conspiracy": datasets.Value("bool"),
"political": datasets.Value("bool"),
"country": datasets.Value("bool"),
"rushed": datasets.Value("bool"),
"ingredients": datasets.Value("bool"),
"side-effect": datasets.Value("bool"),
"ineffective": datasets.Value("bool"),
"religious": datasets.Value("bool"),
"none": datasets.Value("bool"),
}
)
return datasets.DatasetInfo(
features=features,
supervised_keys=None,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = os.path.join(dl_manager.download_and_extract("https://drive.google.com/u/0/uc?id=1e_QaxcG0zSv4UWqncXjDA0ZqBjzg3oVP&export=download"))
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": os.path.join( data_dir, "data/train_data.csv"), "split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": os.path.join( data_dir, "data/val_data.csv"), "split": "test",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": os.path.join( data_dir, "data/val_data.csv"), "split": "validation",
},
),
]
def _generate_examples(self, filepath, split):
"""Yields examples as (key, example) tuples."""
with open(filepath, encoding="utf-8") as f:
next(f) # skip header
for id_, row in enumerate(f):
data = row.split(",")
yield id_, {
"ID": data[0],
"tweet": data[1],
"unnecessary": int(data[2]),
"mandatory": int(data[3]),
"pharma": int(data[4]),
"conspiracy": int(data[5]),
"political": int(data[6]),
"country": int(data[7]),
"rushed": int(data[8]),
"ingredients": int(data[9]),
"side-effect": int(data[10]),
"ineffective": int(data[11]),
"religious": int(data[12]),
"none": int(data[13]),
} |