|
import json
|
|
import os
|
|
import datasets
|
|
|
|
_DESCRIPTION = "Tweet eval stance subset"
|
|
_SUBSETS = ["stance_abortion", "stance_atheism", "stance_climate", "stance_feminist", "stance_hillary"]
|
|
|
|
URL = ""
|
|
_URLs = {split: {"train": URL + f"{split}/train.jsonl", "test": URL + f"{split}/test.jsonl"} for split in _SUBSETS}
|
|
|
|
|
|
|
|
class TweetEval(datasets.GeneratorBasedBuilder):
|
|
"""TweetEval Dataset."""
|
|
|
|
BUILDER_CONFIGS = [
|
|
datasets.BuilderConfig(
|
|
name=name,
|
|
description=f"This part of my dataset covers {name} part of TweetEval Dataset.",
|
|
) for name in _SUBSETS
|
|
]
|
|
|
|
def _info(self):
|
|
names = ["none", "against", "favor"]
|
|
|
|
return datasets.DatasetInfo(
|
|
description=_DESCRIPTION,
|
|
features=datasets.Features(
|
|
{
|
|
"text": datasets.Value("string"),
|
|
"label": datasets.Value("int32"),
|
|
"label_text": datasets.Value("string"),
|
|
}
|
|
),
|
|
supervised_keys=None,
|
|
)
|
|
|
|
def _split_generators(self, dl_manager):
|
|
"""Returns SplitGenerators."""
|
|
my_urls = _URLs[self.config.name]
|
|
data_dir = dl_manager.download_and_extract(my_urls)
|
|
return [
|
|
datasets.SplitGenerator(
|
|
name=datasets.Split.TRAIN,
|
|
|
|
gen_kwargs={"text_path": data_dir["train"]},
|
|
),
|
|
datasets.SplitGenerator(
|
|
name=datasets.Split.TEST,
|
|
|
|
gen_kwargs={"text_path": data_dir["test"]},
|
|
),
|
|
]
|
|
|
|
def _generate_examples(self, text_path):
|
|
"""Yields examples."""
|
|
with open(text_path, encoding="utf-8") as f:
|
|
texts = f.readlines()
|
|
for i, text in enumerate(texts):
|
|
yield i, json.loads(text) |