ryo0634 commited on
Commit
7998590
1 Parent(s): 85d7559

Upload 2 files

Browse files

Remove the 'neutral' label in MARC-ja when 'remove_neutral' is specified in the config

Files changed (2) hide show
  1. JGLUE.py +4 -3
  2. preprocess_marc_ja.py +5 -5
JGLUE.py CHANGED
@@ -178,11 +178,12 @@ def dataset_info_jcommonsenseqa() -> ds.DatasetInfo:
178
  )
179
 
180
 
181
- def dataset_info_marc_ja() -> ds.DatasetInfo:
 
182
  features = ds.Features(
183
  {
184
  "sentence": ds.Value("string"),
185
- "label": ds.ClassLabel(num_classes=3, names=["positive", "negative", "neutral"]),
186
  "review_id": ds.Value("string"),
187
  }
188
  )
@@ -235,7 +236,7 @@ class JGLUE(ds.GeneratorBasedBuilder):
235
  elif self.config.name == "JCommonsenseQA":
236
  return dataset_info_jcommonsenseqa()
237
  elif self.config.name == "MARC-ja":
238
- return dataset_info_marc_ja()
239
  else:
240
  raise ValueError(f"Invalid config name: {self.config.name}")
241
 
 
178
  )
179
 
180
 
181
+ def dataset_info_marc_ja(remove_netural: bool) -> ds.DatasetInfo:
182
+ labels = ["positive", "negative"] if remove_netural else ["positive", "negative", "neutral"]
183
  features = ds.Features(
184
  {
185
  "sentence": ds.Value("string"),
186
+ "label": ds.ClassLabel(num_classes=len(labels), names=labels),
187
  "review_id": ds.Value("string"),
188
  }
189
  )
 
236
  elif self.config.name == "JCommonsenseQA":
237
  return dataset_info_jcommonsenseqa()
238
  elif self.config.name == "MARC-ja":
239
+ return dataset_info_marc_ja(self.config.remove_netural)
240
  else:
241
  raise ValueError(f"Invalid config name: {self.config.name}")
242
 
preprocess_marc_ja.py CHANGED
@@ -23,7 +23,7 @@ class MarcJaConfig(ds.BuilderConfig):
23
  is_han_to_zen: bool = False,
24
  max_instance_num: Optional[int] = None,
25
  max_char_length: int = 500,
26
- is_pos_neg: bool = True,
27
  train_ratio: float = 0.94,
28
  val_ratio: float = 0.03,
29
  test_ratio: float = 0.03,
@@ -55,20 +55,20 @@ class MarcJaConfig(ds.BuilderConfig):
55
  self.is_han_to_zen = is_han_to_zen
56
  self.max_instance_num = max_instance_num
57
  self.max_char_length = max_char_length
58
- self.is_pos_neg = is_pos_neg
59
  self.output_testset = output_testset
60
 
61
  self.filter_review_id_list_valid = filter_review_id_list_valid
62
  self.label_conv_review_id_list_valid = label_conv_review_id_list_valid
63
 
64
 
65
- def get_label(rating: int, is_pos_neg: bool = False) -> Optional[str]:
66
  if rating >= 4:
67
  return "positive"
68
  elif rating <= 2:
69
  return "negative"
70
  else:
71
- if is_pos_neg:
72
  return None
73
  else:
74
  return "neutral"
@@ -225,7 +225,7 @@ def preprocess_marc_ja(
225
 
226
  # convert the rating to label
227
  tqdm.pandas(dynamic_ncols=True, desc="Convert the rating to the label")
228
- df = df.assign(label=df["rating"].progress_apply(lambda rating: get_label(rating, config.is_pos_neg)))
229
 
230
  # remove rows where the label is None
231
  df = df[~df["label"].isnull()]
 
23
  is_han_to_zen: bool = False,
24
  max_instance_num: Optional[int] = None,
25
  max_char_length: int = 500,
26
+ remove_netural: bool = True,
27
  train_ratio: float = 0.94,
28
  val_ratio: float = 0.03,
29
  test_ratio: float = 0.03,
 
55
  self.is_han_to_zen = is_han_to_zen
56
  self.max_instance_num = max_instance_num
57
  self.max_char_length = max_char_length
58
+ self.remove_netural = remove_netural
59
  self.output_testset = output_testset
60
 
61
  self.filter_review_id_list_valid = filter_review_id_list_valid
62
  self.label_conv_review_id_list_valid = label_conv_review_id_list_valid
63
 
64
 
65
+ def get_label(rating: int, remove_netural: bool = False) -> Optional[str]:
66
  if rating >= 4:
67
  return "positive"
68
  elif rating <= 2:
69
  return "negative"
70
  else:
71
+ if remove_netural:
72
  return None
73
  else:
74
  return "neutral"
 
225
 
226
  # convert the rating to label
227
  tqdm.pandas(dynamic_ncols=True, desc="Convert the rating to the label")
228
+ df = df.assign(label=df["rating"].progress_apply(lambda rating: get_label(rating, config.remove_netural)))
229
 
230
  # remove rows where the label is None
231
  df = df[~df["label"].isnull()]