import datasets import pandas as pd _MBIB_DESCRIPTION = 'bla bla' class MBIBConfig(datasets.BuilderConfig): def __init__(self,data_dir,**kwargs): super(MBIBConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs) self.data_dir = data_dir class MBIB(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ MBIBConfig(name="cognitive-bias",data_dir="mbib-aggregated/cognitive-bias.csv"), MBIBConfig(name="fake-news",data_dir="mbib-aggregated/fake-news.csv"), MBIBConfig(name="gender-bias",data_dir="mbib-aggregated/gender-bias.csv"), MBIBConfig(name="hate-speech",data_dir="mbib-aggregated/hate-speech.csv"), MBIBConfig(name="linguistic-bias",data_dir="mbib-aggregated/linguistic-bias.csv"), MBIBConfig(name="political-bias",data_dir="mbib-aggregated/political-bias.csv"), MBIBConfig(name="racial-bias",data_dir="mbib-aggregated/racial-bias.csv"), MBIBConfig(name="text-level-bias",data_dir="mbib-aggregated/text-level-bias.csv")] def _info(self): features=datasets.Features( {"text":datasets.Value("string"), "label":datasets.Value("int32")} ) return datasets.DatasetInfo( description=_MBIB_DESCRIPTION, features=features ) def _split_generators(self, dl_manager): data_file = dl_manager.download(self.config.data_dir) return [datasets.SplitGenerator(name=datasets.Split.TRAIN,gen_kwargs={"data_dir": data_file})] def _generate_examples(self, data_dir): df = pd.read_csv(data_dir)[['text','label']] for i, row in df.iterrows(): yield i, {"text":row['text'],"label":row['label']}