Datasets:
Robin Kurtz
commited on
Commit
·
580e539
1
Parent(s):
9862bb6
readme
Browse files- overlim.py +32 -10
overlim.py
CHANGED
|
@@ -309,7 +309,7 @@ _LANGUAGES = {"sv", "da", "nb"}
|
|
| 309 |
|
| 310 |
class OverLimConfig(datasets.BuilderConfig):
|
| 311 |
"""BuilderConfig for Suc."""
|
| 312 |
-
def __init__(self, name, description, features, citation, language, label_classes=
|
| 313 |
"""BuilderConfig for OverLim.
|
| 314 |
"""
|
| 315 |
self.full_name = name + "_" + language
|
|
@@ -423,7 +423,11 @@ class OverLim(datasets.GeneratorBasedBuilder):
|
|
| 423 |
BUILDER_CONFIGS = [element for inner in BUILDER_CONFIGS for element in inner]
|
| 424 |
|
| 425 |
def _info(self):
|
| 426 |
-
features = {feature: datasets.Value("string") for feature in self.config.features}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
features["idx"] = datasets.Value("int32")
|
| 428 |
|
| 429 |
return datasets.DatasetInfo(
|
|
@@ -474,16 +478,34 @@ class OverLim(datasets.GeneratorBasedBuilder):
|
|
| 474 |
|
| 475 |
def _cast_label(label):
|
| 476 |
"""Converts the label into the appropriate string version."""
|
| 477 |
-
|
|
|
|
| 478 |
return label
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
assert label in (0, 1)
|
| 484 |
return label
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
| 486 |
return label
|
| 487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
# else:
|
| 489 |
# raise ValueError("Invalid label format.")
|
|
|
|
| 309 |
|
| 310 |
class OverLimConfig(datasets.BuilderConfig):
|
| 311 |
"""BuilderConfig for Suc."""
|
| 312 |
+
def __init__(self, name, description, features, citation, language, label_classes=None, **kwargs):
|
| 313 |
"""BuilderConfig for OverLim.
|
| 314 |
"""
|
| 315 |
self.full_name = name + "_" + language
|
|
|
|
| 423 |
BUILDER_CONFIGS = [element for inner in BUILDER_CONFIGS for element in inner]
|
| 424 |
|
| 425 |
def _info(self):
|
| 426 |
+
features = {feature: datasets.Value("string") for feature in self.config.features if feature != "label"}
|
| 427 |
+
if self.config.label_classes:
|
| 428 |
+
features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
|
| 429 |
+
else:
|
| 430 |
+
features["label"] = datasets.Value("float32")
|
| 431 |
features["idx"] = datasets.Value("int32")
|
| 432 |
|
| 433 |
return datasets.DatasetInfo(
|
|
|
|
| 478 |
|
| 479 |
def _cast_label(label):
|
| 480 |
"""Converts the label into the appropriate string version."""
|
| 481 |
+
try:
|
| 482 |
+
label = float(label)
|
| 483 |
return label
|
| 484 |
+
except ValueError:
|
| 485 |
+
pass
|
| 486 |
+
try:
|
| 487 |
+
label = int(label)
|
|
|
|
| 488 |
return label
|
| 489 |
+
except ValueError:
|
| 490 |
+
pass
|
| 491 |
+
try:
|
| 492 |
+
label = int(bool(label))
|
| 493 |
return label
|
| 494 |
+
except ValueError:
|
| 495 |
+
pass
|
| 496 |
+
return label
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
# if isinstance(label, str):
|
| 500 |
+
# return label
|
| 501 |
+
# elif isinstance(label, bool):
|
| 502 |
+
# return "True" if label else "False"
|
| 503 |
+
# # return label
|
| 504 |
+
# elif isinstance(label, int):
|
| 505 |
+
# assert label in (0, 1)
|
| 506 |
+
# return label
|
| 507 |
+
# elif isinstance(label, float):
|
| 508 |
+
# return label
|
| 509 |
+
# # return str(label)
|
| 510 |
# else:
|
| 511 |
# raise ValueError("Invalid label format.")
|