ma2za commited on
Commit
62be3ab
·
1 Parent(s): 5a37cd5

Upload emotions_dataset.py

Browse files
Files changed (1) hide show
  1. emotions_dataset.py +22 -10
emotions_dataset.py CHANGED
@@ -4,10 +4,14 @@ import datasets
4
  import pandas as pd
5
  from datasets import ClassLabel, Value
6
 
7
- _URLS = [
8
- "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_1.csv",
9
- "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_2.csv",
10
- "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_3.csv",
 
 
 
 
11
  ]
12
 
13
  _CLASS_NAMES = [
@@ -57,7 +61,7 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
57
  EmotionsDatasetConfig(
58
  name="all",
59
  label_classes=_CLASS_NAMES,
60
- features=["text", "label", "dataset"]
61
  )
62
  ]
63
 
@@ -68,18 +72,24 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
68
  features=datasets.Features(
69
  {
70
  "id": datasets.Value("string"),
71
- 'label': ClassLabel(names=_CLASS_NAMES, id=None),
72
  'text': Value(dtype='string', id=None),
73
- 'dataset': Value(dtype='string', id=None)
 
 
74
  }
75
  )
76
  )
77
 
78
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
79
- downloaded_files = dl_manager.download_and_extract(_URLS)
80
- return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files})]
 
 
 
 
 
81
 
82
- def _generate_examples(self, filepaths):
83
  for i, filepath in enumerate(filepaths):
84
  df = pd.read_csv(filepath)
85
  current_classes = list(set(df.columns).intersection(set(_CLASS_NAMES)))
@@ -89,4 +99,6 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
89
  uid = f"{i}_{row_idx}"
90
  yield uid, {"text": row["text"],
91
  "id": uid,
 
 
92
  "label": row[current_classes][row == 1].index.item()}
 
4
  import pandas as pd
5
  from datasets import ClassLabel, Value
6
 
7
+ DATASETS_URLS = [{
8
+ "name": "go_emotions",
9
+ "urls": [
10
+ "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_1.csv",
11
+ "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_2.csv",
12
+ "https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_3.csv",
13
+ ],
14
+ "license": "apache license 2.0"}
15
  ]
16
 
17
  _CLASS_NAMES = [
 
61
  EmotionsDatasetConfig(
62
  name="all",
63
  label_classes=_CLASS_NAMES,
64
+ features=["text", "label", "dataset", "license"]
65
  )
66
  ]
67
 
 
72
  features=datasets.Features(
73
  {
74
  "id": datasets.Value("string"),
 
75
  'text': Value(dtype='string', id=None),
76
+ 'label': ClassLabel(names=_CLASS_NAMES, id=None),
77
+ 'dataset': Value(dtype='string', id=None),
78
+ 'license': Value(dtype='string', id=None)
79
  }
80
  )
81
  )
82
 
83
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
84
+ splits = []
85
+ for d in DATASETS_URLS:
86
+ downloaded_files = dl_manager.download_and_extract(d.get("urls"))
87
+ splits.append(datasets.SplitGenerator(name=d.get("name"), gen_kwargs={"filepaths": downloaded_files,
88
+ "dataset": d.get("name"),
89
+ "license": d.get("license")}))
90
+ return splits
91
 
92
+ def _generate_examples(self, filepaths, dataset, license):
93
  for i, filepath in enumerate(filepaths):
94
  df = pd.read_csv(filepath)
95
  current_classes = list(set(df.columns).intersection(set(_CLASS_NAMES)))
 
99
  uid = f"{i}_{row_idx}"
100
  yield uid, {"text": row["text"],
101
  "id": uid,
102
+ "dataset": dataset,
103
+ "license": license,
104
  "label": row[current_classes][row == 1].index.item()}