Datasets:
Upload mbib.py
Browse files
mbib.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
_MBIB_DESCRIPTION = 'bla bla'
|
| 6 |
+
|
| 7 |
+
class MBIBConfig(datasets.BuilderConfig):
|
| 8 |
+
def __init__(self,data_dir,**kwargs):
|
| 9 |
+
super(MBIBConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
| 10 |
+
self.data_dir = data_dir
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MBIB(datasets.GeneratorBasedBuilder):
|
| 14 |
+
BUILDER_CONFIGS = [
|
| 15 |
+
MBIBConfig(name="cognitive-bias",data_dir="mbib-aggregated/cognitive-bias.csv"),
|
| 16 |
+
MBIBConfig(name="fake-news",data_dir="mbib-aggregated/fake-news.csv"),
|
| 17 |
+
MBIBConfig(name="gender-bias",data_dir="mbib-aggregated/gender-bias.csv"),
|
| 18 |
+
MBIBConfig(name="hate-speech",data_dir="mbib-aggregated/hate-speech.csv"),
|
| 19 |
+
MBIBConfig(name="liguistic-bias",data_dir="mbib-aggregated/linguistic-bias.csv"),
|
| 20 |
+
MBIBConfig(name="political-bias",data_dir="mbib-aggregated/political-bias.csv"),
|
| 21 |
+
MBIBConfig(name="racial-bias",data_dir="mbib-aggregated/racial-bias.csv"),
|
| 22 |
+
MBIBConfig(name="text-level-bias",data_dir="mbib-aggregated/text-level-bias.csv")]
|
| 23 |
+
|
| 24 |
+
def _info(self):
|
| 25 |
+
features=datasets.Features(
|
| 26 |
+
{"text":datasets.Value("string"),
|
| 27 |
+
"id":datasets.Value("string"),
|
| 28 |
+
"label":datasets.Value("string"),
|
| 29 |
+
"dataset_id":datasets.Value("string")}
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return datasets.DatasetInfo(
|
| 33 |
+
description=_MBIB_DESCRIPTION,
|
| 34 |
+
features=features
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
def _split_generators(self, dl_manager):
|
| 38 |
+
data_file = dl_manager.download(self.config.data_dir)
|
| 39 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN,gen_kwargs={"data_file": data_file})]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _generate_examples(self, data_dir):
|
| 43 |
+
df = pd.read_csv(data_dir)
|
| 44 |
+
|
| 45 |
+
for i, row in df.iterrows():
|
| 46 |
+
yield i, {"text":row['text'],"label":row['label'],"id":row['id']}
|