Upload dataset_utils.py with huggingface_hub
Browse files1234567891011125 unmodified lines18192021222324252627282930313233343536373839404142434445464748493 unmodified lines535455565758import osfrom .artifact import Artifact, UnitxtArtifactNotFoundError, fetch_artifactfrom .logging_utils import get_loggerfrom .register import _reset_env_local_catalogs, register_all_artifactslogger = get_logger()__default_recipe__ = "standard_recipe"def fetch(artifact_name):5 unmodified linesdef parse(query: str):"""Parses a query of the form 'key1=value1,key2=value2,...' into a dictionary."""result = {}kvs = query.split(",")if len(kvs) == 0:raise ValueError('Illegal query: "{query}" should contain at least one assignment of the form: key1=value1,key2=value2')for kv in kvs:key_val = kv.split("=")if (len(key_val) != 2or len(key_val[0].strip()) == 0or len(key_val[1].strip()) == 0):raise ValueError(f'Illegal query: "{query}" with wrong assignment "{kv}" should be of the form: key=value.')key, val = key_valif val.isdigit():result[key] = int(val)elif val.replace(".", "", 1).isdigit():result[key] = float(val)else:result[key] = valreturn resultdef get_dataset_artifact(dataset_str):3 unmodified linesif recipe is None:args = parse(dataset_str)if "type" not in args:args["type"] = os.environ.get("UNITXT_DEFAULT_RECIPE", __default_recipe__)recipe = Artifact.from_dict(args)return recipe12345678910115 unmodified lines171819202122233 unmodified lines272829303132from .artifact import Artifact, UnitxtArtifactNotFoundError, fetch_artifactfrom .logging_utils import get_loggerfrom .parsing_utils import parse_key_equals_value_string_to_dictfrom .register import _reset_env_local_catalogs, register_all_artifactsfrom .settings_utils import get_settingslogger = get_logger()settings = get_settings()def fetch(artifact_name):5 unmodified linesdef parse(query: str):return parse_key_equals_value_string_to_dict(query)def get_dataset_artifact(dataset_str):3 unmodified linesif recipe is None:args = parse(dataset_str)if "type" not in args:args["type"] = settings.default_reciperecipe = Artifact.from_dict(args)return recipe
dataset_utils.py+5-31