TWEETS / TWEETS.py
Siddharthkak's picture
Update TWEETS.py
34c44fc
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]),
}