holylovenia commited on
Commit
d850e1f
·
verified ·
1 Parent(s): d6b8317

Upload nusaparagraph_emot.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. nusaparagraph_emot.py +20 -20
nusaparagraph_emot.py CHANGED
@@ -2,14 +2,14 @@ from pathlib import Path
2
  from typing import Dict, List, Tuple
3
  import datasets
4
  import pandas as pd
5
- from nusacrowd.utils import schemas
6
- from nusacrowd.utils.configs import NusantaraConfig
7
- from nusacrowd.utils.constants import (DEFAULT_NUSANTARA_VIEW_NAME,
8
  DEFAULT_SOURCE_VIEW_NAME, Tasks)
9
  _LOCAL = False
10
  _DATASETNAME = "nusaparagraph_emot"
11
  _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
12
- _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
13
  _LANGUAGES = [
14
  "btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"
15
  ] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
@@ -31,7 +31,7 @@ _HOMEPAGE = "https://github.com/IndoNLP/nusa-writes"
31
  _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
32
  _SUPPORTED_TASKS = [Tasks.EMOTION_CLASSIFICATION]
33
  _SOURCE_VERSION = "1.0.0"
34
- _NUSANTARA_VERSION = "1.0.0"
35
  _URLS = {
36
  "train":
37
  "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-emot-{lang}-train.csv",
@@ -40,12 +40,12 @@ _URLS = {
40
  "test":
41
  "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-emot-{lang}-test.csv",
42
  }
43
- def nusantara_config_constructor(lang, schema, version):
44
- """Construct NusantaraConfig with nusaparagraph_emot_{lang}_{schema} as the name format"""
45
- if schema != "source" and schema != "nusantara_text":
46
  raise ValueError(f"Invalid schema: {schema}")
47
  if lang == "":
48
- return NusantaraConfig(
49
  name="nusaparagraph_emot_{schema}".format(schema=schema),
50
  version=datasets.Version(version),
51
  description=
@@ -55,7 +55,7 @@ def nusantara_config_constructor(lang, schema, version):
55
  subset_id="nusaparagraph_emot",
56
  )
57
  else:
58
- return NusantaraConfig(
59
  name="nusaparagraph_emot_{lang}_{schema}".format(lang=lang,
60
  schema=schema),
61
  version=datasets.Version(version),
@@ -80,15 +80,15 @@ LANGUAGES_MAP = {
80
  class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
81
  """NusaParagraph-Emot is a 7-labels (fear, disgusted, sad, happy, angry, surprise, and shame) emotion classification dataset for 10 Indonesian local languages."""
82
  BUILDER_CONFIGS = ([
83
- nusantara_config_constructor(lang, "source", _SOURCE_VERSION)
84
  for lang in LANGUAGES_MAP
85
  ] + [
86
- nusantara_config_constructor(lang, "nusantara_text",
87
- _NUSANTARA_VERSION)
88
  for lang in LANGUAGES_MAP
89
  ] + [
90
- nusantara_config_constructor("", "source", _SOURCE_VERSION),
91
- nusantara_config_constructor("", "nusantara_text", _NUSANTARA_VERSION)
92
  ])
93
  DEFAULT_CONFIG_NAME = "nusaparagraph_emot_ind_source"
94
  def _info(self) -> datasets.DatasetInfo:
@@ -98,7 +98,7 @@ class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
98
  "text": datasets.Value("string"),
99
  "label": datasets.Value("string"),
100
  })
101
- elif self.config.schema == "nusantara_text":
102
  features = schemas.text_features([
103
  "fear", "disgusted", "sad", "happy", "angry", "surprise",
104
  "shame"
@@ -114,7 +114,7 @@ class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
114
  self, dl_manager: datasets.DownloadManager
115
  ) -> List[datasets.SplitGenerator]:
116
  """Returns SplitGenerators."""
117
- if self.config.name == "nusaparagraph_emot_source" or self.config.name == "nusaparagraph_emot_nusantara_text":
118
  # Load all 12 languages
119
  train_csv_path = dl_manager.download_and_extract([
120
  _URLS["train"].format(lang=lang)
@@ -154,9 +154,9 @@ class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
154
  ),
155
  ]
156
  def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
157
- if self.config.schema != "source" and self.config.schema != "nusantara_text":
158
  raise ValueError(f"Invalid config: {self.config.name}")
159
- if self.config.name == "nusaparagraph_emot_source" or self.config.name == "nusaparagraph_emot_nusantara_text":
160
  ldf = []
161
  for fp in filepath:
162
  ldf.append(pd.read_csv(fp))
@@ -167,4 +167,4 @@ class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
167
  df = pd.read_csv(filepath).reset_index()
168
  for row in df.itertuples():
169
  ex = {"id": str(row.id), "text": row.text, "label": row.label}
170
- yield row.id, ex
 
2
  from typing import Dict, List, Tuple
3
  import datasets
4
  import pandas as pd
5
+ from seacrowd.utils import schemas
6
+ from seacrowd.utils.configs import SEACrowdConfig
7
+ from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
8
  DEFAULT_SOURCE_VIEW_NAME, Tasks)
9
  _LOCAL = False
10
  _DATASETNAME = "nusaparagraph_emot"
11
  _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
12
+ _UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
13
  _LANGUAGES = [
14
  "btk", "bew", "bug", "jav", "mad", "mak", "min", "mui", "rej", "sun"
15
  ] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
 
31
  _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
32
  _SUPPORTED_TASKS = [Tasks.EMOTION_CLASSIFICATION]
33
  _SOURCE_VERSION = "1.0.0"
34
+ _SEACROWD_VERSION = "2024.06.20"
35
  _URLS = {
36
  "train":
37
  "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-emot-{lang}-train.csv",
 
40
  "test":
41
  "https://raw.githubusercontent.com/IndoNLP/nusa-writes/main/data/nusa_alinea-emot-{lang}-test.csv",
42
  }
43
+ def seacrowd_config_constructor(lang, schema, version):
44
+ """Construct SEACrowdConfig with nusaparagraph_emot_{lang}_{schema} as the name format"""
45
+ if schema != "source" and schema != "seacrowd_text":
46
  raise ValueError(f"Invalid schema: {schema}")
47
  if lang == "":
48
+ return SEACrowdConfig(
49
  name="nusaparagraph_emot_{schema}".format(schema=schema),
50
  version=datasets.Version(version),
51
  description=
 
55
  subset_id="nusaparagraph_emot",
56
  )
57
  else:
58
+ return SEACrowdConfig(
59
  name="nusaparagraph_emot_{lang}_{schema}".format(lang=lang,
60
  schema=schema),
61
  version=datasets.Version(version),
 
80
  class NusaParagraphEmot(datasets.GeneratorBasedBuilder):
81
  """NusaParagraph-Emot is a 7-labels (fear, disgusted, sad, happy, angry, surprise, and shame) emotion classification dataset for 10 Indonesian local languages."""
82
  BUILDER_CONFIGS = ([
83
+ seacrowd_config_constructor(lang, "source", _SOURCE_VERSION)
84
  for lang in LANGUAGES_MAP
85
  ] + [
86
+ seacrowd_config_constructor(lang, "seacrowd_text",
87
+ _SEACROWD_VERSION)
88
  for lang in LANGUAGES_MAP
89
  ] + [
90
+ seacrowd_config_constructor("", "source", _SOURCE_VERSION),
91
+ seacrowd_config_constructor("", "seacrowd_text", _SEACROWD_VERSION)
92
  ])
93
  DEFAULT_CONFIG_NAME = "nusaparagraph_emot_ind_source"
94
  def _info(self) -> datasets.DatasetInfo:
 
98
  "text": datasets.Value("string"),
99
  "label": datasets.Value("string"),
100
  })
101
+ elif self.config.schema == "seacrowd_text":
102
  features = schemas.text_features([
103
  "fear", "disgusted", "sad", "happy", "angry", "surprise",
104
  "shame"
 
114
  self, dl_manager: datasets.DownloadManager
115
  ) -> List[datasets.SplitGenerator]:
116
  """Returns SplitGenerators."""
117
+ if self.config.name == "nusaparagraph_emot_source" or self.config.name == "nusaparagraph_emot_seacrowd_text":
118
  # Load all 12 languages
119
  train_csv_path = dl_manager.download_and_extract([
120
  _URLS["train"].format(lang=lang)
 
154
  ),
155
  ]
156
  def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
157
+ if self.config.schema != "source" and self.config.schema != "seacrowd_text":
158
  raise ValueError(f"Invalid config: {self.config.name}")
159
+ if self.config.name == "nusaparagraph_emot_source" or self.config.name == "nusaparagraph_emot_seacrowd_text":
160
  ldf = []
161
  for fp in filepath:
162
  ldf.append(pd.read_csv(fp))
 
167
  df = pd.read_csv(filepath).reset_index()
168
  for row in df.itertuples():
169
  ex = {"id": str(row.id), "text": row.text, "label": row.label}
170
+ yield row.id, ex