albertvillanova HF staff commited on
Commit
cc398da
1 Parent(s): f7871ca

Update script

Browse files
Files changed (1) hide show
  1. emotion.py +40 -20
emotion.py CHANGED
@@ -1,4 +1,4 @@
1
- import csv
2
 
3
  import datasets
4
  from datasets.tasks import TextClassification
@@ -27,14 +27,33 @@ _CITATION = """\
27
  _DESCRIPTION = """\
28
  Emotion is a dataset of English Twitter messages with six basic emotions: anger, fear, joy, love, sadness, and surprise. For more detailed information please refer to the paper.
29
  """
30
- _URL = "https://github.com/dair-ai/emotion_dataset"
31
- # use dl=1 to force browser to download data instead of displaying it
32
- _TRAIN_DOWNLOAD_URL = "https://www.dropbox.com/s/1pzkadrvffbqw6o/train.txt?dl=1"
33
- _VALIDATION_DOWNLOAD_URL = "https://www.dropbox.com/s/2mzialpsgf9k5l3/val.txt?dl=1"
34
- _TEST_DOWNLOAD_URL = "https://www.dropbox.com/s/ikkqxfdbdec3fuj/test.txt?dl=1"
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  class Emotion(datasets.GeneratorBasedBuilder):
 
 
 
 
 
 
 
 
 
38
  def _info(self):
39
  class_names = ["sadness", "joy", "love", "anger", "fear", "surprise"]
40
  return datasets.DatasetInfo(
@@ -43,26 +62,27 @@ class Emotion(datasets.GeneratorBasedBuilder):
43
  {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=class_names)}
44
  ),
45
  supervised_keys=("text", "label"),
46
- homepage=_URL,
47
  citation=_CITATION,
 
48
  task_templates=[TextClassification(text_column="text", label_column="label")],
49
  )
50
 
51
  def _split_generators(self, dl_manager):
52
  """Returns SplitGenerators."""
53
- train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
54
- valid_path = dl_manager.download_and_extract(_VALIDATION_DOWNLOAD_URL)
55
- test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
56
- return [
57
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
58
- datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": valid_path}),
59
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
60
- ]
 
61
 
62
  def _generate_examples(self, filepath):
63
  """Generate examples."""
64
- with open(filepath, encoding="utf-8") as csv_file:
65
- csv_reader = csv.reader(csv_file, delimiter=";")
66
- for id_, row in enumerate(csv_reader):
67
- text, label = row
68
- yield id_, {"text": text, "label": label}
 
1
+ import json
2
 
3
  import datasets
4
  from datasets.tasks import TextClassification
 
27
  _DESCRIPTION = """\
28
  Emotion is a dataset of English Twitter messages with six basic emotions: anger, fear, joy, love, sadness, and surprise. For more detailed information please refer to the paper.
29
  """
30
+
31
+ _HOMEPAGE = "https://github.com/dair-ai/emotion_dataset"
32
+
33
+ _LICENSE = "The dataset should be used for educational and research purposes only"
34
+
35
+ _URLS = {
36
+ "split": {
37
+ "train": "data/train.jsonl.gz",
38
+ "validation": "data/validation.jsonl.gz",
39
+ "test": "data/test.jsonl.gz",
40
+ },
41
+ "unsplit": {
42
+ "train": "data/data.jsonl.gz",
43
+ },
44
+ }
45
 
46
 
47
  class Emotion(datasets.GeneratorBasedBuilder):
48
+ VERSION = datasets.Version("1.0.0")
49
+ BUILDER_CONFIGS = [
50
+ datasets.BuilderConfig(
51
+ name="split", version=VERSION, description="Dataset split in train, validation and test"
52
+ ),
53
+ datasets.BuilderConfig(name="unsplit", version=VERSION, description="Unsplit dataset"),
54
+ ]
55
+ DEFAULT_CONFIG_NAME = "split"
56
+
57
  def _info(self):
58
  class_names = ["sadness", "joy", "love", "anger", "fear", "surprise"]
59
  return datasets.DatasetInfo(
 
62
  {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=class_names)}
63
  ),
64
  supervised_keys=("text", "label"),
65
+ homepage=_HOMEPAGE,
66
  citation=_CITATION,
67
+ license=_LICENSE,
68
  task_templates=[TextClassification(text_column="text", label_column="label")],
69
  )
70
 
71
  def _split_generators(self, dl_manager):
72
  """Returns SplitGenerators."""
73
+ paths = dl_manager.download_and_extract(_URLS[self.config.name])
74
+ if self.config.name == "split":
75
+ return [
76
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": paths["train"]}),
77
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": paths["validation"]}),
78
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": paths["test"]}),
79
+ ]
80
+ else:
81
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": paths["train"]})]
82
 
83
  def _generate_examples(self, filepath):
84
  """Generate examples."""
85
+ with open(filepath, encoding="utf-8") as f:
86
+ for idx, line in enumerate(f):
87
+ example = json.loads(line)
88
+ yield idx, example